Commit
•
b0b5dd0
1
Parent(s):
e46814f
Commit 1: Add 50 file(s)
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +1 -0
- README.md +6 -7
- demos/audio_debugger/cantina.wav +0 -0
- demos/audio_debugger/run.ipynb +1 -0
- demos/audio_debugger/run.py +38 -0
- demos/blocks_essay/run.ipynb +1 -0
- demos/blocks_essay/run.py +51 -0
- demos/blocks_group/run.ipynb +1 -0
- demos/blocks_group/run.py +110 -0
- demos/blocks_js_methods/run.ipynb +1 -0
- demos/blocks_js_methods/run.py +41 -0
- demos/blocks_layout/run.ipynb +1 -0
- demos/blocks_layout/run.py +37 -0
- demos/blocks_multiple_event_triggers/requirements.txt +3 -0
- demos/blocks_multiple_event_triggers/run.ipynb +1 -0
- demos/blocks_multiple_event_triggers/run.py +38 -0
- demos/blocks_update/run.ipynb +1 -0
- demos/blocks_update/run.py +45 -0
- demos/calculator/examples/log.csv +0 -0
- demos/calculator/run.ipynb +1 -0
- demos/calculator/run.py +34 -0
- demos/calculator/screenshot.gif +3 -0
- demos/cancel_events/run.ipynb +1 -0
- demos/cancel_events/run.py +67 -0
- demos/chatbot_multimodal/run.ipynb +1 -0
- demos/chatbot_multimodal/run.py +48 -0
- demos/chatbot_multimodal/tuples_testcase.py +46 -0
- demos/chatinterface_streaming_echo/run.ipynb +1 -0
- demos/chatinterface_streaming_echo/run.py +12 -0
- demos/clear_components/__init__.py +0 -0
- demos/clear_components/requirements.txt +3 -0
- demos/clear_components/run.ipynb +1 -0
- demos/clear_components/run.py +174 -0
- demos/code/file.css +11 -0
- demos/code/run.ipynb +1 -0
- demos/code/run.py +38 -0
- demos/fake_diffusion_with_gif/requirements.txt +3 -0
- demos/fake_diffusion_with_gif/run.ipynb +1 -0
- demos/fake_diffusion_with_gif/run.py +45 -0
- demos/fake_gan/DESCRIPTION.md +1 -0
- demos/fake_gan/run.ipynb +1 -0
- demos/fake_gan/run.py +31 -0
- demos/file_explorer_component_events/dir1/bar.txt +0 -0
- demos/file_explorer_component_events/dir1/foo.txt +0 -0
- demos/file_explorer_component_events/dir2/baz.png +0 -0
- demos/file_explorer_component_events/dir2/foo.png +0 -0
- demos/file_explorer_component_events/dir3/dir3_bar.log +0 -0
- demos/file_explorer_component_events/dir3/dir3_foo.txt +0 -0
- demos/file_explorer_component_events/dir3/dir4/dir5/dir5_foo.txt +0 -0
- demos/file_explorer_component_events/dir3/dir4/dir7/dir7_foo.txt +0 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
demos/calculator/screenshot.gif filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
@@ -1,12 +1,11 @@
|
|
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 5.9.1
|
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: pr-10225-all-demos
|
4 |
+
emoji: 💩
|
5 |
+
colorFrom: indigo
|
6 |
+
colorTo: indigo
|
7 |
sdk: gradio
|
8 |
sdk_version: 5.9.1
|
9 |
+
app_file: run.py
|
10 |
pinned: false
|
11 |
---
|
|
|
|
demos/audio_debugger/cantina.wav
ADDED
Binary file (132 kB). View file
|
|
demos/audio_debugger/run.ipynb
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: audio_debugger"]}, {"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": ["# Downloading files from the demo repo\n", "import os\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/audio_debugger/cantina.wav"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import subprocess\n", "import os\n", "\n", "audio_file = os.path.join(os.path.abspath(''), \"cantina.wav\")\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Tab(\"Audio\"):\n", " gr.Audio(audio_file)\n", " with gr.Tab(\"Interface\"):\n", " gr.Interface(\n", " lambda x: x, \"audio\", \"audio\", examples=[audio_file], cache_examples=True\n", " )\n", " with gr.Tab(\"Streaming\"):\n", " gr.Interface(\n", " lambda x: x,\n", " gr.Audio(streaming=True),\n", " \"audio\",\n", " examples=[audio_file],\n", " cache_examples=True,\n", " )\n", " with gr.Tab(\"console\"):\n", " ip = gr.Textbox(label=\"User IP Address\")\n", " gr.Interface(\n", " lambda cmd: subprocess.run([cmd], capture_output=True, shell=True, check=False)\n", " .stdout.decode(\"utf-8\")\n", " .strip(),\n", " \"text\",\n", " \"text\",\n", " )\n", "\n", " def get_ip(request: gr.Request):\n", " return request.client.host\n", "\n", " demo.load(get_ip, None, ip)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
demos/audio_debugger/run.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import subprocess
|
3 |
+
import os
|
4 |
+
|
5 |
+
audio_file = os.path.join(os.path.dirname(__file__), "cantina.wav")
|
6 |
+
|
7 |
+
with gr.Blocks() as demo:
|
8 |
+
with gr.Tab("Audio"):
|
9 |
+
gr.Audio(audio_file)
|
10 |
+
with gr.Tab("Interface"):
|
11 |
+
gr.Interface(
|
12 |
+
lambda x: x, "audio", "audio", examples=[audio_file], cache_examples=True
|
13 |
+
)
|
14 |
+
with gr.Tab("Streaming"):
|
15 |
+
gr.Interface(
|
16 |
+
lambda x: x,
|
17 |
+
gr.Audio(streaming=True),
|
18 |
+
"audio",
|
19 |
+
examples=[audio_file],
|
20 |
+
cache_examples=True,
|
21 |
+
)
|
22 |
+
with gr.Tab("console"):
|
23 |
+
ip = gr.Textbox(label="User IP Address")
|
24 |
+
gr.Interface(
|
25 |
+
lambda cmd: subprocess.run([cmd], capture_output=True, shell=True, check=False)
|
26 |
+
.stdout.decode("utf-8")
|
27 |
+
.strip(),
|
28 |
+
"text",
|
29 |
+
"text",
|
30 |
+
)
|
31 |
+
|
32 |
+
def get_ip(request: gr.Request):
|
33 |
+
return request.client.host
|
34 |
+
|
35 |
+
demo.load(get_ip, None, ip)
|
36 |
+
|
37 |
+
if __name__ == "__main__":
|
38 |
+
demo.launch()
|
demos/blocks_essay/run.ipynb
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: blocks_essay"]}, {"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 gradio as gr\n", "\n", "countries_cities_dict = {\n", " \"USA\": [\"New York\", \"Los Angeles\", \"Chicago\"],\n", " \"Canada\": [\"Toronto\", \"Montreal\", \"Vancouver\"],\n", " \"Pakistan\": [\"Karachi\", \"Lahore\", \"Islamabad\"],\n", "}\n", "\n", "def change_textbox(choice):\n", " if choice == \"short\":\n", " return gr.Textbox(lines=2, visible=True), gr.Button(interactive=True)\n", " elif choice == \"long\":\n", " return gr.Textbox(lines=8, visible=True, value=\"Lorem ipsum dolor sit amet\"), gr.Button(interactive=True)\n", " else:\n", " return gr.Textbox(visible=False), gr.Button(interactive=False)\n", "\n", "with gr.Blocks() as demo:\n", " radio = gr.Radio(\n", " [\"short\", \"long\", \"none\"], label=\"What kind of essay would you like to write?\"\n", " )\n", " text = gr.Textbox(lines=2, interactive=True, show_copy_button=True)\n", "\n", " with gr.Row():\n", " num = gr.Number(minimum=0, maximum=100, label=\"input\")\n", " out = gr.Number(label=\"output\")\n", " minimum_slider = gr.Slider(0, 100, 0, label=\"min\")\n", " maximum_slider = gr.Slider(0, 100, 100, label=\"max\")\n", " submit_btn = gr.Button(\"Submit\", variant=\"primary\")\n", "\n", " with gr.Row():\n", " country = gr.Dropdown(list(countries_cities_dict.keys()), label=\"Country\")\n", " cities = gr.Dropdown([], label=\"Cities\")\n", " @country.change(inputs=country, outputs=cities)\n", " def update_cities(country):\n", " cities = list(countries_cities_dict[country])\n", " return gr.Dropdown(choices=cities, value=cities[0], interactive=True)\n", "\n", " def reset_bounds(minimum, maximum):\n", " return gr.Number(minimum=minimum, maximum=maximum)\n", "\n", " radio.change(fn=change_textbox, inputs=radio, outputs=[text, submit_btn])\n", " gr.on(\n", " [minimum_slider.change, maximum_slider.change],\n", " reset_bounds,\n", " [minimum_slider, maximum_slider],\n", " outputs=num,\n", " )\n", " num.submit(lambda x: x, num, out)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
demos/blocks_essay/run.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
countries_cities_dict = {
|
4 |
+
"USA": ["New York", "Los Angeles", "Chicago"],
|
5 |
+
"Canada": ["Toronto", "Montreal", "Vancouver"],
|
6 |
+
"Pakistan": ["Karachi", "Lahore", "Islamabad"],
|
7 |
+
}
|
8 |
+
|
9 |
+
def change_textbox(choice):
|
10 |
+
if choice == "short":
|
11 |
+
return gr.Textbox(lines=2, visible=True), gr.Button(interactive=True)
|
12 |
+
elif choice == "long":
|
13 |
+
return gr.Textbox(lines=8, visible=True, value="Lorem ipsum dolor sit amet"), gr.Button(interactive=True)
|
14 |
+
else:
|
15 |
+
return gr.Textbox(visible=False), gr.Button(interactive=False)
|
16 |
+
|
17 |
+
with gr.Blocks() as demo:
|
18 |
+
radio = gr.Radio(
|
19 |
+
["short", "long", "none"], label="What kind of essay would you like to write?"
|
20 |
+
)
|
21 |
+
text = gr.Textbox(lines=2, interactive=True, show_copy_button=True)
|
22 |
+
|
23 |
+
with gr.Row():
|
24 |
+
num = gr.Number(minimum=0, maximum=100, label="input")
|
25 |
+
out = gr.Number(label="output")
|
26 |
+
minimum_slider = gr.Slider(0, 100, 0, label="min")
|
27 |
+
maximum_slider = gr.Slider(0, 100, 100, label="max")
|
28 |
+
submit_btn = gr.Button("Submit", variant="primary")
|
29 |
+
|
30 |
+
with gr.Row():
|
31 |
+
country = gr.Dropdown(list(countries_cities_dict.keys()), label="Country")
|
32 |
+
cities = gr.Dropdown([], label="Cities")
|
33 |
+
@country.change(inputs=country, outputs=cities)
|
34 |
+
def update_cities(country):
|
35 |
+
cities = list(countries_cities_dict[country])
|
36 |
+
return gr.Dropdown(choices=cities, value=cities[0], interactive=True)
|
37 |
+
|
38 |
+
def reset_bounds(minimum, maximum):
|
39 |
+
return gr.Number(minimum=minimum, maximum=maximum)
|
40 |
+
|
41 |
+
radio.change(fn=change_textbox, inputs=radio, outputs=[text, submit_btn])
|
42 |
+
gr.on(
|
43 |
+
[minimum_slider.change, maximum_slider.change],
|
44 |
+
reset_bounds,
|
45 |
+
[minimum_slider, maximum_slider],
|
46 |
+
outputs=num,
|
47 |
+
)
|
48 |
+
num.submit(lambda x: x, num, out)
|
49 |
+
|
50 |
+
if __name__ == "__main__":
|
51 |
+
demo.launch()
|
demos/blocks_group/run.ipynb
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: blocks_group"]}, {"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 gradio as gr\n", "\n", "def greet(name):\n", " return \"Hello \" + name + \"!\"\n", "\n", "with gr.Blocks() as demo:\n", " gr.Markdown(\"### This is a couple of elements without any gr.Group. Form elements naturally group together anyway.\")\n", " gr.Textbox(\"A\")\n", " gr.Number(3)\n", " gr.Button()\n", " gr.Image()\n", " gr.Slider()\n", "\n", " gr.Markdown(\"### This is the same set put in a gr.Group.\")\n", " with gr.Group():\n", " gr.Textbox(\"A\")\n", " gr.Number(3)\n", " gr.Button()\n", " gr.Image()\n", " gr.Slider()\n", "\n", " gr.Markdown(\"### Now in a Row, no group.\")\n", " with gr.Row():\n", " gr.Textbox(\"A\")\n", " gr.Number(3)\n", " gr.Button()\n", " gr.Image()\n", " gr.Slider()\n", "\n", " gr.Markdown(\"### Now in a Row in a group.\")\n", " with gr.Group():\n", " with gr.Row():\n", " gr.Textbox(\"A\")\n", " gr.Number(3)\n", " gr.Button()\n", " gr.Image()\n", " gr.Slider()\n", "\n", " gr.Markdown(\"### Several rows grouped together.\")\n", " with gr.Group():\n", " with gr.Row():\n", " gr.Textbox(\"A\")\n", " gr.Number(3)\n", " gr.Button()\n", " with gr.Row():\n", " gr.Image()\n", " gr.Audio()\n", "\n", " gr.Markdown(\"### Several columns grouped together. If columns are uneven, there is a gray group background.\")\n", " with gr.Group():\n", " with gr.Row():\n", " with gr.Column():\n", " name = gr.Textbox(label=\"Name\")\n", " btn = gr.Button(\"Hello\")\n", " gr.Dropdown([\"a\", \"b\", \"c\"], interactive=True)\n", " gr.Number()\n", " gr.Textbox()\n", " with gr.Column():\n", " gr.Image()\n", " gr.Dropdown([\"a\", \"b\", \"c\"], interactive=True)\n", " with gr.Row():\n", " gr.Number(scale=2)\n", " gr.Textbox()\n", "\n", " gr.Markdown(\"### container=False removes label, padding, and block border, placing elements 'directly' on background.\")\n", " gr.Radio([1,2,3], container=False)\n", " gr.Textbox(container=False)\n", " gr.Image(\"https://picsum.photos/id/237/200/300\", container=False, height=200)\n", "\n", " gr.Markdown(\"### Textbox, Dropdown, and Number input boxes takes up full space when within a group without a container.\")\n", "\n", " with gr.Group():\n", " name = gr.Textbox(label=\"Name\")\n", " output = gr.Textbox(show_label=False, container=False)\n", " greet_btn = gr.Button(\"Greet\")\n", " with gr.Row():\n", " gr.Dropdown([\"a\", \"b\", \"c\"], interactive=True, container=False)\n", " gr.Textbox(container=False)\n", " gr.Number(container=False)\n", " gr.Image(height=100)\n", " greet_btn.click(fn=greet, inputs=name, outputs=output, api_name=\"greet\")\n", "\n", " gr.Markdown(\"### More examples\")\n", "\n", " with gr.Group():\n", " gr.Chatbot()\n", " with gr.Row():\n", " name = gr.Textbox(label=\"Prompot\", container=False)\n", " go = gr.Button(\"go\", scale=0)\n", "\n", " with gr.Column():\n", " gr.Radio([1,2,3], container=False)\n", " gr.Slider(0, 20, container=False)\n", "\n", " with gr.Group():\n", " with gr.Row():\n", " gr.Dropdown([\"a\", \"b\", \"c\"], interactive=True, container=False, elem_id=\"here2\")\n", " gr.Number(container=False)\n", " gr.Textbox(container=False)\n", "\n", " with gr.Row():\n", " with gr.Column():\n", " gr.Dropdown([\"a\", \"b\", \"c\"], interactive=True, container=False, elem_id=\"here2\")\n", " with gr.Column():\n", " gr.Number(container=False)\n", " with gr.Column():\n", " gr.Textbox(container=False)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
demos/blocks_group/run.py
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
def greet(name):
|
4 |
+
return "Hello " + name + "!"
|
5 |
+
|
6 |
+
with gr.Blocks() as demo:
|
7 |
+
gr.Markdown("### This is a couple of elements without any gr.Group. Form elements naturally group together anyway.")
|
8 |
+
gr.Textbox("A")
|
9 |
+
gr.Number(3)
|
10 |
+
gr.Button()
|
11 |
+
gr.Image()
|
12 |
+
gr.Slider()
|
13 |
+
|
14 |
+
gr.Markdown("### This is the same set put in a gr.Group.")
|
15 |
+
with gr.Group():
|
16 |
+
gr.Textbox("A")
|
17 |
+
gr.Number(3)
|
18 |
+
gr.Button()
|
19 |
+
gr.Image()
|
20 |
+
gr.Slider()
|
21 |
+
|
22 |
+
gr.Markdown("### Now in a Row, no group.")
|
23 |
+
with gr.Row():
|
24 |
+
gr.Textbox("A")
|
25 |
+
gr.Number(3)
|
26 |
+
gr.Button()
|
27 |
+
gr.Image()
|
28 |
+
gr.Slider()
|
29 |
+
|
30 |
+
gr.Markdown("### Now in a Row in a group.")
|
31 |
+
with gr.Group():
|
32 |
+
with gr.Row():
|
33 |
+
gr.Textbox("A")
|
34 |
+
gr.Number(3)
|
35 |
+
gr.Button()
|
36 |
+
gr.Image()
|
37 |
+
gr.Slider()
|
38 |
+
|
39 |
+
gr.Markdown("### Several rows grouped together.")
|
40 |
+
with gr.Group():
|
41 |
+
with gr.Row():
|
42 |
+
gr.Textbox("A")
|
43 |
+
gr.Number(3)
|
44 |
+
gr.Button()
|
45 |
+
with gr.Row():
|
46 |
+
gr.Image()
|
47 |
+
gr.Audio()
|
48 |
+
|
49 |
+
gr.Markdown("### Several columns grouped together. If columns are uneven, there is a gray group background.")
|
50 |
+
with gr.Group():
|
51 |
+
with gr.Row():
|
52 |
+
with gr.Column():
|
53 |
+
name = gr.Textbox(label="Name")
|
54 |
+
btn = gr.Button("Hello")
|
55 |
+
gr.Dropdown(["a", "b", "c"], interactive=True)
|
56 |
+
gr.Number()
|
57 |
+
gr.Textbox()
|
58 |
+
with gr.Column():
|
59 |
+
gr.Image()
|
60 |
+
gr.Dropdown(["a", "b", "c"], interactive=True)
|
61 |
+
with gr.Row():
|
62 |
+
gr.Number(scale=2)
|
63 |
+
gr.Textbox()
|
64 |
+
|
65 |
+
gr.Markdown("### container=False removes label, padding, and block border, placing elements 'directly' on background.")
|
66 |
+
gr.Radio([1,2,3], container=False)
|
67 |
+
gr.Textbox(container=False)
|
68 |
+
gr.Image("https://picsum.photos/id/237/200/300", container=False, height=200)
|
69 |
+
|
70 |
+
gr.Markdown("### Textbox, Dropdown, and Number input boxes takes up full space when within a group without a container.")
|
71 |
+
|
72 |
+
with gr.Group():
|
73 |
+
name = gr.Textbox(label="Name")
|
74 |
+
output = gr.Textbox(show_label=False, container=False)
|
75 |
+
greet_btn = gr.Button("Greet")
|
76 |
+
with gr.Row():
|
77 |
+
gr.Dropdown(["a", "b", "c"], interactive=True, container=False)
|
78 |
+
gr.Textbox(container=False)
|
79 |
+
gr.Number(container=False)
|
80 |
+
gr.Image(height=100)
|
81 |
+
greet_btn.click(fn=greet, inputs=name, outputs=output, api_name="greet")
|
82 |
+
|
83 |
+
gr.Markdown("### More examples")
|
84 |
+
|
85 |
+
with gr.Group():
|
86 |
+
gr.Chatbot()
|
87 |
+
with gr.Row():
|
88 |
+
name = gr.Textbox(label="Prompot", container=False)
|
89 |
+
go = gr.Button("go", scale=0)
|
90 |
+
|
91 |
+
with gr.Column():
|
92 |
+
gr.Radio([1,2,3], container=False)
|
93 |
+
gr.Slider(0, 20, container=False)
|
94 |
+
|
95 |
+
with gr.Group():
|
96 |
+
with gr.Row():
|
97 |
+
gr.Dropdown(["a", "b", "c"], interactive=True, container=False, elem_id="here2")
|
98 |
+
gr.Number(container=False)
|
99 |
+
gr.Textbox(container=False)
|
100 |
+
|
101 |
+
with gr.Row():
|
102 |
+
with gr.Column():
|
103 |
+
gr.Dropdown(["a", "b", "c"], interactive=True, container=False, elem_id="here2")
|
104 |
+
with gr.Column():
|
105 |
+
gr.Number(container=False)
|
106 |
+
with gr.Column():
|
107 |
+
gr.Textbox(container=False)
|
108 |
+
|
109 |
+
if __name__ == "__main__":
|
110 |
+
demo.launch()
|
demos/blocks_js_methods/run.ipynb
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: blocks_js_methods"]}, {"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 gradio as gr\n", "\n", "blocks = gr.Blocks()\n", "\n", "with blocks as demo:\n", " subject = gr.Textbox(placeholder=\"subject\")\n", " verb = gr.Radio([\"ate\", \"loved\", \"hated\"])\n", " object = gr.Textbox(placeholder=\"object\")\n", "\n", " with gr.Row():\n", " btn = gr.Button(\"Create sentence.\")\n", " reverse_btn = gr.Button(\"Reverse sentence.\")\n", " foo_bar_btn = gr.Button(\"Append foo\")\n", " reverse_then_to_the_server_btn = gr.Button(\n", " \"Reverse sentence and send to server.\"\n", " )\n", "\n", " def sentence_maker(w1, w2, w3):\n", " return f\"{w1} {w2} {w3}\"\n", "\n", " output1 = gr.Textbox(label=\"output 1\")\n", " output2 = gr.Textbox(label=\"verb\")\n", " output3 = gr.Textbox(label=\"verb reversed\")\n", " output4 = gr.Textbox(label=\"front end process and then send to backend\")\n", "\n", " btn.click(sentence_maker, [subject, verb, object], output1)\n", " reverse_btn.click(\n", " None, [subject, verb, object], output2, js=\"(s, v, o) => o + ' ' + v + ' ' + s\"\n", " )\n", " verb.change(lambda x: x, verb, output3, js=\"(x) => [...x].reverse().join('')\")\n", " foo_bar_btn.click(None, [], subject, js=\"(x) => x + ' foo'\")\n", "\n", " reverse_then_to_the_server_btn.click(\n", " sentence_maker,\n", " [subject, verb, object],\n", " output4,\n", " js=\"(s, v, o) => [s, v, o].map(x => [...x].reverse().join(''))\",\n", " )\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
demos/blocks_js_methods/run.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
blocks = gr.Blocks()
|
4 |
+
|
5 |
+
with blocks as demo:
|
6 |
+
subject = gr.Textbox(placeholder="subject")
|
7 |
+
verb = gr.Radio(["ate", "loved", "hated"])
|
8 |
+
object = gr.Textbox(placeholder="object")
|
9 |
+
|
10 |
+
with gr.Row():
|
11 |
+
btn = gr.Button("Create sentence.")
|
12 |
+
reverse_btn = gr.Button("Reverse sentence.")
|
13 |
+
foo_bar_btn = gr.Button("Append foo")
|
14 |
+
reverse_then_to_the_server_btn = gr.Button(
|
15 |
+
"Reverse sentence and send to server."
|
16 |
+
)
|
17 |
+
|
18 |
+
def sentence_maker(w1, w2, w3):
|
19 |
+
return f"{w1} {w2} {w3}"
|
20 |
+
|
21 |
+
output1 = gr.Textbox(label="output 1")
|
22 |
+
output2 = gr.Textbox(label="verb")
|
23 |
+
output3 = gr.Textbox(label="verb reversed")
|
24 |
+
output4 = gr.Textbox(label="front end process and then send to backend")
|
25 |
+
|
26 |
+
btn.click(sentence_maker, [subject, verb, object], output1)
|
27 |
+
reverse_btn.click(
|
28 |
+
None, [subject, verb, object], output2, js="(s, v, o) => o + ' ' + v + ' ' + s"
|
29 |
+
)
|
30 |
+
verb.change(lambda x: x, verb, output3, js="(x) => [...x].reverse().join('')")
|
31 |
+
foo_bar_btn.click(None, [], subject, js="(x) => x + ' foo'")
|
32 |
+
|
33 |
+
reverse_then_to_the_server_btn.click(
|
34 |
+
sentence_maker,
|
35 |
+
[subject, verb, object],
|
36 |
+
output4,
|
37 |
+
js="(s, v, o) => [s, v, o].map(x => [...x].reverse().join(''))",
|
38 |
+
)
|
39 |
+
|
40 |
+
if __name__ == "__main__":
|
41 |
+
demo.launch()
|
demos/blocks_layout/run.ipynb
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: blocks_layout"]}, {"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 gradio as gr\n", "\n", "demo = gr.Blocks()\n", "\n", "with demo:\n", " with gr.Row():\n", " gr.Image(interactive=True, scale=2)\n", " gr.Image()\n", " with gr.Row():\n", " gr.Textbox(label=\"Text\")\n", " gr.Number(label=\"Count\", scale=2)\n", " gr.Radio(choices=[\"One\", \"Two\"])\n", " with gr.Row():\n", " gr.Button(\"500\", scale=0, min_width=500)\n", " gr.Button(\"A\", scale=0)\n", " gr.Button(\"grow\")\n", " with gr.Row():\n", " gr.Textbox()\n", " gr.Textbox()\n", " gr.Button()\n", " with gr.Row():\n", " with gr.Row():\n", " with gr.Column():\n", " gr.Textbox(label=\"Text\")\n", " gr.Number(label=\"Count\")\n", " gr.Radio(choices=[\"One\", \"Two\"])\n", " gr.Image()\n", " with gr.Column():\n", " gr.Image(interactive=True)\n", " gr.Image()\n", " gr.Image()\n", " gr.Textbox(label=\"Text\")\n", " gr.Number(label=\"Count\")\n", " gr.Radio(choices=[\"One\", \"Two\"])\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
demos/blocks_layout/run.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
demo = gr.Blocks()
|
4 |
+
|
5 |
+
with demo:
|
6 |
+
with gr.Row():
|
7 |
+
gr.Image(interactive=True, scale=2)
|
8 |
+
gr.Image()
|
9 |
+
with gr.Row():
|
10 |
+
gr.Textbox(label="Text")
|
11 |
+
gr.Number(label="Count", scale=2)
|
12 |
+
gr.Radio(choices=["One", "Two"])
|
13 |
+
with gr.Row():
|
14 |
+
gr.Button("500", scale=0, min_width=500)
|
15 |
+
gr.Button("A", scale=0)
|
16 |
+
gr.Button("grow")
|
17 |
+
with gr.Row():
|
18 |
+
gr.Textbox()
|
19 |
+
gr.Textbox()
|
20 |
+
gr.Button()
|
21 |
+
with gr.Row():
|
22 |
+
with gr.Row():
|
23 |
+
with gr.Column():
|
24 |
+
gr.Textbox(label="Text")
|
25 |
+
gr.Number(label="Count")
|
26 |
+
gr.Radio(choices=["One", "Two"])
|
27 |
+
gr.Image()
|
28 |
+
with gr.Column():
|
29 |
+
gr.Image(interactive=True)
|
30 |
+
gr.Image()
|
31 |
+
gr.Image()
|
32 |
+
gr.Textbox(label="Text")
|
33 |
+
gr.Number(label="Count")
|
34 |
+
gr.Radio(choices=["One", "Two"])
|
35 |
+
|
36 |
+
if __name__ == "__main__":
|
37 |
+
demo.launch()
|
demos/blocks_multiple_event_triggers/requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
plotly
|
2 |
+
pypistats
|
3 |
+
python-dateutil
|
demos/blocks_multiple_event_triggers/run.ipynb
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: blocks_multiple_event_triggers"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio plotly pypistats python-dateutil "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import pypistats\n", "from datetime import date\n", "from dateutil.relativedelta import relativedelta\n", "import pandas as pd\n", "\n", "def get_plot(lib, time):\n", " data = pypistats.overall(lib, total=True, format=\"pandas\")\n", " data = data.groupby(\"category\").get_group(\"with_mirrors\").sort_values(\"date\")\n", " start_date = date.today() - relativedelta(months=int(time.split(\" \")[0]))\n", " data = data[(data['date'] > str(start_date))]\n", " data.date = pd.to_datetime(pd.to_datetime(data.date))\n", " return gr.LinePlot(value=data, x=\"date\", y=\"downloads\",\n", " tooltip=['date', 'downloads'],\n", " title=f\"Pypi downloads of {lib} over last {time}\",\n", " overlay_point=True,\n", " height=400,\n", " width=900)\n", "\n", "with gr.Blocks() as demo:\n", " gr.Markdown(\n", " \"\"\"\n", " ## Pypi Download Stats \ud83d\udcc8\n", " See live download stats for all of Hugging Face's open-source libraries \ud83e\udd17\n", " \"\"\")\n", " with gr.Row():\n", " lib = gr.Dropdown([\"transformers\", \"datasets\", \"huggingface-hub\", \"gradio\", \"accelerate\"],\n", " value=\"gradio\", label=\"Library\")\n", " time = gr.Dropdown([\"3 months\", \"6 months\", \"9 months\", \"12 months\"],\n", " value=\"3 months\", label=\"Downloads over the last...\")\n", "\n", " plt = gr.LinePlot()\n", " # You can add multiple event triggers in 2 lines like this\n", " for event in [lib.change, time.change, demo.load]:\n", " event(get_plot, [lib, time], [plt])\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
demos/blocks_multiple_event_triggers/run.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pypistats
|
3 |
+
from datetime import date
|
4 |
+
from dateutil.relativedelta import relativedelta
|
5 |
+
import pandas as pd
|
6 |
+
|
7 |
+
def get_plot(lib, time):
|
8 |
+
data = pypistats.overall(lib, total=True, format="pandas")
|
9 |
+
data = data.groupby("category").get_group("with_mirrors").sort_values("date")
|
10 |
+
start_date = date.today() - relativedelta(months=int(time.split(" ")[0]))
|
11 |
+
data = data[(data['date'] > str(start_date))]
|
12 |
+
data.date = pd.to_datetime(pd.to_datetime(data.date))
|
13 |
+
return gr.LinePlot(value=data, x="date", y="downloads",
|
14 |
+
tooltip=['date', 'downloads'],
|
15 |
+
title=f"Pypi downloads of {lib} over last {time}",
|
16 |
+
overlay_point=True,
|
17 |
+
height=400,
|
18 |
+
width=900)
|
19 |
+
|
20 |
+
with gr.Blocks() as demo:
|
21 |
+
gr.Markdown(
|
22 |
+
"""
|
23 |
+
## Pypi Download Stats 📈
|
24 |
+
See live download stats for all of Hugging Face's open-source libraries 🤗
|
25 |
+
""")
|
26 |
+
with gr.Row():
|
27 |
+
lib = gr.Dropdown(["transformers", "datasets", "huggingface-hub", "gradio", "accelerate"],
|
28 |
+
value="gradio", label="Library")
|
29 |
+
time = gr.Dropdown(["3 months", "6 months", "9 months", "12 months"],
|
30 |
+
value="3 months", label="Downloads over the last...")
|
31 |
+
|
32 |
+
plt = gr.LinePlot()
|
33 |
+
# You can add multiple event triggers in 2 lines like this
|
34 |
+
for event in [lib.change, time.change, demo.load]:
|
35 |
+
event(get_plot, [lib, time], [plt])
|
36 |
+
|
37 |
+
if __name__ == "__main__":
|
38 |
+
demo.launch()
|
demos/blocks_update/run.ipynb
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: blocks_update"]}, {"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 gradio as gr\n", "\n", "with gr.Blocks() as demo:\n", " gr.Markdown(\n", " \"\"\"\n", " # Animal Generator\n", " Once you select a species, the detail panel should be visible.\n", " \"\"\"\n", " )\n", "\n", " species = gr.Radio(label=\"Animal Class\", choices=[\"Mammal\", \"Fish\", \"Bird\"])\n", " animal = gr.Dropdown(label=\"Animal\", choices=[])\n", "\n", " with gr.Column(visible=False) as details_col:\n", " weight = gr.Slider(0, 20)\n", " details = gr.Textbox(label=\"Extra Details\")\n", " generate_btn = gr.Button(\"Generate\")\n", " output = gr.Textbox(label=\"Output\")\n", "\n", " species_map = {\n", " \"Mammal\": [\"Elephant\", \"Giraffe\", \"Hamster\"],\n", " \"Fish\": [\"Shark\", \"Salmon\", \"Tuna\"],\n", " \"Bird\": [\"Chicken\", \"Eagle\", \"Hawk\"],\n", " }\n", "\n", " def filter_species(species):\n", " return gr.Dropdown(\n", " choices=species_map[species], value=species_map[species][1]\n", " ), gr.Column(visible=True)\n", "\n", " species.change(filter_species, species, [animal, details_col])\n", "\n", " def filter_weight(animal):\n", " if animal in (\"Elephant\", \"Shark\", \"Giraffe\"):\n", " return gr.Slider(maximum=100)\n", " else:\n", " return gr.Slider(maximum=20)\n", "\n", " animal.change(filter_weight, animal, weight)\n", " weight.change(lambda w: gr.Textbox(lines=int(w / 10) + 1), weight, details)\n", "\n", " generate_btn.click(lambda x: x, details, output)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
demos/blocks_update/run.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
with gr.Blocks() as demo:
|
4 |
+
gr.Markdown(
|
5 |
+
"""
|
6 |
+
# Animal Generator
|
7 |
+
Once you select a species, the detail panel should be visible.
|
8 |
+
"""
|
9 |
+
)
|
10 |
+
|
11 |
+
species = gr.Radio(label="Animal Class", choices=["Mammal", "Fish", "Bird"])
|
12 |
+
animal = gr.Dropdown(label="Animal", choices=[])
|
13 |
+
|
14 |
+
with gr.Column(visible=False) as details_col:
|
15 |
+
weight = gr.Slider(0, 20)
|
16 |
+
details = gr.Textbox(label="Extra Details")
|
17 |
+
generate_btn = gr.Button("Generate")
|
18 |
+
output = gr.Textbox(label="Output")
|
19 |
+
|
20 |
+
species_map = {
|
21 |
+
"Mammal": ["Elephant", "Giraffe", "Hamster"],
|
22 |
+
"Fish": ["Shark", "Salmon", "Tuna"],
|
23 |
+
"Bird": ["Chicken", "Eagle", "Hawk"],
|
24 |
+
}
|
25 |
+
|
26 |
+
def filter_species(species):
|
27 |
+
return gr.Dropdown(
|
28 |
+
choices=species_map[species], value=species_map[species][1]
|
29 |
+
), gr.Column(visible=True)
|
30 |
+
|
31 |
+
species.change(filter_species, species, [animal, details_col])
|
32 |
+
|
33 |
+
def filter_weight(animal):
|
34 |
+
if animal in ("Elephant", "Shark", "Giraffe"):
|
35 |
+
return gr.Slider(maximum=100)
|
36 |
+
else:
|
37 |
+
return gr.Slider(maximum=20)
|
38 |
+
|
39 |
+
animal.change(filter_weight, animal, weight)
|
40 |
+
weight.change(lambda w: gr.Textbox(lines=int(w / 10) + 1), weight, details)
|
41 |
+
|
42 |
+
generate_btn.click(lambda x: x, details, output)
|
43 |
+
|
44 |
+
if __name__ == "__main__":
|
45 |
+
demo.launch()
|
demos/calculator/examples/log.csv
ADDED
File without changes
|
demos/calculator/run.ipynb
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: calculator"]}, {"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": ["# Downloading files from the demo repo\n", "import os\n", "os.mkdir('examples')\n", "!wget -q -O examples/log.csv https://github.com/gradio-app/gradio/raw/main/demo/calculator/examples/log.csv"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "\n", "def calculator(num1, operation, num2):\n", " if operation == \"add\":\n", " return num1 + num2\n", " elif operation == \"subtract\":\n", " return num1 - num2\n", " elif operation == \"multiply\":\n", " return num1 * num2\n", " elif operation == \"divide\":\n", " if num2 == 0:\n", " raise gr.Error(\"Cannot divide by zero!\")\n", " return num1 / num2\n", "\n", "demo = gr.Interface(\n", " calculator,\n", " [\n", " \"number\",\n", " gr.Radio([\"add\", \"subtract\", \"multiply\", \"divide\"]),\n", " \"number\"\n", " ],\n", " \"number\",\n", " examples=[\n", " [45, \"add\", 3],\n", " [3.14, \"divide\", 2],\n", " [144, \"multiply\", 2.5],\n", " [0, \"subtract\", 1.2],\n", " ],\n", " title=\"Toy Calculator\",\n", " description=\"Here's a sample toy calculator.\",\n", ")\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
demos/calculator/run.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
def calculator(num1, operation, num2):
|
4 |
+
if operation == "add":
|
5 |
+
return num1 + num2
|
6 |
+
elif operation == "subtract":
|
7 |
+
return num1 - num2
|
8 |
+
elif operation == "multiply":
|
9 |
+
return num1 * num2
|
10 |
+
elif operation == "divide":
|
11 |
+
if num2 == 0:
|
12 |
+
raise gr.Error("Cannot divide by zero!")
|
13 |
+
return num1 / num2
|
14 |
+
|
15 |
+
demo = gr.Interface(
|
16 |
+
calculator,
|
17 |
+
[
|
18 |
+
"number",
|
19 |
+
gr.Radio(["add", "subtract", "multiply", "divide"]),
|
20 |
+
"number"
|
21 |
+
],
|
22 |
+
"number",
|
23 |
+
examples=[
|
24 |
+
[45, "add", 3],
|
25 |
+
[3.14, "divide", 2],
|
26 |
+
[144, "multiply", 2.5],
|
27 |
+
[0, "subtract", 1.2],
|
28 |
+
],
|
29 |
+
title="Toy Calculator",
|
30 |
+
description="Here's a sample toy calculator.",
|
31 |
+
)
|
32 |
+
|
33 |
+
if __name__ == "__main__":
|
34 |
+
demo.launch()
|
demos/calculator/screenshot.gif
ADDED
Git LFS Details
|
demos/cancel_events/run.ipynb
ADDED
@@ -0,0 +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 = pathlib.Path(__file__).parent / \"cancel_events_output_log.txt\"\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", "def long_prediction(*args, **kwargs):\n", " time.sleep(10)\n", " return 42\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}
|
demos/cancel_events/run.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
import gradio as gr
|
3 |
+
import atexit
|
4 |
+
import pathlib
|
5 |
+
|
6 |
+
log_file = pathlib.Path(__file__).parent / "cancel_events_output_log.txt"
|
7 |
+
|
8 |
+
def fake_diffusion(steps):
|
9 |
+
log_file.write_text("")
|
10 |
+
for i in range(steps):
|
11 |
+
print(f"Current step: {i}")
|
12 |
+
with log_file.open("a") as f:
|
13 |
+
f.write(f"Current step: {i}\n")
|
14 |
+
time.sleep(0.2)
|
15 |
+
yield str(i)
|
16 |
+
|
17 |
+
def long_prediction(*args, **kwargs):
|
18 |
+
time.sleep(10)
|
19 |
+
return 42
|
20 |
+
|
21 |
+
with gr.Blocks() as demo:
|
22 |
+
with gr.Row():
|
23 |
+
with gr.Column():
|
24 |
+
n = gr.Slider(1, 10, value=9, step=1, label="Number Steps")
|
25 |
+
run = gr.Button(value="Start Iterating")
|
26 |
+
output = gr.Textbox(label="Iterative Output")
|
27 |
+
stop = gr.Button(value="Stop Iterating")
|
28 |
+
with gr.Column():
|
29 |
+
textbox = gr.Textbox(label="Prompt")
|
30 |
+
prediction = gr.Number(label="Expensive Calculation")
|
31 |
+
run_pred = gr.Button(value="Run Expensive Calculation")
|
32 |
+
with gr.Column():
|
33 |
+
cancel_on_change = gr.Textbox(
|
34 |
+
label="Cancel Iteration and Expensive Calculation on Change"
|
35 |
+
)
|
36 |
+
cancel_on_submit = gr.Textbox(
|
37 |
+
label="Cancel Iteration and Expensive Calculation on Submit"
|
38 |
+
)
|
39 |
+
echo = gr.Textbox(label="Echo")
|
40 |
+
with gr.Row():
|
41 |
+
with gr.Column():
|
42 |
+
image = gr.Image(
|
43 |
+
sources=["webcam"], label="Cancel on clear", interactive=True
|
44 |
+
)
|
45 |
+
with gr.Column():
|
46 |
+
video = gr.Video(
|
47 |
+
sources=["webcam"], label="Cancel on start recording", interactive=True
|
48 |
+
)
|
49 |
+
|
50 |
+
click_event = run.click(fake_diffusion, n, output)
|
51 |
+
stop.click(fn=None, inputs=None, outputs=None, cancels=[click_event])
|
52 |
+
pred_event = run_pred.click(
|
53 |
+
fn=long_prediction, inputs=[textbox], outputs=prediction
|
54 |
+
)
|
55 |
+
|
56 |
+
cancel_on_change.change(None, None, None, cancels=[click_event, pred_event])
|
57 |
+
cancel_on_submit.submit(
|
58 |
+
lambda s: s, cancel_on_submit, echo, cancels=[click_event, pred_event]
|
59 |
+
)
|
60 |
+
image.clear(None, None, None, cancels=[click_event, pred_event])
|
61 |
+
video.start_recording(None, None, None, cancels=[click_event, pred_event])
|
62 |
+
|
63 |
+
demo.queue(max_size=20)
|
64 |
+
atexit.register(lambda: log_file.unlink())
|
65 |
+
|
66 |
+
if __name__ == "__main__":
|
67 |
+
demo.launch()
|
demos/chatbot_multimodal/run.ipynb
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: chatbot_multimodal"]}, {"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": ["# Downloading files from the demo repo\n", "import os\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/chatbot_multimodal/tuples_testcase.py"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import time\n", "\n", "# Chatbot demo with multimodal input (text, markdown, LaTeX, code blocks, image, audio, & video). Plus shows support for streaming text.\n", "\n", "\n", "def print_like_dislike(x: gr.LikeData):\n", " print(x.index, x.value, x.liked)\n", "\n", "\n", "def add_message(history, message):\n", " for x in message[\"files\"]:\n", " history.append({\"role\": \"user\", \"content\": {\"path\": x}})\n", " if message[\"text\"] is not None:\n", " history.append({\"role\": \"user\", \"content\": message[\"text\"]})\n", " return history, gr.MultimodalTextbox(value=None, interactive=False)\n", "\n", "\n", "def bot(history: list):\n", " response = \"**That's cool!**\"\n", " history.append({\"role\": \"assistant\", \"content\": \"\"})\n", " for character in response:\n", " history[-1][\"content\"] += character\n", " time.sleep(0.05)\n", " yield history\n", "\n", "\n", "with gr.Blocks() as demo:\n", " chatbot = gr.Chatbot(elem_id=\"chatbot\", bubble_full_width=False, type=\"messages\")\n", "\n", " chat_input = gr.MultimodalTextbox(\n", " interactive=True,\n", " file_count=\"multiple\",\n", " placeholder=\"Enter message or upload file...\",\n", " show_label=False,\n", " sources=[\"microphone\", \"upload\"],\n", " )\n", "\n", " chat_msg = chat_input.submit(\n", " add_message, [chatbot, chat_input], [chatbot, chat_input]\n", " )\n", " bot_msg = chat_msg.then(bot, chatbot, chatbot, api_name=\"bot_response\")\n", " bot_msg.then(lambda: gr.MultimodalTextbox(interactive=True), None, [chat_input])\n", "\n", " chatbot.like(print_like_dislike, None, None, like_user_message=True)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
demos/chatbot_multimodal/run.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import time
|
3 |
+
|
4 |
+
# Chatbot demo with multimodal input (text, markdown, LaTeX, code blocks, image, audio, & video). Plus shows support for streaming text.
|
5 |
+
|
6 |
+
|
7 |
+
def print_like_dislike(x: gr.LikeData):
|
8 |
+
print(x.index, x.value, x.liked)
|
9 |
+
|
10 |
+
|
11 |
+
def add_message(history, message):
|
12 |
+
for x in message["files"]:
|
13 |
+
history.append({"role": "user", "content": {"path": x}})
|
14 |
+
if message["text"] is not None:
|
15 |
+
history.append({"role": "user", "content": message["text"]})
|
16 |
+
return history, gr.MultimodalTextbox(value=None, interactive=False)
|
17 |
+
|
18 |
+
|
19 |
+
def bot(history: list):
|
20 |
+
response = "**That's cool!**"
|
21 |
+
history.append({"role": "assistant", "content": ""})
|
22 |
+
for character in response:
|
23 |
+
history[-1]["content"] += character
|
24 |
+
time.sleep(0.05)
|
25 |
+
yield history
|
26 |
+
|
27 |
+
|
28 |
+
with gr.Blocks() as demo:
|
29 |
+
chatbot = gr.Chatbot(elem_id="chatbot", bubble_full_width=False, type="messages")
|
30 |
+
|
31 |
+
chat_input = gr.MultimodalTextbox(
|
32 |
+
interactive=True,
|
33 |
+
file_count="multiple",
|
34 |
+
placeholder="Enter message or upload file...",
|
35 |
+
show_label=False,
|
36 |
+
sources=["microphone", "upload"],
|
37 |
+
)
|
38 |
+
|
39 |
+
chat_msg = chat_input.submit(
|
40 |
+
add_message, [chatbot, chat_input], [chatbot, chat_input]
|
41 |
+
)
|
42 |
+
bot_msg = chat_msg.then(bot, chatbot, chatbot, api_name="bot_response")
|
43 |
+
bot_msg.then(lambda: gr.MultimodalTextbox(interactive=True), None, [chat_input])
|
44 |
+
|
45 |
+
chatbot.like(print_like_dislike, None, None, like_user_message=True)
|
46 |
+
|
47 |
+
if __name__ == "__main__":
|
48 |
+
demo.launch()
|
demos/chatbot_multimodal/tuples_testcase.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import plotly.express as px
|
3 |
+
|
4 |
+
# Chatbot demo with multimodal input (text, markdown, LaTeX, code blocks, image, audio, & video). Plus shows support for streaming text.
|
5 |
+
|
6 |
+
def random_plot():
|
7 |
+
df = px.data.iris()
|
8 |
+
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species",
|
9 |
+
size='petal_length', hover_data=['petal_width'])
|
10 |
+
return fig
|
11 |
+
|
12 |
+
def print_like_dislike(x: gr.LikeData):
|
13 |
+
print(x.index, x.value, x.liked)
|
14 |
+
|
15 |
+
def add_message(history, message):
|
16 |
+
for x in message["files"]:
|
17 |
+
history.append(((x,), None))
|
18 |
+
if message["text"] is not None:
|
19 |
+
history.append((message["text"], None))
|
20 |
+
return history, gr.MultimodalTextbox(value=None, interactive=False)
|
21 |
+
|
22 |
+
def bot(history):
|
23 |
+
history[-1][1] = "Cool!"
|
24 |
+
return history
|
25 |
+
|
26 |
+
fig = random_plot()
|
27 |
+
|
28 |
+
with gr.Blocks(fill_height=True) as demo:
|
29 |
+
chatbot = gr.Chatbot(
|
30 |
+
elem_id="chatbot",
|
31 |
+
bubble_full_width=False,
|
32 |
+
scale=1,
|
33 |
+
)
|
34 |
+
|
35 |
+
chat_input = gr.MultimodalTextbox(interactive=True,
|
36 |
+
file_count="multiple",
|
37 |
+
placeholder="Enter message or upload file...", show_label=False)
|
38 |
+
|
39 |
+
chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
|
40 |
+
bot_msg = chat_msg.then(bot, chatbot, chatbot, api_name="bot_response")
|
41 |
+
bot_msg.then(lambda: gr.MultimodalTextbox(interactive=True), None, [chat_input])
|
42 |
+
|
43 |
+
chatbot.like(print_like_dislike, None, None)
|
44 |
+
|
45 |
+
if __name__ == "__main__":
|
46 |
+
demo.launch()
|
demos/chatinterface_streaming_echo/run.ipynb
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: chatinterface_streaming_echo"]}, {"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", "def slow_echo(message, history):\n", " for i in range(len(message)):\n", " time.sleep(0.05)\n", " yield \"You typed: \" + message[: i + 1]\n", "\n", "demo = gr.ChatInterface(slow_echo, type=\"messages\")\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
demos/chatinterface_streaming_echo/run.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
def slow_echo(message, history):
|
5 |
+
for i in range(len(message)):
|
6 |
+
time.sleep(0.05)
|
7 |
+
yield "You typed: " + message[: i + 1]
|
8 |
+
|
9 |
+
demo = gr.ChatInterface(slow_echo, type="messages")
|
10 |
+
|
11 |
+
if __name__ == "__main__":
|
12 |
+
demo.launch()
|
demos/clear_components/__init__.py
ADDED
File without changes
|
demos/clear_components/requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
numpy
|
2 |
+
pandas
|
3 |
+
matplotlib
|
demos/clear_components/run.ipynb
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: clear_components"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio numpy pandas matplotlib "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["# Downloading files from the demo repo\n", "import os\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/clear_components/__init__.py"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "from datetime import datetime\n", "import os\n", "import random\n", "import string\n", "import pandas as pd\n", "\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "\n", "def random_plot():\n", " start_year = 2020\n", " x = np.arange(start_year, start_year + 5)\n", " year_count = x.shape[0]\n", " plt_format = \"-\"\n", " fig = plt.figure()\n", " ax = fig.add_subplot(111)\n", " series = np.arange(0, year_count, dtype=float)\n", " series = series**2\n", " series += np.random.rand(year_count)\n", " ax.plot(x, series, plt_format)\n", " return fig\n", "\n", "images = [\n", " \"https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=387&q=80\",\n", " \"https://images.unsplash.com/photo-1554151228-14d9def656e4?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=386&q=80\",\n", " \"https://images.unsplash.com/photo-1542909168-82c3e7fdca5c?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8aHVtYW4lMjBmYWNlfGVufDB8fDB8fA%3D%3D&w=1000&q=80\",\n", "]\n", "file_dir = os.path.join(os.path.abspath(''), \"..\", \"kitchen_sink\", \"files\")\n", "model3d_dir = os.path.join(os.path.abspath(''), \"..\", \"model3D\", \"files\")\n", "highlighted_text_output_1 = [\n", " {\n", " \"entity\": \"I-LOC\",\n", " \"score\": 0.9988978,\n", " \"index\": 2,\n", " \"word\": \"Chicago\",\n", " \"start\": 5,\n", " \"end\": 12,\n", " },\n", " {\n", " \"entity\": \"I-MISC\",\n", " \"score\": 0.9958592,\n", " \"index\": 5,\n", " \"word\": \"Pakistani\",\n", " \"start\": 22,\n", " \"end\": 31,\n", " },\n", "]\n", "highlighted_text_output_2 = [\n", " {\n", " \"entity\": \"I-LOC\",\n", " \"score\": 0.9988978,\n", " \"index\": 2,\n", " \"word\": \"Chicago\",\n", " \"start\": 5,\n", " \"end\": 12,\n", " },\n", " {\n", " \"entity\": \"I-LOC\",\n", " \"score\": 0.9958592,\n", " \"index\": 5,\n", " \"word\": \"Pakistan\",\n", " \"start\": 22,\n", " \"end\": 30,\n", " },\n", "]\n", "\n", "highlighted_text = \"Does Chicago have any Pakistani restaurants\"\n", "\n", "def random_model3d():\n", " model_3d = random.choice(\n", " [os.path.join(model3d_dir, model) for model in os.listdir(model3d_dir) if model != \"source.txt\"]\n", " )\n", " return model_3d\n", "\n", "components = [\n", " gr.Textbox(value=lambda: datetime.now(), label=\"Current Time\"),\n", " gr.Number(value=lambda: random.random(), label=\"Random Percentage\"),\n", " gr.Slider(minimum=0, maximum=100, randomize=True, label=\"Slider with randomize\"),\n", " gr.Slider(\n", " minimum=0,\n", " maximum=1,\n", " value=lambda: random.random(),\n", " label=\"Slider with value func\",\n", " ),\n", " gr.Checkbox(value=lambda: random.random() > 0.5, label=\"Random Checkbox\"),\n", " gr.CheckboxGroup(\n", " choices=[\"a\", \"b\", \"c\", \"d\"],\n", " value=lambda: random.choice([\"a\", \"b\", \"c\", \"d\"]),\n", " label=\"Random CheckboxGroup\",\n", " ),\n", " gr.Radio(\n", " choices=list(string.ascii_lowercase),\n", " value=lambda: random.choice(string.ascii_lowercase),\n", " ),\n", " gr.Dropdown(\n", " choices=[\"a\", \"b\", \"c\", \"d\", \"e\"],\n", " value=lambda: random.choice([\"a\", \"b\", \"c\"]),\n", " ),\n", " gr.Image(\n", " value=lambda: random.choice(images)\n", " ),\n", " gr.Video(value=lambda: os.path.join(file_dir, \"world.mp4\")),\n", " gr.Audio(value=lambda: os.path.join(file_dir, \"cantina.wav\")),\n", " gr.File(\n", " value=lambda: random.choice(\n", " [os.path.join(file_dir, img) for img in os.listdir(file_dir)]\n", " )\n", " ),\n", " gr.Dataframe(\n", " value=lambda: pd.DataFrame({\"random_number_rows\": range(5)}, columns=[\"one\", \"two\", \"three\"]) # type: ignore\n", " ),\n", " gr.ColorPicker(value=lambda: random.choice([\"#000000\", \"#ff0000\", \"#0000FF\"])),\n", " gr.Label(value=lambda: random.choice([\"Pedestrian\", \"Car\", \"Cyclist\"])),\n", " gr.HighlightedText(\n", " value=lambda: random.choice(\n", " [\n", " {\"text\": highlighted_text, \"entities\": highlighted_text_output_1},\n", " {\"text\": highlighted_text, \"entities\": highlighted_text_output_2},\n", " ]\n", " ),\n", " ),\n", " gr.JSON(value=lambda: random.choice([{\"a\": 1}, {\"b\": 2}])),\n", " gr.HTML(\n", " value=lambda: random.choice(\n", " [\n", " '<p style=\"color:red;\">I am red</p>',\n", " '<p style=\"color:blue;\">I am blue</p>',\n", " ]\n", " )\n", " ),\n", " gr.Gallery(\n", " value=lambda: images\n", " ),\n", " gr.Model3D(value=random_model3d),\n", " gr.Plot(value=random_plot),\n", " gr.Markdown(value=lambda: f\"### {random.choice(['Hello', 'Hi', 'Goodbye!'])}\"),\n", "]\n", "\n", "def evaluate_values(*args):\n", " are_false = []\n", " for a in args:\n", " if isinstance(a, (pd.DataFrame, np.ndarray)):\n", " are_false.append(not a.any().any()) # type: ignore\n", " elif isinstance(a, str) and a.startswith(\"#\"):\n", " are_false.append(a == \"#000000\")\n", " else:\n", " are_false.append(not a)\n", " return all(are_false)\n", "\n", "with gr.Blocks() as demo:\n", " for i, component in enumerate(components):\n", " component.label = f\"component_{str(i).zfill(2)}\"\n", " component.render()\n", " clear = gr.ClearButton(value=\"Clear\", components=components)\n", " result = gr.Textbox(label=\"Are all cleared?\")\n", " hide = gr.Button(value=\"Hide\")\n", " reveal = gr.Button(value=\"Reveal\")\n", " clear_button_and_components = components + [clear]\n", " hide.click(\n", " lambda: [c.__class__(visible=False) for c in clear_button_and_components],\n", " inputs=[],\n", " outputs=clear_button_and_components\n", " )\n", " reveal.click(\n", " lambda: [c.__class__(visible=True) for c in clear_button_and_components],\n", " inputs=[],\n", " outputs=clear_button_and_components\n", " )\n", " get_value = gr.Button(value=\"Get Values\")\n", " get_value.click(evaluate_values, components, result)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
demos/clear_components/run.py
ADDED
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from datetime import datetime
|
3 |
+
import os
|
4 |
+
import random
|
5 |
+
import string
|
6 |
+
import pandas as pd
|
7 |
+
|
8 |
+
import numpy as np
|
9 |
+
import matplotlib.pyplot as plt
|
10 |
+
|
11 |
+
def random_plot():
|
12 |
+
start_year = 2020
|
13 |
+
x = np.arange(start_year, start_year + 5)
|
14 |
+
year_count = x.shape[0]
|
15 |
+
plt_format = "-"
|
16 |
+
fig = plt.figure()
|
17 |
+
ax = fig.add_subplot(111)
|
18 |
+
series = np.arange(0, year_count, dtype=float)
|
19 |
+
series = series**2
|
20 |
+
series += np.random.rand(year_count)
|
21 |
+
ax.plot(x, series, plt_format)
|
22 |
+
return fig
|
23 |
+
|
24 |
+
images = [
|
25 |
+
"https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=387&q=80",
|
26 |
+
"https://images.unsplash.com/photo-1554151228-14d9def656e4?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=386&q=80",
|
27 |
+
"https://images.unsplash.com/photo-1542909168-82c3e7fdca5c?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8aHVtYW4lMjBmYWNlfGVufDB8fDB8fA%3D%3D&w=1000&q=80",
|
28 |
+
]
|
29 |
+
file_dir = os.path.join(os.path.dirname(__file__), "..", "kitchen_sink", "files")
|
30 |
+
model3d_dir = os.path.join(os.path.dirname(__file__), "..", "model3D", "files")
|
31 |
+
highlighted_text_output_1 = [
|
32 |
+
{
|
33 |
+
"entity": "I-LOC",
|
34 |
+
"score": 0.9988978,
|
35 |
+
"index": 2,
|
36 |
+
"word": "Chicago",
|
37 |
+
"start": 5,
|
38 |
+
"end": 12,
|
39 |
+
},
|
40 |
+
{
|
41 |
+
"entity": "I-MISC",
|
42 |
+
"score": 0.9958592,
|
43 |
+
"index": 5,
|
44 |
+
"word": "Pakistani",
|
45 |
+
"start": 22,
|
46 |
+
"end": 31,
|
47 |
+
},
|
48 |
+
]
|
49 |
+
highlighted_text_output_2 = [
|
50 |
+
{
|
51 |
+
"entity": "I-LOC",
|
52 |
+
"score": 0.9988978,
|
53 |
+
"index": 2,
|
54 |
+
"word": "Chicago",
|
55 |
+
"start": 5,
|
56 |
+
"end": 12,
|
57 |
+
},
|
58 |
+
{
|
59 |
+
"entity": "I-LOC",
|
60 |
+
"score": 0.9958592,
|
61 |
+
"index": 5,
|
62 |
+
"word": "Pakistan",
|
63 |
+
"start": 22,
|
64 |
+
"end": 30,
|
65 |
+
},
|
66 |
+
]
|
67 |
+
|
68 |
+
highlighted_text = "Does Chicago have any Pakistani restaurants"
|
69 |
+
|
70 |
+
def random_model3d():
|
71 |
+
model_3d = random.choice(
|
72 |
+
[os.path.join(model3d_dir, model) for model in os.listdir(model3d_dir) if model != "source.txt"]
|
73 |
+
)
|
74 |
+
return model_3d
|
75 |
+
|
76 |
+
components = [
|
77 |
+
gr.Textbox(value=lambda: datetime.now(), label="Current Time"),
|
78 |
+
gr.Number(value=lambda: random.random(), label="Random Percentage"),
|
79 |
+
gr.Slider(minimum=0, maximum=100, randomize=True, label="Slider with randomize"),
|
80 |
+
gr.Slider(
|
81 |
+
minimum=0,
|
82 |
+
maximum=1,
|
83 |
+
value=lambda: random.random(),
|
84 |
+
label="Slider with value func",
|
85 |
+
),
|
86 |
+
gr.Checkbox(value=lambda: random.random() > 0.5, label="Random Checkbox"),
|
87 |
+
gr.CheckboxGroup(
|
88 |
+
choices=["a", "b", "c", "d"],
|
89 |
+
value=lambda: random.choice(["a", "b", "c", "d"]),
|
90 |
+
label="Random CheckboxGroup",
|
91 |
+
),
|
92 |
+
gr.Radio(
|
93 |
+
choices=list(string.ascii_lowercase),
|
94 |
+
value=lambda: random.choice(string.ascii_lowercase),
|
95 |
+
),
|
96 |
+
gr.Dropdown(
|
97 |
+
choices=["a", "b", "c", "d", "e"],
|
98 |
+
value=lambda: random.choice(["a", "b", "c"]),
|
99 |
+
),
|
100 |
+
gr.Image(
|
101 |
+
value=lambda: random.choice(images)
|
102 |
+
),
|
103 |
+
gr.Video(value=lambda: os.path.join(file_dir, "world.mp4")),
|
104 |
+
gr.Audio(value=lambda: os.path.join(file_dir, "cantina.wav")),
|
105 |
+
gr.File(
|
106 |
+
value=lambda: random.choice(
|
107 |
+
[os.path.join(file_dir, img) for img in os.listdir(file_dir)]
|
108 |
+
)
|
109 |
+
),
|
110 |
+
gr.Dataframe(
|
111 |
+
value=lambda: pd.DataFrame({"random_number_rows": range(5)}, columns=["one", "two", "three"]) # type: ignore
|
112 |
+
),
|
113 |
+
gr.ColorPicker(value=lambda: random.choice(["#000000", "#ff0000", "#0000FF"])),
|
114 |
+
gr.Label(value=lambda: random.choice(["Pedestrian", "Car", "Cyclist"])),
|
115 |
+
gr.HighlightedText(
|
116 |
+
value=lambda: random.choice(
|
117 |
+
[
|
118 |
+
{"text": highlighted_text, "entities": highlighted_text_output_1},
|
119 |
+
{"text": highlighted_text, "entities": highlighted_text_output_2},
|
120 |
+
]
|
121 |
+
),
|
122 |
+
),
|
123 |
+
gr.JSON(value=lambda: random.choice([{"a": 1}, {"b": 2}])),
|
124 |
+
gr.HTML(
|
125 |
+
value=lambda: random.choice(
|
126 |
+
[
|
127 |
+
'<p style="color:red;">I am red</p>',
|
128 |
+
'<p style="color:blue;">I am blue</p>',
|
129 |
+
]
|
130 |
+
)
|
131 |
+
),
|
132 |
+
gr.Gallery(
|
133 |
+
value=lambda: images
|
134 |
+
),
|
135 |
+
gr.Model3D(value=random_model3d),
|
136 |
+
gr.Plot(value=random_plot),
|
137 |
+
gr.Markdown(value=lambda: f"### {random.choice(['Hello', 'Hi', 'Goodbye!'])}"),
|
138 |
+
]
|
139 |
+
|
140 |
+
def evaluate_values(*args):
|
141 |
+
are_false = []
|
142 |
+
for a in args:
|
143 |
+
if isinstance(a, (pd.DataFrame, np.ndarray)):
|
144 |
+
are_false.append(not a.any().any()) # type: ignore
|
145 |
+
elif isinstance(a, str) and a.startswith("#"):
|
146 |
+
are_false.append(a == "#000000")
|
147 |
+
else:
|
148 |
+
are_false.append(not a)
|
149 |
+
return all(are_false)
|
150 |
+
|
151 |
+
with gr.Blocks() as demo:
|
152 |
+
for i, component in enumerate(components):
|
153 |
+
component.label = f"component_{str(i).zfill(2)}"
|
154 |
+
component.render()
|
155 |
+
clear = gr.ClearButton(value="Clear", components=components)
|
156 |
+
result = gr.Textbox(label="Are all cleared?")
|
157 |
+
hide = gr.Button(value="Hide")
|
158 |
+
reveal = gr.Button(value="Reveal")
|
159 |
+
clear_button_and_components = components + [clear]
|
160 |
+
hide.click(
|
161 |
+
lambda: [c.__class__(visible=False) for c in clear_button_and_components],
|
162 |
+
inputs=[],
|
163 |
+
outputs=clear_button_and_components
|
164 |
+
)
|
165 |
+
reveal.click(
|
166 |
+
lambda: [c.__class__(visible=True) for c in clear_button_and_components],
|
167 |
+
inputs=[],
|
168 |
+
outputs=clear_button_and_components
|
169 |
+
)
|
170 |
+
get_value = gr.Button(value="Get Values")
|
171 |
+
get_value.click(evaluate_values, components, result)
|
172 |
+
|
173 |
+
if __name__ == "__main__":
|
174 |
+
demo.launch()
|
demos/code/file.css
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.class {
|
2 |
+
color: blue;
|
3 |
+
}
|
4 |
+
|
5 |
+
#id {
|
6 |
+
color: pink;
|
7 |
+
}
|
8 |
+
|
9 |
+
div {
|
10 |
+
color: purple;
|
11 |
+
}
|
demos/code/run.ipynb
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: code"]}, {"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": ["# Downloading files from the demo repo\n", "import os\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/code/file.css"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import os\n", "from time import sleep\n", "\n", "css_file = os.path.join(os.path.abspath(''), \"file.css\")\n", "\n", "def set_lang(language):\n", " print(language)\n", " return gr.Code(language=language)\n", "\n", "def set_lang_from_path():\n", " sleep(1)\n", " return gr.Code(open(css_file).read(), language=\"css\")\n", "\n", "def code(language, code):\n", " return gr.Code(code, language=language)\n", "\n", "io = gr.Interface(lambda x: x, \"code\", \"code\")\n", "\n", "with gr.Blocks() as demo:\n", " lang = gr.Dropdown(value=\"python\", choices=gr.Code.languages)\n", " with gr.Row():\n", " code_in = gr.Code(\n", " language=\"python\",\n", " label=\"Input\",\n", " value='def all_odd_elements(sequence):\\n \"\"\"Returns every odd element of the sequence.\"\"\"',\n", " )\n", " code_out = gr.Code(label=\"Output\")\n", " btn = gr.Button(\"Run\")\n", " btn_two = gr.Button(\"Load File\")\n", "\n", " lang.change(set_lang, inputs=lang, outputs=code_in)\n", " btn.click(code, inputs=[lang, code_in], outputs=code_out)\n", " btn_two.click(set_lang_from_path, inputs=None, outputs=code_out)\n", " io.render()\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
demos/code/run.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
from time import sleep
|
4 |
+
|
5 |
+
css_file = os.path.join(os.path.dirname(__file__), "file.css")
|
6 |
+
|
7 |
+
def set_lang(language):
|
8 |
+
print(language)
|
9 |
+
return gr.Code(language=language)
|
10 |
+
|
11 |
+
def set_lang_from_path():
|
12 |
+
sleep(1)
|
13 |
+
return gr.Code(open(css_file).read(), language="css")
|
14 |
+
|
15 |
+
def code(language, code):
|
16 |
+
return gr.Code(code, language=language)
|
17 |
+
|
18 |
+
io = gr.Interface(lambda x: x, "code", "code")
|
19 |
+
|
20 |
+
with gr.Blocks() as demo:
|
21 |
+
lang = gr.Dropdown(value="python", choices=gr.Code.languages)
|
22 |
+
with gr.Row():
|
23 |
+
code_in = gr.Code(
|
24 |
+
language="python",
|
25 |
+
label="Input",
|
26 |
+
value='def all_odd_elements(sequence):\n """Returns every odd element of the sequence."""',
|
27 |
+
)
|
28 |
+
code_out = gr.Code(label="Output")
|
29 |
+
btn = gr.Button("Run")
|
30 |
+
btn_two = gr.Button("Load File")
|
31 |
+
|
32 |
+
lang.change(set_lang, inputs=lang, outputs=code_in)
|
33 |
+
btn.click(code, inputs=[lang, code_in], outputs=code_out)
|
34 |
+
btn_two.click(set_lang_from_path, inputs=None, outputs=code_out)
|
35 |
+
io.render()
|
36 |
+
|
37 |
+
if __name__ == "__main__":
|
38 |
+
demo.launch()
|
demos/fake_diffusion_with_gif/requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
numpy
|
2 |
+
requests
|
3 |
+
Pillow
|
demos/fake_diffusion_with_gif/run.ipynb
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: fake_diffusion_with_gif"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio numpy requests Pillow "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import numpy as np\n", "import time\n", "import os\n", "from PIL import Image\n", "import requests\n", "from io import BytesIO\n", "\n", "def create_gif(images):\n", " pil_images = []\n", " for image in images:\n", " if isinstance(image, str):\n", " response = requests.get(image)\n", " image = Image.open(BytesIO(response.content))\n", " else:\n", " image = Image.fromarray((image * 255).astype(np.uint8))\n", " pil_images.append(image)\n", " fp_out = os.path.join(os.path.abspath(''), \"image.gif\")\n", " img = pil_images.pop(0)\n", " img.save(fp=fp_out, format='GIF', append_images=pil_images,\n", " save_all=True, duration=400, loop=0)\n", " return fp_out\n", "\n", "def fake_diffusion(steps):\n", " rng = np.random.default_rng()\n", " images = []\n", " for _ in range(steps):\n", " time.sleep(1)\n", " image = rng.random((600, 600, 3))\n", " images.append(image)\n", " yield image, gr.Image(visible=False)\n", "\n", " time.sleep(1)\n", " image = \"https://gradio-builds.s3.amazonaws.com/diffusion_image/cute_dog.jpg\"\n", " images.append(image)\n", " gif_path = create_gif(images)\n", "\n", " yield image, gr.Image(value=gif_path, visible=True)\n", "\n", "demo = gr.Interface(fake_diffusion,\n", " inputs=gr.Slider(1, 10, 3, step=1),\n", " outputs=[\"image\", gr.Image(label=\"All Images\", visible=False)])\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
demos/fake_diffusion_with_gif/run.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import time
|
4 |
+
import os
|
5 |
+
from PIL import Image
|
6 |
+
import requests
|
7 |
+
from io import BytesIO
|
8 |
+
|
9 |
+
def create_gif(images):
|
10 |
+
pil_images = []
|
11 |
+
for image in images:
|
12 |
+
if isinstance(image, str):
|
13 |
+
response = requests.get(image)
|
14 |
+
image = Image.open(BytesIO(response.content))
|
15 |
+
else:
|
16 |
+
image = Image.fromarray((image * 255).astype(np.uint8))
|
17 |
+
pil_images.append(image)
|
18 |
+
fp_out = os.path.join(os.path.dirname(__file__), "image.gif")
|
19 |
+
img = pil_images.pop(0)
|
20 |
+
img.save(fp=fp_out, format='GIF', append_images=pil_images,
|
21 |
+
save_all=True, duration=400, loop=0)
|
22 |
+
return fp_out
|
23 |
+
|
24 |
+
def fake_diffusion(steps):
|
25 |
+
rng = np.random.default_rng()
|
26 |
+
images = []
|
27 |
+
for _ in range(steps):
|
28 |
+
time.sleep(1)
|
29 |
+
image = rng.random((600, 600, 3))
|
30 |
+
images.append(image)
|
31 |
+
yield image, gr.Image(visible=False)
|
32 |
+
|
33 |
+
time.sleep(1)
|
34 |
+
image = "https://gradio-builds.s3.amazonaws.com/diffusion_image/cute_dog.jpg"
|
35 |
+
images.append(image)
|
36 |
+
gif_path = create_gif(images)
|
37 |
+
|
38 |
+
yield image, gr.Image(value=gif_path, visible=True)
|
39 |
+
|
40 |
+
demo = gr.Interface(fake_diffusion,
|
41 |
+
inputs=gr.Slider(1, 10, 3, step=1),
|
42 |
+
outputs=["image", gr.Image(label="All Images", visible=False)])
|
43 |
+
|
44 |
+
if __name__ == "__main__":
|
45 |
+
demo.launch()
|
demos/fake_gan/DESCRIPTION.md
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
This is a fake GAN that shows how to create a text-to-image interface for image generation. Check out the Stable Diffusion demo for more: https://hf.co/spaces/stabilityai/stable-diffusion/
|
demos/fake_gan/run.ipynb
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: fake_gan\n", "### This is a fake GAN that shows how to create a text-to-image interface for image generation. Check out the Stable Diffusion demo for more: https://hf.co/spaces/stabilityai/stable-diffusion/\n", " "]}, {"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": ["# This demo needs to be run from the repo folder.\n", "# python demo/fake_gan/run.py\n", "import random\n", "\n", "import gradio as gr\n", "\n", "def fake_gan():\n", " images = [\n", " (random.choice(\n", " [\n", " \"http://www.marketingtool.online/en/face-generator/img/faces/avatar-1151ce9f4b2043de0d2e3b7826127998.jpg\",\n", " \"http://www.marketingtool.online/en/face-generator/img/faces/avatar-116b5e92936b766b7fdfc242649337f7.jpg\",\n", " \"http://www.marketingtool.online/en/face-generator/img/faces/avatar-1163530ca19b5cebe1b002b8ec67b6fc.jpg\",\n", " \"http://www.marketingtool.online/en/face-generator/img/faces/avatar-1116395d6e6a6581eef8b8038f4c8e55.jpg\",\n", " \"http://www.marketingtool.online/en/face-generator/img/faces/avatar-11319be65db395d0e8e6855d18ddcef0.jpg\",\n", " ]\n", " ), f\"label {i}\")\n", " for i in range(3)\n", " ]\n", " return images\n", "\n", "with gr.Blocks() as demo:\n", " gallery = gr.Gallery(\n", " label=\"Generated images\", show_label=False, elem_id=\"gallery\"\n", " , columns=[3], rows=[1], object_fit=\"contain\", height=\"auto\")\n", " btn = gr.Button(\"Generate images\", scale=0)\n", "\n", " btn.click(fake_gan, None, gallery)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
demos/fake_gan/run.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This demo needs to be run from the repo folder.
|
2 |
+
# python demo/fake_gan/run.py
|
3 |
+
import random
|
4 |
+
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
def fake_gan():
|
8 |
+
images = [
|
9 |
+
(random.choice(
|
10 |
+
[
|
11 |
+
"http://www.marketingtool.online/en/face-generator/img/faces/avatar-1151ce9f4b2043de0d2e3b7826127998.jpg",
|
12 |
+
"http://www.marketingtool.online/en/face-generator/img/faces/avatar-116b5e92936b766b7fdfc242649337f7.jpg",
|
13 |
+
"http://www.marketingtool.online/en/face-generator/img/faces/avatar-1163530ca19b5cebe1b002b8ec67b6fc.jpg",
|
14 |
+
"http://www.marketingtool.online/en/face-generator/img/faces/avatar-1116395d6e6a6581eef8b8038f4c8e55.jpg",
|
15 |
+
"http://www.marketingtool.online/en/face-generator/img/faces/avatar-11319be65db395d0e8e6855d18ddcef0.jpg",
|
16 |
+
]
|
17 |
+
), f"label {i}")
|
18 |
+
for i in range(3)
|
19 |
+
]
|
20 |
+
return images
|
21 |
+
|
22 |
+
with gr.Blocks() as demo:
|
23 |
+
gallery = gr.Gallery(
|
24 |
+
label="Generated images", show_label=False, elem_id="gallery"
|
25 |
+
, columns=[3], rows=[1], object_fit="contain", height="auto")
|
26 |
+
btn = gr.Button("Generate images", scale=0)
|
27 |
+
|
28 |
+
btn.click(fake_gan, None, gallery)
|
29 |
+
|
30 |
+
if __name__ == "__main__":
|
31 |
+
demo.launch()
|
demos/file_explorer_component_events/dir1/bar.txt
ADDED
File without changes
|
demos/file_explorer_component_events/dir1/foo.txt
ADDED
File without changes
|
demos/file_explorer_component_events/dir2/baz.png
ADDED
demos/file_explorer_component_events/dir2/foo.png
ADDED
demos/file_explorer_component_events/dir3/dir3_bar.log
ADDED
File without changes
|
demos/file_explorer_component_events/dir3/dir3_foo.txt
ADDED
File without changes
|
demos/file_explorer_component_events/dir3/dir4/dir5/dir5_foo.txt
ADDED
File without changes
|
demos/file_explorer_component_events/dir3/dir4/dir7/dir7_foo.txt
ADDED
File without changes
|