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

Reload mode should preserve states #8855

Open
1 task done
irgolic opened this issue Jul 19, 2024 · 5 comments
Open
1 task done

Reload mode should preserve states #8855

irgolic opened this issue Jul 19, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@irgolic
Copy link

irgolic commented Jul 19, 2024

  • I have searched to see if a similar issue already exists.

Is your feature request related to a problem? Please describe.
I have some components where input variables are specified, they're generated by a gr.render decorator though, so the actual values are stored in a state. The state does not persist reloads, and I need to input the values every time it reloads.

The same does not hold for normal textboxes – those persist just fine.

Describe the solution you'd like
Upon hot reload, gr.State values should stay what they are. Perhaps a key argument should be added to gr.State to facilitate this.

@abidlabs
Copy link
Member

Ah yeah I think adding key to gr.State like we have for the components makes sense -- cc @aliabid94

btw @irgolic can you share a small code snippet so that we can use to test?

@irgolic irgolic changed the title Reload mode does not persist states Reload mode should preserve states Jul 19, 2024
@abidlabs abidlabs added the enhancement New feature or request label Jul 19, 2024
@irgolic
Copy link
Author

irgolic commented Jul 19, 2024

Sure, here's a quick demo:

import gradio as gr


with gr.Blocks() as demo:
    my_state = gr.State([])

    @gr.render(inputs=[my_state])
    def _(rows):
        for r in rows:
            gr.Textbox(r)

    button = gr.Button("+")
    button.click(lambda l: l + ["row"], my_state, my_state)


demo.launch()

@irgolic
Copy link
Author

irgolic commented Jul 26, 2024

Any updates on this? Anything I can do to help expedite?

@freddyaboulton
Copy link
Collaborator

Hi @irgolic - we're busy preparing a 5.0 major release. Contributions on this are welcome - we'd be happy to review any PRs :) 🙏

@irgolic
Copy link
Author

irgolic commented Aug 2, 2024

Hi @freddyaboulton, good luck with the release!

I'd love to contribute, could you review my other outstanding PR first?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants