Spaces:
Running
on
Zero
Running
on
Zero
Martin Tomov
commited on
Commit
β’
2a212bf
1
Parent(s):
0764038
debugging
Browse files
app.py
CHANGED
@@ -191,25 +191,19 @@ def detections_to_json(detections):
|
|
191 |
detections_list.append(detection_dict)
|
192 |
return detections_list
|
193 |
|
194 |
-
def
|
195 |
labels = ["insect"]
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
image = Image.open(image_file).convert("RGB")
|
200 |
-
original_image, detections = grounded_segmentation(image, labels, threshold=0.3, polygon_refinement=True)
|
201 |
-
yellow_background_with_insects = create_yellow_background_with_insects(np.array(original_image), detections)
|
202 |
-
detections_json = detections_to_json(detections)
|
203 |
-
results.append((yellow_background_with_insects, json.dumps(detections_json, separators=(',', ':'))))
|
204 |
-
json_outputs.append(detections_json)
|
205 |
json_output_path = "insect_detections.json"
|
206 |
with open(json_output_path, 'w') as json_file:
|
207 |
-
json.dump(
|
208 |
-
return
|
209 |
|
210 |
gr.Interface(
|
211 |
-
fn=
|
212 |
-
inputs=gr.
|
213 |
-
outputs=[gr.
|
214 |
title="π InsectSAM + GroundingDINO Inference",
|
215 |
-
).launch()
|
|
|
191 |
detections_list.append(detection_dict)
|
192 |
return detections_list
|
193 |
|
194 |
+
def process_image(image):
|
195 |
labels = ["insect"]
|
196 |
+
original_image, detections = grounded_segmentation(image, labels, threshold=0.3, polygon_refinement=True)
|
197 |
+
yellow_background_with_insects = create_yellow_background_with_insects(np.array(original_image), detections)
|
198 |
+
detections_json = detections_to_json(detections)
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
json_output_path = "insect_detections.json"
|
200 |
with open(json_output_path, 'w') as json_file:
|
201 |
+
json.dump(detections_json, json_file, indent=4)
|
202 |
+
return yellow_background_with_insects, json.dumps(detections_json, separators=(',', ':'))
|
203 |
|
204 |
gr.Interface(
|
205 |
+
fn=process_image,
|
206 |
+
inputs=gr.Image(type="pil"),
|
207 |
+
outputs=[gr.Image(type="numpy"), gr.Textbox()],
|
208 |
title="π InsectSAM + GroundingDINO Inference",
|
209 |
+
).launch()
|