Martin Tomov commited on
Commit
61fa334
Β·
verified Β·
1 Parent(s): ceceed1

gr.inputs.Image fix

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -185,7 +185,9 @@ def draw_classification_boxes(image_with_insects, detections):
185
  )
186
  return image_with_insects
187
 
188
- def process_image(image):
 
 
189
  labels = ["insect"]
190
  original_image, detections = grounded_segmentation(image, labels, threshold=0.3, polygon_refinement=True)
191
  annotated_image = plot_detections(original_image, detections)
@@ -193,11 +195,10 @@ def process_image(image):
193
  yellow_background_with_boxes = draw_classification_boxes(yellow_background_with_insects.copy(), detections)
194
  return annotated_image, yellow_background_with_boxes
195
 
196
- default_image_url = "https://i.imgur.com/qZOnNAC.jpeg"
197
-
198
  gr.Interface(
199
  fn=process_image,
200
- inputs=gr.Image(type="pil", label="Input Image", default=default_image_url),
201
  outputs=[gr.Image(type="numpy", label="Annotated Image"), gr.Image(type="numpy", label="Yellow Background with Insects")],
202
  title="🐞 InsectSAM + GroundingDINO Inference",
 
203
  ).launch()
 
185
  )
186
  return image_with_insects
187
 
188
+ def process_image(image=None):
189
+ if image is None:
190
+ image = load_image("https://i.imgur.com/qZOnNAC.jpeg")
191
  labels = ["insect"]
192
  original_image, detections = grounded_segmentation(image, labels, threshold=0.3, polygon_refinement=True)
193
  annotated_image = plot_detections(original_image, detections)
 
195
  yellow_background_with_boxes = draw_classification_boxes(yellow_background_with_insects.copy(), detections)
196
  return annotated_image, yellow_background_with_boxes
197
 
 
 
198
  gr.Interface(
199
  fn=process_image,
200
+ inputs=gr.Image(type="pil", label="Input Image"),
201
  outputs=[gr.Image(type="numpy", label="Annotated Image"), gr.Image(type="numpy", label="Yellow Background with Insects")],
202
  title="🐞 InsectSAM + GroundingDINO Inference",
203
+ examples=["https://i.imgur.com/qZOnNAC.jpeg"]
204
  ).launch()