Martin Tomov commited on
Commit
3114eb9
Β·
verified Β·
1 Parent(s): b961115

multiple image upload app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
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 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()
 
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()