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
Add a gr.ClearButton
#4456
Add a gr.ClearButton
#4456
Conversation
All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-4456-all-demos |
🎉 The demo notebooks match the run.py files! 🎉 |
Will fix the tests tomorrow, but everything is working locally so opening up for review! |
When filing #1719, I had this functionality in mind so it's ok to close it out with this PR. |
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.
LGTM
@abidlabs I agree it's best if the Clear button behaves the same for all components but it's behaved this way for so long I wonder if users have come to expect the current behavior? Maybe it's safest to use the current clear button implementation in interface unitl 4.0? |
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.
Code for ClearButton
looks great @abidlabs !
@@ -14,7 +14,7 @@ This tutorial will show how to make several kinds of chatbot UIs with Gradio: fi | |||
$demo_chatbot_streaming | |||
|
|||
**Prerequisite**: We'll be using the `gradio.Blocks` class to build our Chatbot demo. | |||
You can [read the Guide to Blocks first](https://gradio.app/quickstart/#blocks-more-flexibility-and-control) if you are not already familiar with it. | |||
You can [read the Guide to Blocks first](https://gradio.app/quickstart/#blocks-more-flexibility-and-control) if you are not already familiar with it. Also please make sure you are using the **latest version** version of Gradio: `pip install --upgrade gradio`. |
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.
nit: This sentence in the guide is outdated now that the clear internal is abstracted away:
Finally, when the `Clear` button is clicked, we assign `None` to the value of the `Chatbot` to clear its entire history.
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.
Ooh good catch
I can implement that, but we'd need some stuff on the frontend to store the original default value. I actually think it's okay to change behavior here, because if they are looking to reset values, they can always just refresh the page manually. |
in light of the above, I’ll go ahead and merge. Thanks @freddyaboulton @aliabid94 for the detailed reviews! |
Hey has this been released as part of the new release of Gradio ? |
Not yet, soon! |
Adds a
gr.ClearButton
which can be used to clear the value of components ingr.Blocks()
. It is also used internally ingr.Interface
.Example:
Also removes the
cleared_value
attribute from components, which will be better for community componentsDiscussion: There was a discrepancy between the behavior of the Clear button for different components. For 4 of our components (
Slider
,CheckboxGroup
,Radio
,Dropdown
), the Clear button set the value to the original default value set by the app developer. For all of our other components, such asTextbox
,Checkbox
,Image
, it explicitly cleared the value (e.g. setting it to "" forTextbox
, unchecked forCheckbox
, or no uploaded image forImage
even if there was originally a default). We should have a single behavior for all of our components -- I've set it so it always clears the value as this is what I think most people expect when they hit Clear.Fixes: #1719
Fixes: #4473