rdezwart commited on
Commit
0721dd9
·
1 Parent(s): 8a23239

Debug issues with proceed button functionality

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -72,11 +72,14 @@ def detect_objects(img: Image.Image):
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
- proceed_button.interactive = evt.index is not None
 
80
  return evt.index
81
 
82
 
@@ -95,11 +98,11 @@ if __name__ == "__main__":
95
  with gr.Column():
96
  yolos_input = gr.Image(type="pil")
97
  yolos_submit = gr.Button("Submit")
98
- yolos_output = gr.Gallery(label="Detected Objects", object_fit="scale-down", columns=3, scale=2,
99
  show_share_button=False, allow_preview=False, selected_index=None)
100
 
101
  with gr.Row():
102
- yolos_selected = gr.Number(label="Selected Image Index")
103
  proceed_button = gr.Button("To Moondream", interactive=False)
104
 
105
  with gr.Tab("Inference"):
@@ -112,7 +115,7 @@ if __name__ == "__main__":
112
 
113
  # --- YOLOS --- #
114
  yolos_submit.click(detect_objects, [yolos_input], yolos_output)
115
- yolos_output.select(get_selected_index, None, yolos_selected)
116
 
117
  # --- Moondream --- #
118
  moon_submit.click(answer_question, [moon_img, moon_prompt], moon_output)
 
72
  return box_images
73
 
74
 
75
+ def gallery_selected(evt: gr.SelectData):
76
  """
77
+ Listener for the gallery selection event.
78
+
79
+ :return: index of the currently selected image
80
  """
81
+ proceed_button.interactive = evt.selected
82
+ print(f"Index: {evt.index}, Value: {evt.value}, Selected: {evt.selected}")
83
  return evt.index
84
 
85
 
 
98
  with gr.Column():
99
  yolos_input = gr.Image(type="pil")
100
  yolos_submit = gr.Button("Submit")
101
+ yolos_output = gr.Gallery(label="Detected Objects", object_fit="scale-down", columns=3, scale=1,
102
  show_share_button=False, allow_preview=False, selected_index=None)
103
 
104
  with gr.Row():
105
+ yolos_selected = gr.TextArea(label="Selected Image Index")
106
  proceed_button = gr.Button("To Moondream", interactive=False)
107
 
108
  with gr.Tab("Inference"):
 
115
 
116
  # --- YOLOS --- #
117
  yolos_submit.click(detect_objects, [yolos_input], yolos_output)
118
+ yolos_output.select(gallery_selected, None, yolos_selected)
119
 
120
  # --- Moondream --- #
121
  moon_submit.click(answer_question, [moon_img, moon_prompt], moon_output)