Skip to content

Reset components to original state by setting value to None#2044

Merged
freddyaboulton merged 8 commits into
mainfrom
1672-component-reset
Aug 22, 2022
Merged

Reset components to original state by setting value to None#2044
freddyaboulton merged 8 commits into
mainfrom
1672-component-reset

Conversation

@freddyaboulton
Copy link
Copy Markdown
Collaborator

@freddyaboulton freddyaboulton commented Aug 19, 2022

Description

Fixes #1672

Previously, it was unclear how to reset components to their original state. As stated in the original issue, the "reset" value depended on the component, e.g. "" for textbox and [] for HightlightedText, and None would confusingly not do anything.

This PR makes it so that None will always reset the component to its unset state. The reason None would originally work is that the delete_none util method would delete the value field from the update dict if it was None.

To test:

  • python demo/kitchen_sink_random/reset_component_demo.py and hit the Reset button
  • unit tests

Checklist:

  • I have performed a self-review of my own code
  • My code follows the style guidelines of this project
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@github-actions
Copy link
Copy Markdown
Contributor

All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-2044-all-demos

@freddyaboulton freddyaboulton marked this pull request as ready for review August 19, 2022 15:39
Comment thread gradio/blocks.py Outdated
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All components can now postprocess None

Comment thread gradio/components.py Outdated
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To reset the chatbot

Comment thread gradio/test_data/blocks_configs.py Outdated
Copy link
Copy Markdown
Collaborator Author

@freddyaboulton freddyaboulton Aug 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None is no longer filtered out from the config. I think this is fine because the value is always postprocessed if None is not a "valid" value for the component.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's appropriate to reset these components with None

@freddyaboulton freddyaboulton force-pushed the 1672-component-reset branch 2 times, most recently from 9c47019 to f33b0a8 Compare August 19, 2022 21:33
Comment thread gradio/utils.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest adding something in the docstring to mention the fact that we exclude keys whose name is "value" and the rationale (in case someone is reading the code later wonders why)

@abidlabs
Copy link
Copy Markdown
Member

Nice fix @freddyaboulton! And great tests and demo. You might consider putting the demo in its own separate folder and in a file named run.py. There are a few places in the codebase where we assume demos are all in files called run.py, for example if we try to reference their code in the website. (Nit.)

@freddyaboulton freddyaboulton mentioned this pull request Aug 22, 2022
@freddyaboulton
Copy link
Copy Markdown
Collaborator Author

Thanks for the review @abidlabs !

@freddyaboulton freddyaboulton merged commit e2dc87a into main Aug 22, 2022
@freddyaboulton freddyaboulton deleted the 1672-component-reset branch August 22, 2022 20:05
@freddyaboulton freddyaboulton mentioned this pull request Sep 1, 2022
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make it easier to reset components to their original state when the app first launches

3 participants