Spaces:
Running
Running
Upload with huggingface_hub
Browse files- README.md +6 -7
- requirements.txt +1 -0
- run.py +49 -0
README.md
CHANGED
@@ -1,12 +1,11 @@
|
|
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.6
|
8 |
-
app_file:
|
9 |
pinned: false
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
+
|
2 |
---
|
3 |
+
title: cancel_events_main
|
4 |
+
emoji: 🔥
|
5 |
+
colorFrom: indigo
|
6 |
+
colorTo: indigo
|
7 |
sdk: gradio
|
8 |
sdk_version: 3.6
|
9 |
+
app_file: run.py
|
10 |
pinned: false
|
11 |
---
|
|
|
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
https://gradio-main-build.s3.amazonaws.com/c3bec6153737855510542e8154391f328ac72606/gradio-3.6-py3-none-any.whl
|
run.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
|
5 |
+
def fake_diffusion(steps):
|
6 |
+
for i in range(steps):
|
7 |
+
print(f"Current step: {i}")
|
8 |
+
time.sleep(1)
|
9 |
+
yield str(i)
|
10 |
+
|
11 |
+
|
12 |
+
def long_prediction(*args, **kwargs):
|
13 |
+
time.sleep(10)
|
14 |
+
return 42
|
15 |
+
|
16 |
+
|
17 |
+
with gr.Blocks() as demo:
|
18 |
+
with gr.Row():
|
19 |
+
with gr.Column():
|
20 |
+
n = gr.Slider(1, 10, value=9, step=1, label="Number Steps")
|
21 |
+
run = gr.Button()
|
22 |
+
output = gr.Textbox(label="Iterative Output")
|
23 |
+
stop = gr.Button(value="Stop Iterating")
|
24 |
+
with gr.Column():
|
25 |
+
textbox = gr.Textbox(label="Prompt")
|
26 |
+
prediction = gr.Number(label="Expensive Calculation")
|
27 |
+
run_pred = gr.Button(value="Run Expensive Calculation")
|
28 |
+
with gr.Column():
|
29 |
+
cancel_on_change = gr.Textbox(label="Cancel Iteration and Expensive Calculation on Change")
|
30 |
+
cancel_on_submit = gr.Textbox(label="Cancel Iteration and Expensive Calculation on Submit")
|
31 |
+
echo = gr.Textbox(label="Echo")
|
32 |
+
with gr.Row():
|
33 |
+
with gr.Column():
|
34 |
+
image = gr.Image(source="webcam", tool="editor", label="Cancel on edit", interactive=True)
|
35 |
+
with gr.Column():
|
36 |
+
video = gr.Video(source="webcam", label="Cancel on play", interactive=True)
|
37 |
+
|
38 |
+
click_event = run.click(fake_diffusion, n, output)
|
39 |
+
stop.click(fn=None, inputs=None, outputs=None, cancels=[click_event])
|
40 |
+
pred_event = run_pred.click(fn=long_prediction, inputs=[textbox], outputs=prediction)
|
41 |
+
|
42 |
+
cancel_on_change.change(None, None, None, cancels=[click_event, pred_event])
|
43 |
+
cancel_on_submit.submit(lambda s: s, cancel_on_submit, echo, cancels=[click_event, pred_event])
|
44 |
+
image.edit(None, None, None, cancels=[click_event, pred_event])
|
45 |
+
video.play(None, None, None, cancels=[click_event, pred_event])
|
46 |
+
|
47 |
+
|
48 |
+
if __name__ == "__main__":
|
49 |
+
demo.queue(concurrency_count=2, max_size=20).launch()
|