Spaces:
Running
on
Zero
Running
on
Zero
Martin Tomov
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -196,15 +196,16 @@ def detections_to_json(detections):
|
|
196 |
def process_image(image, include_json):
|
197 |
labels = ["insect"]
|
198 |
original_image, detections = grounded_segmentation(image, labels, threshold=0.3, polygon_refinement=True)
|
|
|
199 |
yellow_background_with_insects = create_yellow_background_with_insects(np.array(original_image), detections)
|
200 |
if include_json:
|
201 |
detections_json = detections_to_json(detections)
|
202 |
json_output_path = "insect_detections.json"
|
203 |
with open(json_output_path, 'w') as json_file:
|
204 |
json.dump(detections_json, json_file, indent=4)
|
205 |
-
return yellow_background_with_insects, json.dumps(detections_json, separators=(',', ':'))
|
206 |
else:
|
207 |
-
return yellow_background_with_insects, None
|
208 |
|
209 |
examples = [
|
210 |
["flower-night.jpg"]
|
@@ -213,7 +214,7 @@ examples = [
|
|
213 |
gr.Interface(
|
214 |
fn=process_image,
|
215 |
inputs=[gr.Image(type="pil"), gr.Checkbox(label="Include JSON", value=False)],
|
216 |
-
outputs=[gr.Image(type="numpy"), gr.Textbox()],
|
217 |
title="InsectSAM π",
|
218 |
examples=examples
|
219 |
).launch()
|
|
|
196 |
def process_image(image, include_json):
|
197 |
labels = ["insect"]
|
198 |
original_image, detections = grounded_segmentation(image, labels, threshold=0.3, polygon_refinement=True)
|
199 |
+
annotated_image = plot_detections(original_image, detections)
|
200 |
yellow_background_with_insects = create_yellow_background_with_insects(np.array(original_image), detections)
|
201 |
if include_json:
|
202 |
detections_json = detections_to_json(detections)
|
203 |
json_output_path = "insect_detections.json"
|
204 |
with open(json_output_path, 'w') as json_file:
|
205 |
json.dump(detections_json, json_file, indent=4)
|
206 |
+
return annotated_image, yellow_background_with_insects, json.dumps(detections_json, separators=(',', ':'))
|
207 |
else:
|
208 |
+
return annotated_image, yellow_background_with_insects, None
|
209 |
|
210 |
examples = [
|
211 |
["flower-night.jpg"]
|
|
|
214 |
gr.Interface(
|
215 |
fn=process_image,
|
216 |
inputs=[gr.Image(type="pil"), gr.Checkbox(label="Include JSON", value=False)],
|
217 |
+
outputs=[gr.Image(type="numpy"), gr.Image(type="numpy"), gr.Textbox()],
|
218 |
title="InsectSAM π",
|
219 |
examples=examples
|
220 |
).launch()
|