Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files
README.md
CHANGED
@@ -5,7 +5,7 @@ emoji: 🔥
|
|
5 |
colorFrom: indigo
|
6 |
colorTo: indigo
|
7 |
sdk: gradio
|
8 |
-
sdk_version: 4.
|
9 |
app_file: run.py
|
10 |
pinned: false
|
11 |
hf_oauth: true
|
|
|
5 |
colorFrom: indigo
|
6 |
colorTo: indigo
|
7 |
sdk: gradio
|
8 |
+
sdk_version: 4.36.0
|
9 |
app_file: run.py
|
10 |
pinned: false
|
11 |
hf_oauth: true
|
requirements.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
-
gradio-client @ git+https://github.com/gradio-app/gradio@
|
2 |
-
https://gradio-builds.s3.amazonaws.com/
|
|
|
1 |
+
gradio-client @ git+https://github.com/gradio-app/gradio@a2cd8a9838864596318a686510f15e7998a27880#subdirectory=client/python
|
2 |
+
https://gradio-builds.s3.amazonaws.com/a2cd8a9838864596318a686510f15e7998a27880/gradio-4.36.0-py3-none-any.whl
|
run.ipynb
CHANGED
@@ -1 +1 @@
|
|
1 |
-
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: cancel_events"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import time\n", "import gradio as gr\n", "import atexit\n", "import pathlib\n", "\n", "log_file =
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: cancel_events"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import time\n", "import gradio as gr\n", "import atexit\n", "import pathlib\n", "\n", "log_file = pathlib.Path(__file__).parent / \"cancel_events_output_log.txt\"\n", "\n", "\n", "def fake_diffusion(steps):\n", " log_file.write_text(\"\")\n", " for i in range(steps):\n", " print(f\"Current step: {i}\")\n", " with log_file.open(\"a\") as f:\n", " f.write(f\"Current step: {i}\\n\")\n", " time.sleep(0.2)\n", " yield str(i)\n", "\n", "\n", "def long_prediction(*args, **kwargs):\n", " time.sleep(10)\n", " return 42\n", "\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " with gr.Column():\n", " n = gr.Slider(1, 10, value=9, step=1, label=\"Number Steps\")\n", " run = gr.Button(value=\"Start Iterating\")\n", " output = gr.Textbox(label=\"Iterative Output\")\n", " stop = gr.Button(value=\"Stop Iterating\")\n", " with gr.Column():\n", " textbox = gr.Textbox(label=\"Prompt\")\n", " prediction = gr.Number(label=\"Expensive Calculation\")\n", " run_pred = gr.Button(value=\"Run Expensive Calculation\")\n", " with gr.Column():\n", " cancel_on_change = gr.Textbox(\n", " label=\"Cancel Iteration and Expensive Calculation on Change\"\n", " )\n", " cancel_on_submit = gr.Textbox(\n", " label=\"Cancel Iteration and Expensive Calculation on Submit\"\n", " )\n", " echo = gr.Textbox(label=\"Echo\")\n", " with gr.Row():\n", " with gr.Column():\n", " image = gr.Image(\n", " sources=[\"webcam\"], label=\"Cancel on clear\", interactive=True\n", " )\n", " with gr.Column():\n", " video = gr.Video(\n", " sources=[\"webcam\"], label=\"Cancel on start recording\", interactive=True\n", " )\n", "\n", " click_event = run.click(fake_diffusion, n, output)\n", " stop.click(fn=None, inputs=None, outputs=None, cancels=[click_event])\n", " pred_event = run_pred.click(\n", " fn=long_prediction, inputs=[textbox], outputs=prediction\n", " )\n", "\n", " cancel_on_change.change(None, None, None, cancels=[click_event, pred_event])\n", " cancel_on_submit.submit(\n", " lambda s: s, cancel_on_submit, echo, cancels=[click_event, pred_event]\n", " )\n", " image.clear(None, None, None, cancels=[click_event, pred_event])\n", " video.start_recording(None, None, None, cancels=[click_event, pred_event])\n", "\n", " demo.queue(max_size=20)\n", " atexit.register(lambda: log_file.unlink())\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
run.py
CHANGED
@@ -3,7 +3,8 @@ import gradio as gr
|
|
3 |
import atexit
|
4 |
import pathlib
|
5 |
|
6 |
-
log_file =
|
|
|
7 |
|
8 |
def fake_diffusion(steps):
|
9 |
log_file.write_text("")
|
@@ -32,21 +33,33 @@ with gr.Blocks() as demo:
|
|
32 |
prediction = gr.Number(label="Expensive Calculation")
|
33 |
run_pred = gr.Button(value="Run Expensive Calculation")
|
34 |
with gr.Column():
|
35 |
-
cancel_on_change = gr.Textbox(
|
36 |
-
|
|
|
|
|
|
|
|
|
37 |
echo = gr.Textbox(label="Echo")
|
38 |
with gr.Row():
|
39 |
with gr.Column():
|
40 |
-
image = gr.Image(
|
|
|
|
|
41 |
with gr.Column():
|
42 |
-
video = gr.Video(
|
|
|
|
|
43 |
|
44 |
click_event = run.click(fake_diffusion, n, output)
|
45 |
stop.click(fn=None, inputs=None, outputs=None, cancels=[click_event])
|
46 |
-
pred_event = run_pred.click(
|
|
|
|
|
47 |
|
48 |
cancel_on_change.change(None, None, None, cancels=[click_event, pred_event])
|
49 |
-
cancel_on_submit.submit(
|
|
|
|
|
50 |
image.clear(None, None, None, cancels=[click_event, pred_event])
|
51 |
video.start_recording(None, None, None, cancels=[click_event, pred_event])
|
52 |
|
|
|
3 |
import atexit
|
4 |
import pathlib
|
5 |
|
6 |
+
log_file = pathlib.Path(__file__).parent / "cancel_events_output_log.txt"
|
7 |
+
|
8 |
|
9 |
def fake_diffusion(steps):
|
10 |
log_file.write_text("")
|
|
|
33 |
prediction = gr.Number(label="Expensive Calculation")
|
34 |
run_pred = gr.Button(value="Run Expensive Calculation")
|
35 |
with gr.Column():
|
36 |
+
cancel_on_change = gr.Textbox(
|
37 |
+
label="Cancel Iteration and Expensive Calculation on Change"
|
38 |
+
)
|
39 |
+
cancel_on_submit = gr.Textbox(
|
40 |
+
label="Cancel Iteration and Expensive Calculation on Submit"
|
41 |
+
)
|
42 |
echo = gr.Textbox(label="Echo")
|
43 |
with gr.Row():
|
44 |
with gr.Column():
|
45 |
+
image = gr.Image(
|
46 |
+
sources=["webcam"], label="Cancel on clear", interactive=True
|
47 |
+
)
|
48 |
with gr.Column():
|
49 |
+
video = gr.Video(
|
50 |
+
sources=["webcam"], label="Cancel on start recording", interactive=True
|
51 |
+
)
|
52 |
|
53 |
click_event = run.click(fake_diffusion, n, output)
|
54 |
stop.click(fn=None, inputs=None, outputs=None, cancels=[click_event])
|
55 |
+
pred_event = run_pred.click(
|
56 |
+
fn=long_prediction, inputs=[textbox], outputs=prediction
|
57 |
+
)
|
58 |
|
59 |
cancel_on_change.change(None, None, None, cancels=[click_event, pred_event])
|
60 |
+
cancel_on_submit.submit(
|
61 |
+
lambda s: s, cancel_on_submit, echo, cancels=[click_event, pred_event]
|
62 |
+
)
|
63 |
image.clear(None, None, None, cancels=[click_event, pred_event])
|
64 |
video.start_recording(None, None, None, cancels=[click_event, pred_event])
|
65 |
|