Spaces:
Running
on
Zero
Running
on
Zero
Martin Tomov
commited on
multiple image upload app.py
Browse files
app.py
CHANGED
@@ -191,19 +191,24 @@ 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 |
json_output_path = "insect_detections.json"
|
200 |
with open(json_output_path, 'w') as json_file:
|
201 |
-
json.dump(
|
202 |
-
return
|
203 |
|
204 |
gr.Interface(
|
205 |
-
fn=
|
206 |
-
inputs=gr.
|
207 |
-
outputs=[gr.
|
208 |
title="π InsectSAM + GroundingDINO Inference",
|
209 |
).launch()
|
|
|
191 |
detections_list.append(detection_dict)
|
192 |
return detections_list
|
193 |
|
194 |
+
def process_images(images):
|
195 |
labels = ["insect"]
|
196 |
+
results = []
|
197 |
+
json_outputs = []
|
198 |
+
for image in images:
|
199 |
+
original_image, detections = grounded_segmentation(image, labels, threshold=0.3, polygon_refinement=True)
|
200 |
+
yellow_background_with_insects = create_yellow_background_with_insects(np.array(original_image), detections)
|
201 |
+
detections_json = detections_to_json(detections)
|
202 |
+
results.append((yellow_background_with_insects, json.dumps(detections_json, separators=(',', ':'))))
|
203 |
+
json_outputs.append(detections_json)
|
204 |
json_output_path = "insect_detections.json"
|
205 |
with open(json_output_path, 'w') as json_file:
|
206 |
+
json.dump(json_outputs, json_file, indent=4)
|
207 |
+
return results
|
208 |
|
209 |
gr.Interface(
|
210 |
+
fn=process_images,
|
211 |
+
inputs=gr.File(file_count="multiple", type="file"),
|
212 |
+
outputs=[gr.Gallery(), gr.Textbox()],
|
213 |
title="π InsectSAM + GroundingDINO Inference",
|
214 |
).launch()
|