Martin Tomov commited on
Commit
ba1d3f9
β€’
1 Parent(s): ea41ff1
Files changed (1) hide show
  1. app.py +23 -7
app.py CHANGED
@@ -222,10 +222,26 @@ examples = [
222
  ["flower-night.jpg"]
223
  ]
224
 
225
- gr.Interface(
226
- fn=process_image,
227
- inputs=[gr.Image(type="pil"), gr.Checkbox(label="Include JSON", value=False), gr.Checkbox(label="Include Bounding Boxes", value=False)],
228
- outputs=[gr.Image(type="numpy")] + [gr.Image(type="numpy")] * 10 + [gr.Textbox()],
229
- title="InsectSAM 🐞",
230
- examples=examples
231
- ).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
  ["flower-night.jpg"]
223
  ]
224
 
225
+ with gr.Blocks() as demo:
226
+ with gr.Row():
227
+ image_input = gr.Image(type="pil")
228
+ include_json = gr.Checkbox(label="Include JSON", value=False)
229
+ include_bboxes = gr.Checkbox(label="Include Bounding Boxes", value=False)
230
+ submit_button = gr.Button("Submit")
231
+
232
+ annotated_output = gr.Image(type="numpy")
233
+ json_output = gr.Textbox()
234
+ crops_output = gr.Gallery(label="Cropped Bounding Boxes").style(grid=[2], height="auto")
235
+
236
+ def update_outputs(image, include_json, include_bboxes):
237
+ results = process_image(image, include_json, include_bboxes)
238
+ if include_bboxes:
239
+ annotated_img, *crops, json_txt = results
240
+ return (annotated_img, json_txt, crops)
241
+ else:
242
+ annotated_img, json_txt = results
243
+ return (annotated_img, json_txt, [])
244
+
245
+ submit_button.click(update_outputs, [image_input, include_json, include_bboxes], [annotated_output, json_output, crops_output])
246
+
247
+ demo.launch()