Fix bugs with gr.update#2157
Conversation
|
All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-2157-all-demos |
|
Just wanted to confirm a few things as I look into this PR:
|
|
Also cc @aliabid94 for his feedback on this API |
|
@abidlabs Thanks for reviewing! Good questions!
EDIT: Just thought of a corner case - what if a user wants to set the value of a text-box to the string "VOID". Need to use an enum so that there aren't conflicts from enum import Enum
class Keywords(Enum):
VOID = "VOID" |
|
Hi @freddyaboulton. It seems that when the output is only slider, the example doesn't work as expected |
|
Hey @freddyaboulton sorry for the late comment, but could we use sentinels to distinguish between the user passing in If this works, it has several advantages: (1) it's not a breaking change (2) it does not introduce any key words / additional syntax that a Gradio user needs to know |
|
Hi @williamberrios ! Thanks for the find. That's a separate issue (not introduced in this PR). I filed an issue for that here: #2191 |
60db0bb to
b566f37
Compare
|
@abidlabs Thank you for the suggestion about "sentinel values". I think it does work - I implemented it by just setting the default value of This should be good for another look! |
|
Will take a look now! |
|
Some minor comments, but LGTM! Nice fix |
Improve comment Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
Use NO_VALUE in tests Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

Description
Fixes #2154 #2156
During #2044, I made it so that
delete_nonewould keepNonein thevaluekey. This was to let users set the value of the component tonullin the front-end which would reset the component value. The problem is thatNoneis the default of thevaluekey in theupdatecomponent method, so the value is always reset, even when users are not trying to reset the value!!The solution I went for was to distinguish the "don't update the value" and "set the value to null" use cases. For the former, we use an enum for the default value of the update method and for the latter, the user can return
Noneas before.The enum I chose is
_Keywords.NO_VALUE. It's not exposed at the top-level gradio package and it's marked "private" by the leading underscore so it should not be autocompleted in IDES. So it should mean that the user did not pass in a value for the"value"key.To test:
The slider value and drop down should be persisted when clicking different radio buttons.
I also added
blocks_updatetoall_demos- slider value should be persisted as well.Checklist: