Spaces:
Running
on
Zero
Running
on
Zero
dont break
Browse files
app.py
CHANGED
@@ -84,8 +84,17 @@ def process(
|
|
84 |
image = Image.open(io.BytesIO(base64.b64decode(dino_labled_img)))
|
85 |
print('finish processing')
|
86 |
parsed_content_list = '\n'.join(parsed_content_list)
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
|
|
89 |
|
90 |
|
91 |
with gr.Blocks() as demo:
|
@@ -94,10 +103,8 @@ with gr.Blocks() as demo:
|
|
94 |
with gr.Column():
|
95 |
image_input_component = gr.Image(
|
96 |
type='pil', label='Upload image')
|
97 |
-
# set the threshold for removing the bounding boxes with low confidence, default is 0.05
|
98 |
box_threshold_component = gr.Slider(
|
99 |
label='Box Threshold', minimum=0.01, maximum=1.0, step=0.01, value=0.05)
|
100 |
-
# set the threshold for removing the bounding boxes with large overlap, default is 0.1
|
101 |
iou_threshold_component = gr.Slider(
|
102 |
label='IOU Threshold', minimum=0.01, maximum=1.0, step=0.01, value=0.1)
|
103 |
submit_button_component = gr.Button(
|
@@ -105,6 +112,12 @@ with gr.Blocks() as demo:
|
|
105 |
with gr.Column():
|
106 |
image_output_component = gr.Image(type='pil', label='Image Output')
|
107 |
text_output_component = gr.Textbox(label='Parsed screen elements', placeholder='Text Output')
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
|
109 |
submit_button_component.click(
|
110 |
fn=process,
|
@@ -113,9 +126,15 @@ with gr.Blocks() as demo:
|
|
113 |
box_threshold_component,
|
114 |
iou_threshold_component
|
115 |
],
|
116 |
-
outputs=[
|
|
|
|
|
|
|
|
|
117 |
)
|
118 |
|
|
|
|
|
119 |
# demo.launch(debug=False, show_error=True, share=True)
|
120 |
# demo.launch(share=True, server_port=7861, server_name='0.0.0.0')
|
121 |
-
demo.queue().launch(share=False)
|
|
|
84 |
image = Image.open(io.BytesIO(base64.b64decode(dino_labled_img)))
|
85 |
print('finish processing')
|
86 |
parsed_content_list = '\n'.join(parsed_content_list)
|
87 |
+
|
88 |
+
# Format the coordinates output in a more readable way
|
89 |
+
coordinates_text = "Bounding Box Coordinates (x, y, width, height):\n"
|
90 |
+
for box_id, coords in sorted(label_coordinates.items(), key=lambda x: int(x[0])):
|
91 |
+
# Convert numpy array to list and round values
|
92 |
+
coords_list = coords.tolist()
|
93 |
+
coords_formatted = [f"{coord:.1f}" for coord in coords_list]
|
94 |
+
coordinates_text += f"Box {box_id}: [{coords_formatted[0]}, {coords_formatted[1]}, {coords_formatted[2]}, {coords_formatted[3]}]\n"
|
95 |
+
|
96 |
|
97 |
+
return image, str(parsed_content_list), str(coordinates_text)
|
98 |
|
99 |
|
100 |
with gr.Blocks() as demo:
|
|
|
103 |
with gr.Column():
|
104 |
image_input_component = gr.Image(
|
105 |
type='pil', label='Upload image')
|
|
|
106 |
box_threshold_component = gr.Slider(
|
107 |
label='Box Threshold', minimum=0.01, maximum=1.0, step=0.01, value=0.05)
|
|
|
108 |
iou_threshold_component = gr.Slider(
|
109 |
label='IOU Threshold', minimum=0.01, maximum=1.0, step=0.01, value=0.1)
|
110 |
submit_button_component = gr.Button(
|
|
|
112 |
with gr.Column():
|
113 |
image_output_component = gr.Image(type='pil', label='Image Output')
|
114 |
text_output_component = gr.Textbox(label='Parsed screen elements', placeholder='Text Output')
|
115 |
+
coordinates_output_component = gr.Textbox(
|
116 |
+
label='Bounding Box Coordinates',
|
117 |
+
placeholder='Coordinates will appear here',
|
118 |
+
lines=20, # Increased lines to show more coordinates
|
119 |
+
interactive=False # Make it read-only
|
120 |
+
)
|
121 |
|
122 |
submit_button_component.click(
|
123 |
fn=process,
|
|
|
126 |
box_threshold_component,
|
127 |
iou_threshold_component
|
128 |
],
|
129 |
+
outputs=[
|
130 |
+
image_output_component,
|
131 |
+
text_output_component,
|
132 |
+
coordinates_output_component
|
133 |
+
]
|
134 |
)
|
135 |
|
136 |
+
demo.queue().launch(share=False)
|
137 |
+
|
138 |
# demo.launch(debug=False, show_error=True, share=True)
|
139 |
# demo.launch(share=True, server_port=7861, server_name='0.0.0.0')
|
140 |
+
# demo.queue().launch(share=False)
|