gradio
gradio copied to clipboard
Pressing "clear" should interrupt and clear an iterative output
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.
@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?
Ok will take a look.
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".
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)
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?
👍
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.
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 🤗
Sorry for the delay @simoninithomas, I'll look into this today and see if I can get something working!
No pb and it's not urgent don't worry 🤗. Let me know if/how I can help.