Skip to content
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

Improvements to State #2100

Merged
merged 15 commits into from Aug 29, 2022
Merged

Improvements to State #2100

merged 15 commits into from Aug 29, 2022

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented Aug 28, 2022

This PR makes some enhancements to session state. First, it introduces gr.State() as an alias of gr.Variable(), unifying the naming we use in Blocks and Interface. To use state in Interface, one can do either of these approaches:

  • gr.Interface(..., "state", "state")
  • gr.Interface(..., gr.State(), gr.State()) (previously, this would not work)

In Blocks, the same approach works as before but using gr.State() instead of gr.Variable().

Some additional tests have been added. The demos and documentation have also been updated to use gr.State(). For backwards compatibility, gr.Variable() is still accepted.

Fixes: #730

@github-actions
Copy link
Contributor

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

@abidlabs abidlabs changed the title Improvements to state Improvements to State Aug 28, 2022
@abidlabs abidlabs marked this pull request as ready for review August 28, 2022 15:06
Copy link
Collaborator

@freddyaboulton freddyaboulton left a comment

Choose a reason for hiding this comment

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

@abidlabs Looks good to me except the change in the config for gr.Variable I note in one of the comments

demo/kitchen_sink_random/run.py Show resolved Hide resolved
gradio/components.py Show resolved Hide resolved
demo/hangman/run.py Show resolved Hide resolved
gradio/interface.py Show resolved Hide resolved

With more complex apps, you will likely have many Variables storing session state in a single Blocks app.
With more complex apps, you will likely have many State variables storing session state in a single Blocks app.
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the interface_state.md guide should we mention that interfaces only support a single state variable? And point them to blocks for more complex state?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure will make the addition

@abidlabs
Copy link
Member Author

Thanks for the catches @freddyaboulton! Have updated the PR and will merge after the tests pass

@abidlabs abidlabs merged commit 4d58ae7 into main Aug 29, 2022
@abidlabs abidlabs deleted the state-fix branch August 29, 2022 16:53
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.

[Blocks] State throws a js error
2 participants