Spaces:
Running
Running
Modify image_input to allow appending images continuously to the gallery component.
Browse files
app.py
CHANGED
@@ -470,17 +470,26 @@ def get_selection_from_gallery(gallery: list, selected_state: gr.SelectData):
|
|
470 |
|
471 |
return (selected_state.value["image"]["path"], selected_state.value["caption"]), tag_result["strings"], tag_result["rating"], tag_result["character_res"], tag_result["general_res"]
|
472 |
|
473 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
474 |
if gallery is None:
|
475 |
gallery = []
|
476 |
if not images:
|
477 |
return gallery
|
478 |
|
479 |
# Combine the new images with the existing gallery images
|
480 |
-
|
481 |
-
|
482 |
-
else:
|
483 |
-
gallery.extend(images)
|
484 |
return gallery
|
485 |
|
486 |
def remove_image_from_gallery(gallery: list, selected_image: str):
|
@@ -620,10 +629,9 @@ def main():
|
|
620 |
)
|
621 |
|
622 |
# Define the event listener to add the uploaded image to the gallery
|
623 |
-
image_input.change(
|
624 |
-
|
625 |
# When the upload button is clicked, add the new images to the gallery
|
626 |
-
upload_button.upload(
|
627 |
# Event to update the selected image when an image is clicked in the gallery
|
628 |
selected_image = gr.Textbox(label="Selected Image", visible=False)
|
629 |
gallery.select(get_selection_from_gallery, inputs=gallery, outputs=[selected_image, sorted_general_strings, rating, character_res, general_res])
|
|
|
470 |
|
471 |
return (selected_state.value["image"]["path"], selected_state.value["caption"]), tag_result["strings"], tag_result["rating"], tag_result["character_res"], tag_result["general_res"]
|
472 |
|
473 |
+
def append_gallery(gallery: list, image: str):
|
474 |
+
if gallery is None:
|
475 |
+
gallery = []
|
476 |
+
if not image:
|
477 |
+
return gallery, None
|
478 |
+
|
479 |
+
gallery.append(image)
|
480 |
+
|
481 |
+
return gallery, None
|
482 |
+
|
483 |
+
|
484 |
+
def extend_gallery(gallery: list, images):
|
485 |
if gallery is None:
|
486 |
gallery = []
|
487 |
if not images:
|
488 |
return gallery
|
489 |
|
490 |
# Combine the new images with the existing gallery images
|
491 |
+
gallery.extend(images)
|
492 |
+
|
|
|
|
|
493 |
return gallery
|
494 |
|
495 |
def remove_image_from_gallery(gallery: list, selected_image: str):
|
|
|
629 |
)
|
630 |
|
631 |
# Define the event listener to add the uploaded image to the gallery
|
632 |
+
image_input.change(append_gallery, inputs=[gallery, image_input], outputs=[gallery, image_input])
|
|
|
633 |
# When the upload button is clicked, add the new images to the gallery
|
634 |
+
upload_button.upload(extend_gallery, inputs=[gallery, upload_button], outputs=gallery)
|
635 |
# Event to update the selected image when an image is clicked in the gallery
|
636 |
selected_image = gr.Textbox(label="Selected Image", visible=False)
|
637 |
gallery.select(get_selection_from_gallery, inputs=gallery, outputs=[selected_image, sorted_general_strings, rating, character_res, general_res])
|