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:
|
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.0.2
|
9 |
app_file: run.py
|
10 |
pinned: false
|
11 |
hf_oauth: true
|
requirements.txt
CHANGED
@@ -1 +1 @@
|
|
1 |
-
https://gradio-builds.s3.amazonaws.com/
|
|
|
1 |
+
https://gradio-builds.s3.amazonaws.com/874005938d65543c4cefe610a17e58d2ec7b3fb1/gradio-4.0.2-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", "\n", "\n", "def fake_diffusion(steps):\n", " for i in range(steps):\n", " print(f\"Current step: {i}\")\n", " time.sleep(
|
|
|
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", "\n", "\n", "def fake_diffusion(steps):\n", " for i in range(steps):\n", " print(f\"Current step: {i}\")\n", " time.sleep(1)\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(label=\"Cancel Iteration and Expensive Calculation on Change\")\n", " cancel_on_submit = gr.Textbox(label=\"Cancel Iteration and Expensive Calculation on Submit\")\n", " echo = gr.Textbox(label=\"Echo\")\n", " with gr.Row():\n", " with gr.Column():\n", " image = gr.Image(sources=[\"webcam\"], tool=\"editor\", label=\"Cancel on edit\", interactive=True)\n", " with gr.Column():\n", " video = gr.Video(sources=[\"webcam\"], label=\"Cancel on play\", interactive=True)\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(fn=long_prediction, inputs=[textbox], outputs=prediction)\n", "\n", " cancel_on_change.change(None, None, None, cancels=[click_event, pred_event])\n", " cancel_on_submit.submit(lambda s: s, cancel_on_submit, echo, cancels=[click_event, pred_event])\n", " image.edit(None, None, None, cancels=[click_event, pred_event])\n", " video.play(None, None, None, cancels=[click_event, pred_event])\n", "\n", " demo.queue(max_size=20)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
run.py
CHANGED
@@ -5,7 +5,7 @@ import gradio as gr
|
|
5 |
def fake_diffusion(steps):
|
6 |
for i in range(steps):
|
7 |
print(f"Current step: {i}")
|
8 |
-
time.sleep(
|
9 |
yield str(i)
|
10 |
|
11 |
|
@@ -31,9 +31,9 @@ with gr.Blocks() as demo:
|
|
31 |
echo = gr.Textbox(label="Echo")
|
32 |
with gr.Row():
|
33 |
with gr.Column():
|
34 |
-
image = gr.Image(
|
35 |
with gr.Column():
|
36 |
-
video = gr.Video(
|
37 |
|
38 |
click_event = run.click(fake_diffusion, n, output)
|
39 |
stop.click(fn=None, inputs=None, outputs=None, cancels=[click_event])
|
@@ -44,7 +44,7 @@ with gr.Blocks() as demo:
|
|
44 |
image.edit(None, None, None, cancels=[click_event, pred_event])
|
45 |
video.play(None, None, None, cancels=[click_event, pred_event])
|
46 |
|
47 |
-
demo.queue(
|
48 |
|
49 |
if __name__ == "__main__":
|
50 |
demo.launch()
|
|
|
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 |
|
|
|
31 |
echo = gr.Textbox(label="Echo")
|
32 |
with gr.Row():
|
33 |
with gr.Column():
|
34 |
+
image = gr.Image(sources=["webcam"], tool="editor", label="Cancel on edit", interactive=True)
|
35 |
with gr.Column():
|
36 |
+
video = gr.Video(sources=["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])
|
|
|
44 |
image.edit(None, None, None, cancels=[click_event, pred_event])
|
45 |
video.play(None, None, None, cancels=[click_event, pred_event])
|
46 |
|
47 |
+
demo.queue(max_size=20)
|
48 |
|
49 |
if __name__ == "__main__":
|
50 |
demo.launch()
|