rdezwart commited on
Commit
cbb61c3
·
1 Parent(s): 9b94c6b

Adjust layout and test gallery event listener

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -72,6 +72,13 @@ def detect_objects(img: Image.Image):
72
  return box_images
73
 
74
 
 
 
 
 
 
 
 
75
  if __name__ == "__main__":
76
  with gr.Blocks() as app:
77
  gr.Markdown(
@@ -83,11 +90,12 @@ if __name__ == "__main__":
83
  )
84
 
85
  with gr.Tab("Object Detection"):
86
- with gr.Column():
87
- yolos_input = gr.Image(type="pil")
88
- yolos_button = gr.Button("Submit")
89
- with gr.Column():
90
- yolos_output = gr.Gallery(label="Detected Objects", object_fit="contain", columns=3)
 
91
 
92
  with gr.Tab("Inference"):
93
  with gr.Row():
@@ -97,7 +105,11 @@ if __name__ == "__main__":
97
  moon_img = gr.Image(label="Image", type="pil")
98
  moon_output = gr.TextArea(label="Output")
99
 
100
- moon_submit.click(answer_question, [moon_img, moon_prompt], moon_output)
101
  yolos_button.click(detect_objects, [yolos_input], yolos_output)
 
 
 
 
102
 
103
  app.queue().launch()
 
72
  return box_images
73
 
74
 
75
+ def get_selected_index(evt: gr.SelectData):
76
+ """
77
+ Returns the selected image from the object detection output gallery.
78
+ """
79
+ return evt.index
80
+
81
+
82
  if __name__ == "__main__":
83
  with gr.Blocks() as app:
84
  gr.Markdown(
 
90
  )
91
 
92
  with gr.Tab("Object Detection"):
93
+ with gr.Row():
94
+ with gr.Column():
95
+ yolos_input = gr.Image(type="pil")
96
+ yolos_button = gr.Button("Submit")
97
+ yolos_output = gr.Gallery(label="Detected Objects", object_fit="scale-down", columns=3, scale=1)
98
+ yolos_selected = gr.Number()
99
 
100
  with gr.Tab("Inference"):
101
  with gr.Row():
 
105
  moon_img = gr.Image(label="Image", type="pil")
106
  moon_output = gr.TextArea(label="Output")
107
 
108
+ # --- YOLOS --- #
109
  yolos_button.click(detect_objects, [yolos_input], yolos_output)
110
+ yolos_output.select(get_selected_index, None, yolos_selected)
111
+
112
+ # --- Moondream --- #
113
+ moon_submit.click(answer_question, [moon_img, moon_prompt], moon_output)
114
 
115
  app.queue().launch()