-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding the .select event listener #3399
Conversation
🎉 The demo notebooks match the run.py files! 🎉 |
All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-3399-all-demos |
A suggestion on naming: how about
|
CHANGELOG.md
Outdated
@@ -2,7 +2,7 @@ | |||
|
|||
|
|||
## New Features: | |||
No changes to highlight. | |||
- Added the `.focus()` event listener, applicable right now only to the Gallery component. This event has EventData, data that is passed along the API to provide additional information about the event trigger. The EventData for the Gallery component is the index of the gallery item that was clicked. By [@aliabid94](https://github.com/aliabid94) in [PR 3399](https://github.com/gradio-app/gradio/pull/3399) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be great to include a code snippet showing usage in the changelog since this is a pretty big new feature
Very cool @aliabid94! Tested and works well. Should get the frontend reviewed as well though My little demo: import gradio as gr
import numpy as np
def display(images, event_data: gr.EventData):
return images[event_data.data["index"]].name
with gr.Blocks() as demo:
with gr.Row():
f = gr.Files(file_types=["image"], file_count="multiple")
g = gr.Gallery().style(preview=True)
i = gr.Image()
with gr.Row():
s = gr.Button("Start")
s.click(lambda files: [i.name for i in files], f, g)
g.focus(display, f, i)
if __name__ == "__main__":
demo.launch() |
@aliabid94 this looks great to me! I opened PR #3403 to this PR (lol) to show how we can add type hints to the Gallery Event data. I think that will be better for developer experience. Type hints in action for @abidlabs 's example: Let me know what you think |
The reason I didn't want to choose select is because it seems to be very applicable to Radio, Dropdown, etc., and they already have a
Amazing, thanks @freddyaboulton! |
I think we should actually add a This comes up from time to time, see this issue for a mock example: #1431 |
@aliabid94 Needs rebasing on main before i can review. |
Ok fixed. Initially I had only attached the
Done. |
LGTM @aliabid94! Overall docs look great, just left a few nits above for your consideration |
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool PR @aliabid94 ! 🥳
Went through the demos on the PR and everything is working as expected. Didn't detect any regressions in the deployed demos either!
documented target, actually hid data for now because I want users to use the subclasses attributes directly. Data is just an ugly json they shouldn't worry about. |
LGTM @aliabid94! |
I think we're ready to go!! 🚀 |
Adds the
.select()
event listener to various components. This event hasEventData
, data that is passed along the API to provide additional information about the event trigger. Specifically,Gallery
: TheEventData
for the Gallery component is the index of the gallery item that was clicked.Chatbot
: users can select a messageCheckboxGroup
: refers to user selected optionDataframe
: users can select a specific cellDropdown
: refers to user selected optionFile
: users can select a file from a list of filesGallery
: users can select an image from a galleryHighlightedText
: users can selected a highlighted spanLabel
: users can select a categoryRadio
: refers to user selected optionTabItem
: refers to own selected tab nameTab
: refers to user selected tab nameTextbox
: Users can select a subset of textFixes: #1976