gradio icon indicating copy to clipboard operation
gradio copied to clipboard

Pressing "clear" should interrupt and clear an iterative output

Open abidlabs opened this issue 3 years ago • 7 comments

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 avatar Sep 09 '22 13:09 abidlabs

@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?

abidlabs avatar Sep 09 '22 17:09 abidlabs

Ok will take a look.

aliabid94 avatar Sep 09 '22 19:09 aliabid94

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".

freddyaboulton avatar Sep 15 '22 18:09 freddyaboulton

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)

abidlabs avatar Sep 15 '22 21:09 abidlabs

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?

freddyaboulton avatar Sep 15 '22 21:09 freddyaboulton

👍

abidlabs avatar Sep 15 '22 22:09 abidlabs

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.

aliabid94 avatar Sep 19 '22 08:09 aliabid94

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 🤗

simoninithomas avatar Oct 03 '22 09:10 simoninithomas

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

abidlabs avatar Oct 03 '22 14:10 abidlabs

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

simoninithomas avatar Oct 03 '22 14:10 simoninithomas