Skip to content

Remove usage of deprecated gr.inputs and gr.outputs from website#1796

Merged
freddyaboulton merged 5 commits into
mainfrom
1786-remove-deprecated-modules-from-website
Jul 19, 2022
Merged

Remove usage of deprecated gr.inputs and gr.outputs from website#1796
freddyaboulton merged 5 commits into
mainfrom
1786-remove-deprecated-modules-from-website

Conversation

@freddyaboulton
Copy link
Copy Markdown
Collaborator

@freddyaboulton freddyaboulton commented Jul 14, 2022

Description

Fixes #1786

Mainly just deleted usage of gr.inputs and gr.ouputs but also got rid of usage of the "state" shortcut.

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

@freddyaboulton freddyaboulton marked this pull request as ready for review July 14, 2022 19:05
Comment thread demo/chatbot_demo/run.py Outdated
return history, history


state = gr.Variable(value=[])
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.

using "state" is technically deprecated so I'm using gr.Variable here.

It makes the demo more verbose but it's more aligned with our current api. What do people think? Also had to modify the chatbot and real-time speech recognition guides.

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.

Actually I think "state" shortcut is not deprecated in Interfaces. Is this demo not working for you as is @freddyaboulton? Because I just tested it on my end and it is working for me!

cc @aliabid94 as well

Another type of data persistence Gradio supports is session **state**, where data persists across multiple submits within a page load. However, data is *not* shared between different users of your model. To store data in a session state, you need to do three things: (1) Pass in an extra parameter into your function, which represents the state of the interface. (2) At the end of the function, return the updated value of the state as an extra return value (3) Add the `'state'` input and `'state'` output components when creating your `Interface`. See the chatbot example below:
Another type of data persistence Gradio supports is session **state**, where data persists across multiple submits within a page load. However, data is *not* shared between different users of your model. To store data in a session state, you need to do three things:

1. Pass in an extra parameter into your function, which represents the state of the interface.
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.

Unrelated to the original purpose of this PR but I think using a numbered list is easier to read here:
Screen Shot 2022-07-14 at 4 00 39 PM

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.

Agreed thanks @freddyaboulton!

Comment thread guides/creating_a_chatbot.md Outdated

```python
def predict(input, history=[]):
def predict(input, history):
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.

I think we need this to set the original value of the state

Comment thread guides/advanced_interface_features.md Outdated

1. Pass in an extra parameter into your function, which represents the state of the interface.
2. At the end of the function, return the updated value of the state as an extra return value.
3. Create a `gr.Variable` and pass it as an input and output component of the `Interface`.
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.

Let's resolve the issue about the string shortcut. I think it is an acceptable approach within Interface.

We've deprected "gr.State" but the "state" shortcut should still work, it just maps to "gr.Variable" instead

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.

I'll back out the changes related to the "state" string shortcut!

Much simpler to use and if it's not deprecated no need to remove it from the docs. Thank you

Comment thread demo/chatbot_demo/run.py Outdated


state = gr.Variable(value=[])
chatbot = gr.Chatbot(color_map=("green", "pink")).style()
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.

On the other hand, color_map is not part of the constructor for gr.Chatbot, it's been moved to style()

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.

Great point!

@abidlabs
Copy link
Copy Markdown
Member

Great, thanks for the fix @freddyaboulton! Have some considerations around "state" and whether we should really deprecate it, but otherwise LGTM.

cc @aliabid94

@freddyaboulton freddyaboulton force-pushed the 1786-remove-deprecated-modules-from-website branch from 55a6b00 to a7cdc4f Compare July 18, 2022 14:51
@freddyaboulton
Copy link
Copy Markdown
Collaborator Author

Thanks for the review @abidlabs ! Should be good for another look now - removed all the changes related to the "state" string shortcut.

Copy link
Copy Markdown
Contributor

@omerXfaruq omerXfaruq left a comment

Choose a reason for hiding this comment

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

Thanks for removing deprecated parts from the codebase :)

@freddyaboulton freddyaboulton force-pushed the 1786-remove-deprecated-modules-from-website branch from b8bece2 to 2ad985a Compare July 19, 2022 15:44
@freddyaboulton freddyaboulton merged commit 4a1879e into main Jul 19, 2022
@freddyaboulton freddyaboulton deleted the 1786-remove-deprecated-modules-from-website branch July 19, 2022 15: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.

Remove usage of deprecated inputs and outputs from docs and guides

3 participants