Spaces:
Running
Running
Adjust layout and test gallery event listener
Browse files
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.
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
yolos_output = gr.Gallery(label="Detected Objects", object_fit="
|
|
|
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 |
-
|
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()
|