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

Pressing "clear" should interrupt and clear an iterative output #2220

Closed
abidlabs opened this issue Sep 9, 2022 · 10 comments · Fixed by #2433
Closed

Pressing "clear" should interrupt and clear an iterative output #2220

abidlabs opened this issue Sep 9, 2022 · 10 comments · Fixed by #2433
Assignees
Labels
bug Something isn't working svelte Frontend-related issue (JS)

Comments

@abidlabs
Copy link
Member

abidlabs commented Sep 9, 2022

Currently, when you have an iterative output like this:

import gradio as gr
import numpy as np
import time


def fake_diffusion(steps):
    for _ in range(steps):
        time.sleep(1)
        image = np.random.random((600, 600, 3))
        yield image
    
    image = "https://i.picsum.photos/id/867/600/600.jpg?hmac=qE7QFJwLmlE_WKI7zMH6SgH5iY5fx8ec6ZJQBwKRT44" 
    yield image


demo = gr.Interface(fake_diffusion, 
                    inputs=gr.Slider(1, 10, 3), 
                    outputs="image")
demo.queue()

if __name__ == "__main__":
    demo.launch()

If you press the "Clear" button while the output is iterating, it momentarily clears, but then the output continues iterating. This is not the expected behavior -- instead the output should remain clear and allow the user to resubmit a new input.

@abidlabs abidlabs added bug Something isn't working svelte Frontend-related issue (JS) labels Sep 9, 2022
@abidlabs
Copy link
Member Author

abidlabs commented Sep 9, 2022

@aliabid94 I tried to fix this but I'm not sure how to connect the trigger of the clear button to the websocket-related functions. Would you be able to take a look at this?

@aliabid94 aliabid94 self-assigned this Sep 9, 2022
@aliabid94
Copy link
Collaborator

Ok will take a look.

@freddyaboulton
Copy link
Collaborator

If you press the "Clear" button while the output is iterating, it momentarily clears, but then the output continues iterating.

I actually think the current behavior is correct. To me, Clear doesn't mean "stop all running functions" but rather "reset the visible state of the UI".

@abidlabs
Copy link
Member Author

Yes, the clear button should reset the UI, but the fact that it continues iterating after you hit "clear" is probably frustrating to users (I don't see any use case where you'd want that)

@freddyaboulton
Copy link
Collaborator

I'm wondering if we should add a Stop button if the function is a generator as opposed to having the clear button do two things?

@abidlabs
Copy link
Member Author

abidlabs commented Sep 15, 2022 via email

@aliabid94
Copy link
Collaborator

I think Clear should both "stop" and "clear", and a stop button can just "stop". the submit button can turn into a "stop" button during a pending request. This should be true for generative outputs and regular requests.

@simoninithomas
Copy link

Hi, I'm planning to update the demo but I still have the issue. Is there is something I can change from my side implementation to solve the problem or it's gradio feature pb?
Thanks 🤗

@abidlabs
Copy link
Member Author

abidlabs commented Oct 3, 2022

Sorry for the delay @simoninithomas, I'll look into this today and see if I can get something working!

@simoninithomas
Copy link

No pb and it's not urgent don't worry 🤗. Let me know if/how I can help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working svelte Frontend-related issue (JS)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants