Skip to content

Commit

Permalink
Add JSON output formatting to process function; return label_coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
abrichr committed Nov 1, 2024
1 parent b8b952c commit 201af0f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions gradio_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from PIL import Image
import io

import base64, os

import base64, json, os
from utils import check_ocr_box, get_yolo_model, get_caption_model_processor, get_som_labeled_img
import torch
from PIL import Image
Expand Down Expand Up @@ -68,12 +69,17 @@ def process(
ocr_bbox_rslt, is_goal_filtered = check_ocr_box(image_save_path, display_img = False, output_bb_format='xyxy', goal_filtering=None, easyocr_args={'paragraph': False, 'text_threshold':0.9}, use_paddleocr=use_paddleocr)
text, ocr_bbox = ocr_bbox_rslt
# print('prompt:', prompt)

dino_labled_img, label_coordinates, parsed_content_list = get_som_labeled_img(image_save_path, yolo_model, BOX_TRESHOLD = box_threshold, output_coord_in_ratio=True, ocr_bbox=ocr_bbox,draw_bbox_config=draw_bbox_config, caption_model_processor=caption_model_processor, ocr_text=text,iou_threshold=iou_threshold)
image = Image.open(io.BytesIO(base64.b64decode(dino_labled_img)))

print('finish processing')
return image, str(parsed_content_list), str(label_coordinates)
print('finish processing')
output_dict = {
"parsed_content_list": parsed_content_list,
"label_coordinates": label_coordinates,
}
combined_text_output = json.dumps(output_dict, indent=2)
return image, combined_text_output



with gr.Blocks() as demo:
Expand Down Expand Up @@ -108,4 +114,4 @@ def process(
)

# demo.launch(debug=False, show_error=True, share=True)
demo.launch(share=True, server_port=7861, server_name='0.0.0.0')
demo.launch(share=True, server_port=7861, server_name='0.0.0.0')

0 comments on commit 201af0f

Please sign in to comment.