-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Cancel events from other events #2433
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d1abf97
WIP
freddyaboulton 387a45d
Use async iteration
freddyaboulton fac991b
Format + comment
freddyaboulton 1b3bc8e
Very hacky WIP
freddyaboulton 8b430de
Fix synchronization
freddyaboulton 0371b93
Add comments + tidy up implementation
freddyaboulton 5759342
Remove print
freddyaboulton 3129f47
Fix rebase
freddyaboulton bebda1b
Lint
freddyaboulton ba8ae8e
Disconnect queue when cancelled
freddyaboulton 2b89e67
Add stop button for interface automaticallY
freddyaboulton c178bb2
Unit tests + interface fixes
freddyaboulton 786b562
Skip some tests on 3.7
freddyaboulton a903a4d
Skip in 3.7
freddyaboulton 334a789
Fix skip message
freddyaboulton c0ef077
Fix for python 3.7
freddyaboulton b5f92cd
Add stop variant to button variant type union
freddyaboulton 55a47b8
CHANGELOG
freddyaboulton 34b7a7a
Add demos/gifs to the changelog
freddyaboulton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import time | ||
import gradio as gr | ||
|
||
|
||
def fake_diffusion(steps): | ||
for i in range(steps): | ||
print(f"Current step: {i}") | ||
time.sleep(1) | ||
yield str(i) | ||
|
||
|
||
def long_prediction(*args, **kwargs): | ||
time.sleep(10) | ||
return 42 | ||
|
||
|
||
with gr.Blocks() as demo: | ||
with gr.Row(): | ||
with gr.Column(): | ||
n = gr.Slider(1, 10, value=9, step=1, label="Number Steps") | ||
run = gr.Button() | ||
output = gr.Textbox(label="Iterative Output") | ||
stop = gr.Button(value="Stop Iterating") | ||
with gr.Column(): | ||
textbox = gr.Textbox(label="Prompt") | ||
prediction = gr.Number(label="Expensive Calculation") | ||
run_pred = gr.Button(value="Run Expensive Calculation") | ||
with gr.Column(): | ||
cancel_on_change = gr.Textbox(label="Cancel Iteration and Expensive Calculation on Change") | ||
cancel_on_submit = gr.Textbox(label="Cancel Iteration and Expensive Calculation on Submit") | ||
echo = gr.Textbox(label="Echo") | ||
with gr.Row(): | ||
with gr.Column(): | ||
image = gr.Image(source="webcam", tool="editor", label="Cancel on edit", interactive=True) | ||
with gr.Column(): | ||
video = gr.Video(source="webcam", label="Cancel on play", interactive=True) | ||
|
||
click_event = run.click(fake_diffusion, n, output) | ||
stop.click(fn=None, inputs=None, outputs=None, cancels=[click_event]) | ||
pred_event = run_pred.click(fn=long_prediction, inputs=[textbox], outputs=prediction) | ||
|
||
cancel_on_change.change(None, None, None, cancels=[click_event, pred_event]) | ||
cancel_on_submit.submit(lambda s: s, cancel_on_submit, echo, cancels=[click_event, pred_event]) | ||
image.edit(None, None, None, cancels=[click_event, pred_event]) | ||
video.play(None, None, None, cancels=[click_event, pred_event]) | ||
|
||
|
||
if __name__ == "__main__": | ||
demo.queue(concurrency_count=2, max_size=20).launch() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
cancels
to docstring below