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

Auto-Reloading doesn't run gr.render(input=state_object) #10199

Open
1 task done
cliffxuan opened this issue Dec 13, 2024 · 2 comments
Open
1 task done

Auto-Reloading doesn't run gr.render(input=state_object) #10199

cliffxuan opened this issue Dec 13, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@cliffxuan
Copy link

cliffxuan commented Dec 13, 2024

Describe the bug

Auto-Reloading doesn't run the @gr.render(...) decorated function if the input is a gr.State object.

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

  1. Run this official doc's example on dynamic event listeners
    https://www.gradio.app/guides/dynamic-apps-with-render-decorator#dynamic-event-listeners
import gradio as gr

with gr.Blocks() as demo:
    text_count = gr.State(1)
    add_btn = gr.Button("Add Box")
    add_btn.click(lambda x: x + 1, text_count, text_count)

    @gr.render(inputs=text_count)
    def render_count(count):
        boxes = []
        for i in range(count):
            box = gr.Textbox(key=i, label=f"Box {i}")
            boxes.append(box)

        def merge(*args):
            return " ".join(args)

        merge_btn.click(merge, boxes, output)

    merge_btn = gr.Button("Merge")
    output = gr.Textbox(label="Merged Output")

demo.launch()

it should render correctly like this:
image

  1. Now change the code slightly, e.g. change the button text to Add a Box and wait for auto-reloading to re-render
    image

Screenshot

No response

Logs

No response

System Info

gradio environment  
Gradio Environment Information:
------------------------------
Operating System: Linux
gradio version: 5.3.0
gradio_client version: 1.4.2

Severity

I can work around it by refreshing the page, however, if it works as expected, it will be more ergonomic and make the development experience more enjoyable and less disruptive.

@cliffxuan cliffxuan added the bug Something isn't working label Dec 13, 2024
@abidlabs
Copy link
Member

abidlabs commented Dec 16, 2024

thanks for reporting, cc @aliabid94!

@myke11j
Copy link

myke11j commented Dec 18, 2024

Facing the same issue. I need render decorator to get called on refresh page, so component is loaded using app state rather than static value at the time interface launch.

Is there any other option or workaround to achieve this until the issue is fixed?

timestamp_text = gr.Text(value=f'Last active at {app_state.state['last_sync']}', label='Last activity timestamp')

@gr.render(inputs=timestamp_text)
    def show_ts(text):
        # Get latest value saved in state
        gr.Text(value=f'Last active at {app_state.state['last_sync']}', label='Last activity timestamp')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants