Spaces:
Sleeping
Sleeping
Feed 'selected_image' as function input
Browse files
app.py
CHANGED
|
@@ -82,14 +82,15 @@ def gallery_selected(evt: gr.SelectData) -> tuple[int, gr.Button]:
|
|
| 82 |
return evt.index, gr.Button(interactive=evt.selected)
|
| 83 |
|
| 84 |
|
| 85 |
-
def to_moondream(images: list[tuple[Image.Image, str | None]]) -> tuple[gr.Tabs, Image.Image]:
|
| 86 |
"""
|
| 87 |
Listener that sends selected gallery image to the moondream model.
|
| 88 |
|
| 89 |
:param images: list of images from yolos_gallery
|
|
|
|
| 90 |
:return: new selected tab and selected image (no caption)
|
| 91 |
"""
|
| 92 |
-
return gr.Tabs(selected='moondream'), images[
|
| 93 |
|
| 94 |
|
| 95 |
if __name__ == "__main__":
|
|
@@ -101,7 +102,7 @@ if __name__ == "__main__":
|
|
| 101 |
Final project for IAT 481 at Simon Fraser University, Spring 2024.
|
| 102 |
"""
|
| 103 |
)
|
| 104 |
-
selected_image = gr.Number(visible=False)
|
| 105 |
|
| 106 |
# Referenced: https://github.com/gradio-app/gradio/issues/7726#issuecomment-2028051431
|
| 107 |
with gr.Tabs(selected='yolos') as tabs:
|
|
@@ -128,7 +129,7 @@ if __name__ == "__main__":
|
|
| 128 |
# --- YOLOS --- #
|
| 129 |
yolos_submit.click(detect_objects, [yolos_input], yolos_gallery)
|
| 130 |
yolos_gallery.select(gallery_selected, None, [selected_image, proceed_button])
|
| 131 |
-
proceed_button.click(to_moondream, yolos_gallery, [tabs, moon_img])
|
| 132 |
|
| 133 |
# --- Moondream --- #
|
| 134 |
moon_submit.click(answer_question, [moon_img, moon_prompt], moon_output)
|
|
|
|
| 82 |
return evt.index, gr.Button(interactive=evt.selected)
|
| 83 |
|
| 84 |
|
| 85 |
+
def to_moondream(images: list[tuple[Image.Image, str | None]], index: int) -> tuple[gr.Tabs, Image.Image]:
|
| 86 |
"""
|
| 87 |
Listener that sends selected gallery image to the moondream model.
|
| 88 |
|
| 89 |
:param images: list of images from yolos_gallery
|
| 90 |
+
:param index: index of selected gallery image
|
| 91 |
:return: new selected tab and selected image (no caption)
|
| 92 |
"""
|
| 93 |
+
return gr.Tabs(selected='moondream'), images[index][0]
|
| 94 |
|
| 95 |
|
| 96 |
if __name__ == "__main__":
|
|
|
|
| 102 |
Final project for IAT 481 at Simon Fraser University, Spring 2024.
|
| 103 |
"""
|
| 104 |
)
|
| 105 |
+
selected_image = gr.Number(visible=False, precision=0)
|
| 106 |
|
| 107 |
# Referenced: https://github.com/gradio-app/gradio/issues/7726#issuecomment-2028051431
|
| 108 |
with gr.Tabs(selected='yolos') as tabs:
|
|
|
|
| 129 |
# --- YOLOS --- #
|
| 130 |
yolos_submit.click(detect_objects, [yolos_input], yolos_gallery)
|
| 131 |
yolos_gallery.select(gallery_selected, None, [selected_image, proceed_button])
|
| 132 |
+
proceed_button.click(to_moondream, [yolos_gallery, selected_image], [tabs, moon_img])
|
| 133 |
|
| 134 |
# --- Moondream --- #
|
| 135 |
moon_submit.click(answer_question, [moon_img, moon_prompt], moon_output)
|