You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched to see if a similar issue already exists.
Is your feature request related to a problem? Please describe.
Currently, as an interactive component used as an input, the gr.Gallery has several areas that could be improved. For instance, it should support pasting images from the clipboard, allow users to upload new images after the initial upload, and provide the ability to remove specific images.
Describe the solution you'd like
I achieved the functionality I wanted by using additional gr.Image and gr.Button components, as shown below.
withgr.Column(variant="panel"):
# Create an Image component for uploading imagesimage_input=gr.Image(label="Upload an Image or clicking paste from clipboard button", type="filepath", sources=["upload", "clipboard"], height=150)
gallery=gr.Gallery(columns=5, rows=5, show_share_button=False, interactive=True, height="500px", label="Gallery that displaying a grid of images")
withgr.Row():
upload_button=gr.UploadButton("Upload multiple images", file_types=["image"], file_count="multiple", size="sm")
remove_button=gr.Button("Remove Selected Image", size="sm")
# Define the event listener to add the uploaded image to the galleryimage_input.change(add_images_to_gallery, inputs=[gallery, image_input], outputs=gallery)
# When the upload button is clicked, add the new images to the galleryupload_button.upload(add_images_to_gallery, inputs=[gallery, upload_button], outputs=gallery)
# Event to update the selected image when an image is clicked in the galleryselected_image=gr.Textbox(label="Selected Image", visible=False)
gallery.select(get_selection_from_gallery, inputs=gallery, outputs=[selected_image, sorted_general_strings, rating, character_res, general_res])
# Event to remove a selected image from the galleryremove_button.click(remove_image_from_gallery, inputs=[gallery, selected_image], outputs=gallery)
defget_selection_from_gallery(gallery: list, selected_state: gr.SelectData):
ifnotselected_state:
returnselected_statetag_result= { "strings": "", "rating": "", "character_res": "", "general_res": "" }
ifselected_state.value["image"]["path"] intag_results:
tag_result=tag_results[selected_state.value["image"]["path"]]
return (selected_state.value["image"]["path"], selected_state.value["caption"]), tag_result["strings"], tag_result["rating"], tag_result["character_res"], tag_result["general_res"]
defadd_images_to_gallery(gallery: list, images):
ifgalleryisNone:
gallery= []
ifnotimages:
returngallery# Combine the new images with the existing gallery imagesiftype(images) isstr:
gallery.append(images)
else:
gallery.extend(images)
returngallerydefremove_image_from_gallery(gallery: list, selected_image: str):
ifnotgalleryornotselected_image:
returngalleryselected_image=eval(selected_image)
# Remove the selected image from the galleryifselected_imageingallery:
gallery.remove(selected_image)
returngallery
Additional context
Although the custom implementation mentioned above achieves the desired functionality, it is clearly lacking in integration. If Gradio could implement these features as built-in functionality within the gr.Gallery component, it would be extremely useful.
Thank to the gradio team!
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
Currently, as an interactive component used as an input, the gr.Gallery has several areas that could be improved. For instance, it should support pasting images from the clipboard, allow users to upload new images after the initial upload, and provide the ability to remove specific images.
Describe the solution you'd like
I achieved the functionality I wanted by using additional gr.Image and gr.Button components, as shown below.
Additional context
Although the custom implementation mentioned above achieves the desired functionality, it is clearly lacking in integration. If Gradio could implement these features as built-in functionality within the gr.Gallery component, it would be extremely useful.
Thank to the gradio team!
The text was updated successfully, but these errors were encountered: