Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,11 +9,15 @@ from utils import check_ocr_box, get_yolo_model, get_caption_model_processor, ge
|
|
9 |
from PIL import Image
|
10 |
|
11 |
from ultralytics import YOLO
|
12 |
-
yolo_model = YOLO('weights/icon_detect/best.pt')
|
13 |
|
14 |
from transformers import AutoProcessor, AutoModelForCausalLM
|
15 |
processor = AutoProcessor.from_pretrained("microsoft/Florence-2-base", trust_remote_code=True)
|
16 |
-
model = AutoModelForCausalLM.from_pretrained(
|
|
|
|
|
|
|
|
|
17 |
|
18 |
caption_model_processor = {'processor': processor, 'model': model}
|
19 |
print('Finished loading model.')
|
@@ -57,7 +61,7 @@ def process(
|
|
57 |
)
|
58 |
text, ocr_bbox = ocr_bbox_rslt
|
59 |
|
60 |
-
|
61 |
image_save_path,
|
62 |
yolo_model,
|
63 |
BOX_TRESHOLD=box_threshold,
|
@@ -68,10 +72,12 @@ def process(
|
|
68 |
ocr_text=text,
|
69 |
iou_threshold=iou_threshold
|
70 |
)
|
71 |
-
image = Image.open(io.BytesIO(base64.b64decode(
|
72 |
print('Finished processing.')
|
73 |
-
|
74 |
-
|
|
|
|
|
75 |
|
76 |
with gr.Blocks() as demo:
|
77 |
gr.Markdown(MARKDOWN)
|
@@ -88,6 +94,8 @@ with gr.Blocks() as demo:
|
|
88 |
image_output_component = gr.Image(type='pil', label='Image Output')
|
89 |
text_output_component = gr.Textbox(
|
90 |
label='Parsed Screen Elements', placeholder='Text Output')
|
|
|
|
|
91 |
|
92 |
submit_button_component.click(
|
93 |
fn=process,
|
@@ -96,7 +104,11 @@ with gr.Blocks() as demo:
|
|
96 |
box_threshold_component,
|
97 |
iou_threshold_component
|
98 |
],
|
99 |
-
outputs=[
|
|
|
|
|
|
|
|
|
100 |
)
|
101 |
|
102 |
-
demo.queue().launch(share=False)
|
|
|
9 |
from PIL import Image
|
10 |
|
11 |
from ultralytics import YOLO
|
12 |
+
yolo_model = YOLO('weights/icon_detect/best.pt')
|
13 |
|
14 |
from transformers import AutoProcessor, AutoModelForCausalLM
|
15 |
processor = AutoProcessor.from_pretrained("microsoft/Florence-2-base", trust_remote_code=True)
|
16 |
+
model = AutoModelForCausalLM.from_pretrained(
|
17 |
+
"weights/icon_caption_florence",
|
18 |
+
torch_dtype=torch.float32,
|
19 |
+
trust_remote_code=True
|
20 |
+
)
|
21 |
|
22 |
caption_model_processor = {'processor': processor, 'model': model}
|
23 |
print('Finished loading model.')
|
|
|
61 |
)
|
62 |
text, ocr_bbox = ocr_bbox_rslt
|
63 |
|
64 |
+
dino_labeled_img, label_coordinates, parsed_content_list = get_som_labeled_img(
|
65 |
image_save_path,
|
66 |
yolo_model,
|
67 |
BOX_TRESHOLD=box_threshold,
|
|
|
72 |
ocr_text=text,
|
73 |
iou_threshold=iou_threshold
|
74 |
)
|
75 |
+
image = Image.open(io.BytesIO(base64.b64decode(dino_labeled_img)))
|
76 |
print('Finished processing.')
|
77 |
+
parsed_content_list_str = '\n'.join(parsed_content_list)
|
78 |
+
label_coordinates_str = '\n'.join([str(coord) for coord in label_coordinates])
|
79 |
+
|
80 |
+
return image, parsed_content_list_str, label_coordinates_str
|
81 |
|
82 |
with gr.Blocks() as demo:
|
83 |
gr.Markdown(MARKDOWN)
|
|
|
94 |
image_output_component = gr.Image(type='pil', label='Image Output')
|
95 |
text_output_component = gr.Textbox(
|
96 |
label='Parsed Screen Elements', placeholder='Text Output')
|
97 |
+
coordinates_output_component = gr.Textbox(
|
98 |
+
label='Coordinates', placeholder='Coordinates Output')
|
99 |
|
100 |
submit_button_component.click(
|
101 |
fn=process,
|
|
|
104 |
box_threshold_component,
|
105 |
iou_threshold_component
|
106 |
],
|
107 |
+
outputs=[
|
108 |
+
image_output_component,
|
109 |
+
text_output_component,
|
110 |
+
coordinates_output_component
|
111 |
+
]
|
112 |
)
|
113 |
|
114 |
+
demo.queue().launch(share=False)
|