Spaces:
Sleeping
Sleeping
Commit
•
c3392d4
1
Parent(s):
4c47026
Upload with huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +7 -0
- app.py +31 -0
- demos/blocks_component_shortcut/run.py +31 -0
- demos/blocks_essay/run.py +22 -0
- demos/blocks_essay_update/run.py +19 -0
- demos/blocks_flashcards/run.py +92 -0
- demos/blocks_flipper/run.py +27 -0
- demos/blocks_flipper/screenshot.gif +3 -0
- demos/blocks_form/run.py +33 -0
- demos/blocks_gpt/run.py +16 -0
- demos/blocks_hello/run.py +17 -0
- demos/blocks_inputs/config.json +99 -0
- demos/blocks_inputs/lion.jpg +0 -0
- demos/blocks_inputs/run.py +36 -0
- demos/blocks_joined/files/cheetah1.jpg +0 -0
- demos/blocks_joined/run.py +58 -0
- demos/blocks_js_methods/run.py +28 -0
- demos/blocks_kinematics/config.json +124 -0
- demos/blocks_kinematics/run.py +40 -0
- demos/blocks_layout/run.py +31 -0
- demos/blocks_mask/lion.jpg +0 -0
- demos/blocks_mask/run.py +26 -0
- demos/blocks_multiple_event_triggers/run.py +35 -0
- demos/blocks_neural_instrument_coding/flute.wav +0 -0
- demos/blocks_neural_instrument_coding/new-sax-1.mp3 +0 -0
- demos/blocks_neural_instrument_coding/new-sax-1.wav +0 -0
- demos/blocks_neural_instrument_coding/new-sax.wav +0 -0
- demos/blocks_neural_instrument_coding/run.py +143 -0
- demos/blocks_neural_instrument_coding/sax.wav +3 -0
- demos/blocks_neural_instrument_coding/sax2.wav +0 -0
- demos/blocks_neural_instrument_coding/trombone.wav +0 -0
- demos/blocks_outputs/config.json +325 -0
- demos/blocks_outputs/run.py +95 -0
- demos/blocks_page_load/config.json +58 -0
- demos/blocks_page_load/run.py +15 -0
- demos/blocks_plug/run.py +36 -0
- demos/blocks_random_slider/run.py +18 -0
- demos/blocks_scroll/run.py +24 -0
- demos/blocks_simple_squares/config.json +115 -0
- demos/blocks_simple_squares/run.py +23 -0
- demos/blocks_static_textbox/run.py +10 -0
- demos/blocks_style/run.py +104 -0
- demos/blocks_textbox_max_lines/run.py +13 -0
- demos/blocks_update/run.py +46 -0
- demos/blocks_webcam/run.py +13 -0
- demos/blocks_xray/config.json +339 -0
- demos/blocks_xray/run.py +67 -0
- demos/calculator/examples/log.csv +0 -0
- demos/calculator/run.py +31 -0
- demos/calculator/screenshot.gif +3 -0
.gitattributes
CHANGED
@@ -29,3 +29,10 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
29 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
30 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
31 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
30 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
31 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
32 |
+
demos/calculator/screenshot.gif filter=lfs diff=lfs merge=lfs -text
|
33 |
+
demos/blocks_neural_instrument_coding/sax.wav filter=lfs diff=lfs merge=lfs -text
|
34 |
+
demos/kitchen_sink/files/world.mp4 filter=lfs diff=lfs merge=lfs -text
|
35 |
+
demos/image_mod/screenshot.png filter=lfs diff=lfs merge=lfs -text
|
36 |
+
demos/sepia_filter/screenshot.gif filter=lfs diff=lfs merge=lfs -text
|
37 |
+
demos/blocks_flipper/screenshot.gif filter=lfs diff=lfs merge=lfs -text
|
38 |
+
demos/hello_world_2/screenshot.gif filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import importlib
|
2 |
+
import gradio as gr
|
3 |
+
import os
|
4 |
+
import sys
|
5 |
+
import copy
|
6 |
+
import pathlib
|
7 |
+
|
8 |
+
os.environ["SYSTEM"] = "pretend-not-spaces"
|
9 |
+
|
10 |
+
demo_dir = pathlib.Path(__file__).parent / "demos"
|
11 |
+
|
12 |
+
|
13 |
+
all_demos = []
|
14 |
+
for p in os.listdir("./demos"):
|
15 |
+
all_demos.append(p)
|
16 |
+
|
17 |
+
demo_module = None
|
18 |
+
with gr.Blocks() as mega_demo:
|
19 |
+
with gr.Tabs():
|
20 |
+
for demo_name in all_demos:
|
21 |
+
with gr.TabItem(demo_name):
|
22 |
+
old_path = copy.deepcopy(sys.path)
|
23 |
+
sys.path = [os.path.join(demo_dir, demo_name)] + sys.path
|
24 |
+
if demo_module is None:
|
25 |
+
demo_module = importlib.import_module(f"run")
|
26 |
+
else:
|
27 |
+
demo_module = importlib.reload(demo_module)
|
28 |
+
demo_module.demo
|
29 |
+
sys.path = old_path
|
30 |
+
|
31 |
+
mega_demo.launch()
|
demos/blocks_component_shortcut/run.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
|
4 |
+
def greet(str):
|
5 |
+
return str
|
6 |
+
|
7 |
+
|
8 |
+
with gr.Blocks() as demo:
|
9 |
+
"""
|
10 |
+
You can make use of str shortcuts you use in Interface within Blocks as well.
|
11 |
+
|
12 |
+
Interface shortcut example:
|
13 |
+
Interface(greet, "textarea", "textarea")
|
14 |
+
|
15 |
+
You can use
|
16 |
+
1. gr.component()
|
17 |
+
2. gr.templates.Template()
|
18 |
+
3. gr.Template()
|
19 |
+
All the templates are listed in gradio/templates.py
|
20 |
+
"""
|
21 |
+
with gr.Row():
|
22 |
+
text1 = gr.component("textarea")
|
23 |
+
text2 = gr.TextArea()
|
24 |
+
text3 = gr.templates.TextArea()
|
25 |
+
text1.change(greet, text1, text2)
|
26 |
+
text2.change(greet, text2, text3)
|
27 |
+
text3.change(greet, text3, text1)
|
28 |
+
button = gr.component("button")
|
29 |
+
|
30 |
+
if __name__ == "__main__":
|
31 |
+
demo.launch()
|
demos/blocks_essay/run.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
|
4 |
+
def change_textbox(choice):
|
5 |
+
if choice == "short":
|
6 |
+
return gr.Textbox.update(lines=2, visible=True)
|
7 |
+
elif choice == "long":
|
8 |
+
return gr.Textbox.update(lines=8, visible=True)
|
9 |
+
else:
|
10 |
+
return gr.Textbox.update(visible=False)
|
11 |
+
|
12 |
+
|
13 |
+
with gr.Blocks() as demo:
|
14 |
+
radio = gr.Radio(
|
15 |
+
["short", "long", "none"], label="What kind of essay would you like to write?"
|
16 |
+
)
|
17 |
+
text = gr.Textbox(lines=2, interactive=True)
|
18 |
+
|
19 |
+
radio.change(fn=change_textbox, inputs=radio, outputs=text)
|
20 |
+
|
21 |
+
if __name__ == "__main__":
|
22 |
+
demo.launch()
|
demos/blocks_essay_update/run.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
def change_textbox(choice):
|
4 |
+
if choice == "short":
|
5 |
+
return gr.update(lines=2, visible=True, value="Short story: ")
|
6 |
+
elif choice == "long":
|
7 |
+
return gr.update(lines=8, visible=True, value="Long story...")
|
8 |
+
else:
|
9 |
+
return gr.update(visible=False)
|
10 |
+
|
11 |
+
with gr.Blocks() as demo:
|
12 |
+
radio = gr.Radio(
|
13 |
+
["short", "long", "none"], label="Essay Length to Write?"
|
14 |
+
)
|
15 |
+
text = gr.Textbox(lines=2, interactive=True)
|
16 |
+
radio.change(fn=change_textbox, inputs=radio, outputs=text)
|
17 |
+
|
18 |
+
if __name__ == "__main__":
|
19 |
+
demo.launch()
|
demos/blocks_flashcards/run.py
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
demo = gr.Blocks()
|
6 |
+
|
7 |
+
with demo:
|
8 |
+
gr.Markdown(
|
9 |
+
"Load the flashcards in the table below, then use the Practice tab to practice."
|
10 |
+
)
|
11 |
+
|
12 |
+
with gr.Tabs():
|
13 |
+
with gr.TabItem("Word Bank"):
|
14 |
+
flashcards_table = gr.Dataframe(headers=["front", "back"], type="array")
|
15 |
+
with gr.TabItem("Practice"):
|
16 |
+
with gr.Row():
|
17 |
+
with gr.Column():
|
18 |
+
front = gr.Textbox(label="Prompt")
|
19 |
+
with gr.Row():
|
20 |
+
new_btn = gr.Button("New Card").style(full_width=True)
|
21 |
+
flip_btn = gr.Button("Flip Card").style(full_width=True)
|
22 |
+
with gr.Column(visible=False) as answer_col:
|
23 |
+
back = gr.Textbox(label="Answer")
|
24 |
+
selected_card = gr.Variable()
|
25 |
+
with gr.Row():
|
26 |
+
correct_btn = gr.Button(
|
27 |
+
"Correct",
|
28 |
+
).style(full_width=True)
|
29 |
+
incorrect_btn = gr.Button("Incorrect").style(full_width=True)
|
30 |
+
|
31 |
+
with gr.TabItem("Results"):
|
32 |
+
results = gr.Variable(value={})
|
33 |
+
correct_field = gr.Markdown("# Correct: 0")
|
34 |
+
incorrect_field = gr.Markdown("# Incorrect: 0")
|
35 |
+
gr.Markdown("Card Statistics: ")
|
36 |
+
results_table = gr.Dataframe(headers=["Card", "Correct", "Incorrect"])
|
37 |
+
|
38 |
+
def load_new_card(flashcards):
|
39 |
+
card = random.choice(flashcards)
|
40 |
+
return (
|
41 |
+
card,
|
42 |
+
card[0],
|
43 |
+
gr.Column.update(visible=False),
|
44 |
+
)
|
45 |
+
|
46 |
+
new_btn.click(
|
47 |
+
load_new_card,
|
48 |
+
[flashcards_table],
|
49 |
+
[selected_card, front, answer_col],
|
50 |
+
)
|
51 |
+
|
52 |
+
def flip_card(card):
|
53 |
+
return card[1], gr.Column.update(visible=True)
|
54 |
+
|
55 |
+
flip_btn.click(flip_card, [selected_card], [back, answer_col])
|
56 |
+
|
57 |
+
def mark_correct(card, results):
|
58 |
+
if card[0] not in results:
|
59 |
+
results[card[0]] = [0, 0]
|
60 |
+
results[card[0]][0] += 1
|
61 |
+
correct_count = sum(result[0] for result in results.values())
|
62 |
+
return (
|
63 |
+
results,
|
64 |
+
f"# Correct: {correct_count}",
|
65 |
+
[[front, scores[0], scores[1]] for front, scores in results.items()],
|
66 |
+
)
|
67 |
+
|
68 |
+
def mark_incorrect(card, results):
|
69 |
+
if card[0] not in results:
|
70 |
+
results[card[0]] = [0, 0]
|
71 |
+
results[card[0]][1] += 1
|
72 |
+
incorrect_count = sum(result[1] for result in results.values())
|
73 |
+
return (
|
74 |
+
results,
|
75 |
+
f"# Inorrect: {incorrect_count}",
|
76 |
+
[[front, scores[0], scores[1]] for front, scores in results.items()],
|
77 |
+
)
|
78 |
+
|
79 |
+
correct_btn.click(
|
80 |
+
mark_correct,
|
81 |
+
[selected_card, results],
|
82 |
+
[results, correct_field, results_table],
|
83 |
+
)
|
84 |
+
|
85 |
+
incorrect_btn.click(
|
86 |
+
mark_incorrect,
|
87 |
+
[selected_card, results],
|
88 |
+
[results, incorrect_field, results_table],
|
89 |
+
)
|
90 |
+
|
91 |
+
if __name__ == "__main__":
|
92 |
+
demo.launch()
|
demos/blocks_flipper/run.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
def flip_text(x):
|
5 |
+
return x[::-1]
|
6 |
+
|
7 |
+
def flip_image(x):
|
8 |
+
return np.fliplr(x)
|
9 |
+
|
10 |
+
with gr.Blocks() as demo:
|
11 |
+
gr.Markdown("Flip text or image files using this demo.")
|
12 |
+
with gr.Tabs():
|
13 |
+
with gr.TabItem("Flip Text"):
|
14 |
+
text_input = gr.Textbox()
|
15 |
+
text_output = gr.Textbox()
|
16 |
+
text_button = gr.Button("Flip")
|
17 |
+
with gr.TabItem("Flip Image"):
|
18 |
+
with gr.Row():
|
19 |
+
image_input = gr.Image()
|
20 |
+
image_output = gr.Image()
|
21 |
+
image_button = gr.Button("Flip")
|
22 |
+
|
23 |
+
text_button.click(flip_text, inputs=text_input, outputs=text_output)
|
24 |
+
image_button.click(flip_image, inputs=image_input, outputs=image_output)
|
25 |
+
|
26 |
+
if __name__ == "__main__":
|
27 |
+
demo.launch()
|
demos/blocks_flipper/screenshot.gif
ADDED
Git LFS Details
|
demos/blocks_form/run.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
with gr.Blocks() as demo:
|
4 |
+
error_box = gr.Textbox(label="Error", visible=False)
|
5 |
+
|
6 |
+
name_box = gr.Textbox(label="Name")
|
7 |
+
age_box = gr.Number(label="Age")
|
8 |
+
symptoms_box = gr.CheckboxGroup(["Cough", "Fever", "Runny Nose"])
|
9 |
+
submit_btn = gr.Button("Submit")
|
10 |
+
|
11 |
+
with gr.Column(visible=False) as output_col:
|
12 |
+
diagnosis_box = gr.Textbox(label="Diagnosis")
|
13 |
+
patient_summary_box = gr.Textbox(label="Patient Summary")
|
14 |
+
|
15 |
+
def submit(name, age, symptoms):
|
16 |
+
if len(name) == 0:
|
17 |
+
return {error_box: gr.update(value="Enter name", visible=True)}
|
18 |
+
if age < 0 or age > 200:
|
19 |
+
return {error_box: gr.update(value="Enter valid age", visible=True)}
|
20 |
+
return {
|
21 |
+
output_col: gr.update(visible=True),
|
22 |
+
diagnosis_box: "covid" if "Cough" in symptoms else "flu",
|
23 |
+
patient_summary_box: f"{name}, {age} y/o"
|
24 |
+
}
|
25 |
+
|
26 |
+
submit_btn.click(
|
27 |
+
submit,
|
28 |
+
[name_box, age_box, symptoms_box],
|
29 |
+
[error_box, diagnosis_box, patient_summary_box, output_col],
|
30 |
+
)
|
31 |
+
|
32 |
+
if __name__ == "__main__":
|
33 |
+
demo.launch()
|
demos/blocks_gpt/run.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
api = gr.Interface.load("huggingface/EleutherAI/gpt-j-6B")
|
4 |
+
|
5 |
+
def complete_with_gpt(text):
|
6 |
+
# Use the last 50 characters of the text as context
|
7 |
+
return text[:-50] + api(text[-50:])
|
8 |
+
|
9 |
+
with gr.Blocks() as demo:
|
10 |
+
textbox = gr.Textbox(placeholder="Type here and press enter...", lines=4)
|
11 |
+
btn = gr.Button("Generate")
|
12 |
+
|
13 |
+
btn.click(complete_with_gpt, textbox, textbox)
|
14 |
+
|
15 |
+
if __name__ == "__main__":
|
16 |
+
demo.launch()
|
demos/blocks_hello/run.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
def welcome(name):
|
4 |
+
return f"Welcome to Gradio, {name}!"
|
5 |
+
|
6 |
+
with gr.Blocks() as demo:
|
7 |
+
gr.Markdown(
|
8 |
+
"""
|
9 |
+
# Hello World!
|
10 |
+
Start typing below to see the output.
|
11 |
+
""")
|
12 |
+
inp = gr.Textbox(placeholder="What is your name?")
|
13 |
+
out = gr.Textbox()
|
14 |
+
inp.change(welcome, inp, out)
|
15 |
+
|
16 |
+
if __name__ == "__main__":
|
17 |
+
demo.launch()
|
demos/blocks_inputs/config.json
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"version": "3.0.6",
|
3 |
+
"mode": "blocks",
|
4 |
+
"dev_mode": true,
|
5 |
+
"components": [
|
6 |
+
{
|
7 |
+
"id": 1,
|
8 |
+
"type": "textbox",
|
9 |
+
"props": {
|
10 |
+
"lines": 5,
|
11 |
+
"max_lines": 20,
|
12 |
+
"value": "",
|
13 |
+
"label": "Input",
|
14 |
+
"show_label": true,
|
15 |
+
"name": "textbox",
|
16 |
+
"visible": true,
|
17 |
+
"style": {}
|
18 |
+
}
|
19 |
+
},
|
20 |
+
{
|
21 |
+
"id": 2,
|
22 |
+
"type": "textbox",
|
23 |
+
"props": {
|
24 |
+
"lines": 1,
|
25 |
+
"max_lines": 20,
|
26 |
+
"value": "",
|
27 |
+
"label": "Output-Interactive",
|
28 |
+
"show_label": true,
|
29 |
+
"name": "textbox",
|
30 |
+
"visible": true,
|
31 |
+
"style": {}
|
32 |
+
}
|
33 |
+
},
|
34 |
+
{
|
35 |
+
"id": 3,
|
36 |
+
"type": "textbox",
|
37 |
+
"props": {
|
38 |
+
"lines": 1,
|
39 |
+
"max_lines": 20,
|
40 |
+
"value": "Hello friends\nhello friends\n\nHello friends\n\n",
|
41 |
+
"label": "Output",
|
42 |
+
"show_label": true,
|
43 |
+
"interactive": false,
|
44 |
+
"name": "textbox",
|
45 |
+
"visible": true,
|
46 |
+
"style": {}
|
47 |
+
}
|
48 |
+
},
|
49 |
+
{
|
50 |
+
"id": 4,
|
51 |
+
"type": "button",
|
52 |
+
"props": {
|
53 |
+
"value": "Submit",
|
54 |
+
"variant": "secondary",
|
55 |
+
"name": "button",
|
56 |
+
"visible": true,
|
57 |
+
"style": {}
|
58 |
+
}
|
59 |
+
}
|
60 |
+
],
|
61 |
+
"theme": "default",
|
62 |
+
"css": null,
|
63 |
+
"enable_queue": false,
|
64 |
+
"layout": {
|
65 |
+
"id": 0,
|
66 |
+
"children": [
|
67 |
+
{
|
68 |
+
"id": 1
|
69 |
+
},
|
70 |
+
{
|
71 |
+
"id": 2
|
72 |
+
},
|
73 |
+
{
|
74 |
+
"id": 3
|
75 |
+
},
|
76 |
+
{
|
77 |
+
"id": 4
|
78 |
+
}
|
79 |
+
]
|
80 |
+
},
|
81 |
+
"dependencies": [
|
82 |
+
{
|
83 |
+
"targets": [
|
84 |
+
4
|
85 |
+
],
|
86 |
+
"trigger": "click",
|
87 |
+
"inputs": [
|
88 |
+
1
|
89 |
+
],
|
90 |
+
"outputs": [
|
91 |
+
2
|
92 |
+
],
|
93 |
+
"backend_fn": true,
|
94 |
+
"js": null,
|
95 |
+
"status_tracker": null,
|
96 |
+
"queue": null
|
97 |
+
}
|
98 |
+
]
|
99 |
+
}
|
demos/blocks_inputs/lion.jpg
ADDED
demos/blocks_inputs/run.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
|
4 |
+
def combine(a, b):
|
5 |
+
return a + " " + b
|
6 |
+
|
7 |
+
def mirror(x):
|
8 |
+
return x
|
9 |
+
|
10 |
+
with gr.Blocks() as demo:
|
11 |
+
|
12 |
+
txt = gr.Textbox(label="Input", lines=2)
|
13 |
+
txt_2 = gr.Textbox(label="Input 2")
|
14 |
+
txt_3 = gr.Textbox(value="", label="Output")
|
15 |
+
btn = gr.Button(value="Submit")
|
16 |
+
btn.click(combine, inputs=[txt, txt_2], outputs=[txt_3])
|
17 |
+
|
18 |
+
with gr.Row():
|
19 |
+
im = gr.Image()
|
20 |
+
im_2 = gr.Image()
|
21 |
+
|
22 |
+
btn = gr.Button(value="Mirror Image")
|
23 |
+
btn.click(mirror, inputs=[im], outputs=[im_2])
|
24 |
+
|
25 |
+
gr.Markdown("## Text Examples")
|
26 |
+
gr.Examples([["hi", "Adam"], ["hello", "Eve"]], [txt, txt_2], txt_3, combine, cache_examples=True)
|
27 |
+
gr.Markdown("## Image Examples")
|
28 |
+
gr.Examples(
|
29 |
+
examples=[os.path.join(os.path.dirname(__file__), "lion.jpg")],
|
30 |
+
inputs=im,
|
31 |
+
outputs=im_2,
|
32 |
+
fn=mirror,
|
33 |
+
cache_examples=True)
|
34 |
+
|
35 |
+
if __name__ == "__main__":
|
36 |
+
demo.launch()
|
demos/blocks_joined/files/cheetah1.jpg
ADDED
demos/blocks_joined/run.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from time import sleep
|
2 |
+
import gradio as gr
|
3 |
+
import os
|
4 |
+
|
5 |
+
cheetah = os.path.join(os.path.dirname(__file__), "files/cheetah1.jpg")
|
6 |
+
|
7 |
+
|
8 |
+
def img(text):
|
9 |
+
sleep(3)
|
10 |
+
return [
|
11 |
+
cheetah,
|
12 |
+
cheetah,
|
13 |
+
cheetah,
|
14 |
+
cheetah,
|
15 |
+
cheetah,
|
16 |
+
cheetah,
|
17 |
+
cheetah,
|
18 |
+
cheetah,
|
19 |
+
cheetah,
|
20 |
+
]
|
21 |
+
|
22 |
+
|
23 |
+
with gr.Blocks(css=".container { max-width: 800px; margin: auto; }") as demo:
|
24 |
+
gr.Markdown("<h1><center>DALL·E mini</center></h1>")
|
25 |
+
gr.Markdown(
|
26 |
+
"DALL·E mini is an AI model that generates images from any prompt you give!"
|
27 |
+
)
|
28 |
+
with gr.Group():
|
29 |
+
with gr.Box():
|
30 |
+
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
31 |
+
|
32 |
+
text = gr.Textbox(
|
33 |
+
label="Enter your prompt", show_label=False, max_lines=1
|
34 |
+
).style(
|
35 |
+
border=(True, False, True, True),
|
36 |
+
rounded=(True, False, False, True),
|
37 |
+
container=False,
|
38 |
+
)
|
39 |
+
btn = gr.Button("Run").style(
|
40 |
+
margin=False,
|
41 |
+
rounded=(False, True, True, False),
|
42 |
+
)
|
43 |
+
gallery = gr.Gallery(label="Generated images", show_label=False).style(
|
44 |
+
grid=(
|
45 |
+
1,
|
46 |
+
3,
|
47 |
+
),
|
48 |
+
height="auto",
|
49 |
+
)
|
50 |
+
btn.click(img, inputs=text, outputs=gallery)
|
51 |
+
|
52 |
+
|
53 |
+
if __name__ == "__main__":
|
54 |
+
demo.launch()
|
55 |
+
|
56 |
+
|
57 |
+
# margin = (TOP, RIGHT, BOTTOM, LEFT)
|
58 |
+
# rounded = (TOPLEFT, TOPRIGHT, BOTTOMRIGHT, BOTTOMLEFT)
|
demos/blocks_js_methods/run.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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("Foo bar.")
|
14 |
+
|
15 |
+
def sentence_maker(w1, w2, w3):
|
16 |
+
return f"{w1} {w2} {w3}"
|
17 |
+
|
18 |
+
output1 = gr.Textbox(label="output 1")
|
19 |
+
output2 = gr.Textbox(label="verb")
|
20 |
+
output3 = gr.Textbox(label="verb reversed")
|
21 |
+
|
22 |
+
btn.click(sentence_maker, [subject, verb, object], output1)
|
23 |
+
reverse_btn.click(None, [subject, verb, object], output2, _js="(s, v, o) => o + ' ' + v + ' ' + s")
|
24 |
+
verb.change(lambda x: x, verb, output3, _js="(x) => [...x].reverse().join('')")
|
25 |
+
foo_bar_btn.click(None, [], subject, _js="(x) => x + ' foo'")
|
26 |
+
|
27 |
+
if __name__ == "__main__":
|
28 |
+
demo.launch()
|
demos/blocks_kinematics/config.json
ADDED
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"version": "3.0.6",
|
3 |
+
"mode": "blocks",
|
4 |
+
"dev_mode": true,
|
5 |
+
"components": [
|
6 |
+
{
|
7 |
+
"id": 1,
|
8 |
+
"type": "markdown",
|
9 |
+
"props": {
|
10 |
+
"value": "<p>Let's do some kinematics! Choose the speed and angle to see the trajectory.</p>\n",
|
11 |
+
"name": "markdown",
|
12 |
+
"visible": true,
|
13 |
+
"style": {}
|
14 |
+
}
|
15 |
+
},
|
16 |
+
{
|
17 |
+
"id": 2,
|
18 |
+
"type": "row",
|
19 |
+
"props": {
|
20 |
+
"type": "row",
|
21 |
+
"visible": true,
|
22 |
+
"style": {}
|
23 |
+
}
|
24 |
+
},
|
25 |
+
{
|
26 |
+
"id": 3,
|
27 |
+
"type": "slider",
|
28 |
+
"props": {
|
29 |
+
"minimum": 1,
|
30 |
+
"maximum": 30,
|
31 |
+
"step": 0.1,
|
32 |
+
"value": 25,
|
33 |
+
"label": "Speed",
|
34 |
+
"show_label": true,
|
35 |
+
"name": "slider",
|
36 |
+
"visible": true,
|
37 |
+
"style": {}
|
38 |
+
}
|
39 |
+
},
|
40 |
+
{
|
41 |
+
"id": 4,
|
42 |
+
"type": "slider",
|
43 |
+
"props": {
|
44 |
+
"minimum": 0,
|
45 |
+
"maximum": 90,
|
46 |
+
"step": 0.1,
|
47 |
+
"value": 45,
|
48 |
+
"label": "Angle",
|
49 |
+
"show_label": true,
|
50 |
+
"name": "slider",
|
51 |
+
"visible": true,
|
52 |
+
"style": {}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
{
|
56 |
+
"id": 5,
|
57 |
+
"type": "plot",
|
58 |
+
"props": {
|
59 |
+
"show_label": true,
|
60 |
+
"name": "plot",
|
61 |
+
"visible": true,
|
62 |
+
"style": {}
|
63 |
+
}
|
64 |
+
},
|
65 |
+
{
|
66 |
+
"id": 6,
|
67 |
+
"type": "button",
|
68 |
+
"props": {
|
69 |
+
"value": "Run",
|
70 |
+
"variant": "secondary",
|
71 |
+
"name": "button",
|
72 |
+
"visible": true,
|
73 |
+
"style": {}
|
74 |
+
}
|
75 |
+
}
|
76 |
+
],
|
77 |
+
"theme": "default",
|
78 |
+
"css": null,
|
79 |
+
"enable_queue": false,
|
80 |
+
"layout": {
|
81 |
+
"id": 0,
|
82 |
+
"children": [
|
83 |
+
{
|
84 |
+
"id": 1
|
85 |
+
},
|
86 |
+
{
|
87 |
+
"id": 2,
|
88 |
+
"children": [
|
89 |
+
{
|
90 |
+
"id": 3
|
91 |
+
},
|
92 |
+
{
|
93 |
+
"id": 4
|
94 |
+
}
|
95 |
+
]
|
96 |
+
},
|
97 |
+
{
|
98 |
+
"id": 5
|
99 |
+
},
|
100 |
+
{
|
101 |
+
"id": 6
|
102 |
+
}
|
103 |
+
]
|
104 |
+
},
|
105 |
+
"dependencies": [
|
106 |
+
{
|
107 |
+
"targets": [
|
108 |
+
6
|
109 |
+
],
|
110 |
+
"trigger": "click",
|
111 |
+
"inputs": [
|
112 |
+
3,
|
113 |
+
4
|
114 |
+
],
|
115 |
+
"outputs": [
|
116 |
+
5
|
117 |
+
],
|
118 |
+
"backend_fn": true,
|
119 |
+
"js": null,
|
120 |
+
"status_tracker": null,
|
121 |
+
"queue": null
|
122 |
+
}
|
123 |
+
]
|
124 |
+
}
|
demos/blocks_kinematics/run.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import matplotlib
|
2 |
+
matplotlib.use('Agg')
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
|
9 |
+
def plot(v, a):
|
10 |
+
g = 9.81
|
11 |
+
theta = a / 180 * 3.14
|
12 |
+
tmax = ((2 * v) * np.sin(theta)) / g
|
13 |
+
timemat = tmax * np.linspace(0, 1, 40)[:, None]
|
14 |
+
|
15 |
+
x = (v * timemat) * np.cos(theta)
|
16 |
+
y = ((v * timemat) * np.sin(theta)) - ((0.5 * g) * (timemat**2))
|
17 |
+
|
18 |
+
fig = plt.figure()
|
19 |
+
plt.scatter(x=x, y=y, marker=".")
|
20 |
+
plt.xlim(0, 100)
|
21 |
+
plt.ylim(0, 60)
|
22 |
+
return fig
|
23 |
+
|
24 |
+
|
25 |
+
demo = gr.Blocks()
|
26 |
+
|
27 |
+
with demo:
|
28 |
+
gr.Markdown(
|
29 |
+
"Let's do some kinematics! Choose the speed and angle to see the trajectory."
|
30 |
+
)
|
31 |
+
|
32 |
+
with gr.Row():
|
33 |
+
speed = gr.Slider(1, 30, 25, label="Speed")
|
34 |
+
angle = gr.Slider(0, 90, 45, label="Angle")
|
35 |
+
output = gr.Plot()
|
36 |
+
btn = gr.Button(value="Run")
|
37 |
+
btn.click(plot, [speed, angle], output)
|
38 |
+
|
39 |
+
if __name__ == "__main__":
|
40 |
+
demo.launch()
|
demos/blocks_layout/run.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
|
4 |
+
demo = gr.Blocks()
|
5 |
+
|
6 |
+
with demo:
|
7 |
+
with gr.Row():
|
8 |
+
gr.Image(interactive=True)
|
9 |
+
gr.Image()
|
10 |
+
with gr.Row():
|
11 |
+
gr.Textbox(label="Text")
|
12 |
+
gr.Number(label="Count")
|
13 |
+
gr.Radio(choices=["One", "Two"])
|
14 |
+
with gr.Row():
|
15 |
+
with gr.Row():
|
16 |
+
with gr.Column():
|
17 |
+
gr.Textbox(label="Text")
|
18 |
+
gr.Number(label="Count")
|
19 |
+
gr.Radio(choices=["One", "Two"])
|
20 |
+
gr.Image()
|
21 |
+
with gr.Column():
|
22 |
+
gr.Image(interactive=True)
|
23 |
+
gr.Image()
|
24 |
+
gr.Image()
|
25 |
+
gr.Textbox(label="Text")
|
26 |
+
gr.Number(label="Count")
|
27 |
+
gr.Radio(choices=["One", "Two"])
|
28 |
+
|
29 |
+
|
30 |
+
if __name__ == "__main__":
|
31 |
+
demo.launch()
|
demos/blocks_mask/lion.jpg
ADDED
demos/blocks_mask/run.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
|
4 |
+
def fn(mask):
|
5 |
+
return [mask["image"], mask["mask"]]
|
6 |
+
|
7 |
+
|
8 |
+
demo = gr.Blocks()
|
9 |
+
|
10 |
+
with demo:
|
11 |
+
with gr.Row():
|
12 |
+
with gr.Column():
|
13 |
+
img = gr.Image(
|
14 |
+
tool="sketch", source="upload", label="Mask", value=os.path.join(os.path.dirname(__file__), "lion.jpg")
|
15 |
+
)
|
16 |
+
with gr.Row():
|
17 |
+
btn = gr.Button("Run")
|
18 |
+
with gr.Column():
|
19 |
+
img2 = gr.Image()
|
20 |
+
img3 = gr.Image()
|
21 |
+
|
22 |
+
btn.click(fn=fn, inputs=img, outputs=[img2, img3])
|
23 |
+
|
24 |
+
|
25 |
+
if __name__ == "__main__":
|
26 |
+
demo.launch()
|
demos/blocks_multiple_event_triggers/run.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
pd.options.plotting.backend = "plotly"
|
8 |
+
|
9 |
+
|
10 |
+
def get_plot(lib, time):
|
11 |
+
data = pypistats.overall(lib, total=True, format="pandas")
|
12 |
+
data = data.groupby("category").get_group("with_mirrors").sort_values("date")
|
13 |
+
start_date = date.today() - relativedelta(months=int(time.split(" ")[0]))
|
14 |
+
data = data[(data['date'] > str(start_date))]
|
15 |
+
chart = data.plot(x="date", y="downloads")
|
16 |
+
return chart
|
17 |
+
|
18 |
+
|
19 |
+
with gr.Blocks() as demo:
|
20 |
+
gr.Markdown(
|
21 |
+
"""
|
22 |
+
## Pypi Download Stats 📈
|
23 |
+
See live download stats for all of Hugging Face's open-source libraries 🤗
|
24 |
+
""")
|
25 |
+
with gr.Row():
|
26 |
+
lib = gr.Dropdown(["transformers", "datasets", "huggingface-hub", "gradio", "accelerate"], label="Library")
|
27 |
+
time = gr.Dropdown(["3 months", "6 months", "9 months", "12 months"], label="Downloads over the last...")
|
28 |
+
|
29 |
+
plt = gr.Plot()
|
30 |
+
# You can add multiple event triggers in 2 lines like this
|
31 |
+
for event in [lib.change, time.change]:
|
32 |
+
event(get_plot, [lib, time], [plt])
|
33 |
+
|
34 |
+
if __name__ == "__main__":
|
35 |
+
demo.launch()
|
demos/blocks_neural_instrument_coding/flute.wav
ADDED
Binary file (223 kB). View file
|
|
demos/blocks_neural_instrument_coding/new-sax-1.mp3
ADDED
Binary file (95.1 kB). View file
|
|
demos/blocks_neural_instrument_coding/new-sax-1.wav
ADDED
Binary file (154 kB). View file
|
|
demos/blocks_neural_instrument_coding/new-sax.wav
ADDED
Binary file (384 kB). View file
|
|
demos/blocks_neural_instrument_coding/run.py
ADDED
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# A Blocks implementation of https://erlj.notion.site/Neural-Instrument-Cloning-from-very-few-samples-2cf41d8b630842ee8c7eb55036a1bfd6
|
2 |
+
|
3 |
+
import datetime
|
4 |
+
import os
|
5 |
+
import random
|
6 |
+
|
7 |
+
import gradio as gr
|
8 |
+
from gradio.components import Markdown as m
|
9 |
+
|
10 |
+
|
11 |
+
def get_time():
|
12 |
+
now = datetime.datetime.now()
|
13 |
+
return now.strftime("%m/%d/%Y, %H:%M:%S")
|
14 |
+
|
15 |
+
|
16 |
+
def generate_recording():
|
17 |
+
return random.choice(["new-sax-1.mp3", "new-sax-1.wav"])
|
18 |
+
|
19 |
+
|
20 |
+
def reconstruct(audio):
|
21 |
+
return random.choice(["new-sax-1.mp3", "new-sax-1.wav"])
|
22 |
+
|
23 |
+
|
24 |
+
io1 = gr.Interface(
|
25 |
+
lambda x, y, z: os.path.join(os.path.dirname(__file__),"sax.wav"),
|
26 |
+
[
|
27 |
+
gr.Slider(label="pitch"),
|
28 |
+
gr.Slider(label="loudness"),
|
29 |
+
gr.Audio(label="base audio file (optional)"),
|
30 |
+
],
|
31 |
+
gr.Audio(),
|
32 |
+
)
|
33 |
+
|
34 |
+
io2 = gr.Interface(
|
35 |
+
lambda x, y, z: os.path.join(os.path.dirname(__file__),"flute.wav"),
|
36 |
+
[
|
37 |
+
gr.Slider(label="pitch"),
|
38 |
+
gr.Slider(label="loudness"),
|
39 |
+
gr.Audio(label="base audio file (optional)"),
|
40 |
+
],
|
41 |
+
gr.Audio(),
|
42 |
+
)
|
43 |
+
|
44 |
+
io3 = gr.Interface(
|
45 |
+
lambda x, y, z: os.path.join(os.path.dirname(__file__),"trombone.wav"),
|
46 |
+
[
|
47 |
+
gr.Slider(label="pitch"),
|
48 |
+
gr.Slider(label="loudness"),
|
49 |
+
gr.Audio(label="base audio file (optional)"),
|
50 |
+
],
|
51 |
+
gr.Audio(),
|
52 |
+
)
|
53 |
+
|
54 |
+
io4 = gr.Interface(
|
55 |
+
lambda x, y, z: os.path.join(os.path.dirname(__file__),"sax2.wav"),
|
56 |
+
[
|
57 |
+
gr.Slider(label="pitch"),
|
58 |
+
gr.Slider(label="loudness"),
|
59 |
+
gr.Audio(label="base audio file (optional)"),
|
60 |
+
],
|
61 |
+
gr.Audio(),
|
62 |
+
)
|
63 |
+
|
64 |
+
demo = gr.Blocks(title="Neural Instrument Cloning")
|
65 |
+
|
66 |
+
with demo.clear():
|
67 |
+
m(
|
68 |
+
"""
|
69 |
+
## Neural Instrument Cloning from Very Few Samples
|
70 |
+
<center><img src="https://media.istockphoto.com/photos/brass-trombone-picture-id490455809?k=20&m=490455809&s=612x612&w=0&h=l9KJvH_25z0QTLggHrcH_MsR4gPLH7uXwDPUAZ_C5zk=" width="400px"></center>"""
|
71 |
+
)
|
72 |
+
m(
|
73 |
+
"""
|
74 |
+
This Blocks implementation is an adaptation [a report written](https://erlj.notion.site/Neural-Instrument-Cloning-from-very-few-samples-2cf41d8b630842ee8c7eb55036a1bfd6) by Nicolas Jonason and Bob L.T. Sturm.
|
75 |
+
|
76 |
+
I've implemented it in Blocks to show off some cool features, such as embedding live ML demos. More on that ahead...
|
77 |
+
|
78 |
+
### What does this machine learning model do?
|
79 |
+
It combines techniques from neural voice cloning with musical instrument synthesis. This makes it possible to produce neural instrument synthesisers from just seconds of target instrument audio.
|
80 |
+
|
81 |
+
### Audio Examples
|
82 |
+
Here are some **real** 16 second saxophone recordings:
|
83 |
+
"""
|
84 |
+
)
|
85 |
+
gr.Audio(os.path.join(os.path.dirname(__file__),"sax.wav"), label="Here is a real 16 second saxophone recording:")
|
86 |
+
gr.Audio(os.path.join(os.path.dirname(__file__),"sax.wav"))
|
87 |
+
|
88 |
+
m(
|
89 |
+
"""\n
|
90 |
+
Here is a **generated** saxophone recordings:"""
|
91 |
+
)
|
92 |
+
a = gr.Audio(os.path.join(os.path.dirname(__file__),"new-sax.wav"))
|
93 |
+
|
94 |
+
gr.Button("Generate a new saxophone recording")
|
95 |
+
|
96 |
+
m(
|
97 |
+
"""
|
98 |
+
### Inputs to the model
|
99 |
+
The inputs to the model are:
|
100 |
+
* pitch
|
101 |
+
* loudness
|
102 |
+
* base audio file
|
103 |
+
"""
|
104 |
+
)
|
105 |
+
|
106 |
+
m(
|
107 |
+
"""
|
108 |
+
Try the model live!
|
109 |
+
"""
|
110 |
+
)
|
111 |
+
|
112 |
+
gr.TabbedInterface(
|
113 |
+
[io1, io2, io3, io4], ["Saxophone", "Flute", "Trombone", "Another Saxophone"]
|
114 |
+
)
|
115 |
+
|
116 |
+
m(
|
117 |
+
"""
|
118 |
+
### Using the model for cloning
|
119 |
+
You can also use this model a different way, to simply clone the audio file and reconstruct it
|
120 |
+
using machine learning. Here, we'll show a demo of that below:
|
121 |
+
"""
|
122 |
+
)
|
123 |
+
|
124 |
+
a2 = gr.Audio()
|
125 |
+
a2.change(reconstruct, a2, a2)
|
126 |
+
|
127 |
+
m(
|
128 |
+
"""
|
129 |
+
Thanks for reading this! As you may have realized, all of the "models" in this demo are fake. They are just designed to show you what is possible using Blocks 🤗.
|
130 |
+
|
131 |
+
For details of the model, read the [original report here](https://erlj.notion.site/Neural-Instrument-Cloning-from-very-few-samples-2cf41d8b630842ee8c7eb55036a1bfd6).
|
132 |
+
|
133 |
+
*Details for nerds*: this report was "launched" on:
|
134 |
+
"""
|
135 |
+
)
|
136 |
+
|
137 |
+
t = gr.Textbox(label="timestamp")
|
138 |
+
|
139 |
+
demo.load(get_time, [], t)
|
140 |
+
|
141 |
+
|
142 |
+
if __name__ == "__main__":
|
143 |
+
demo.launch()
|
demos/blocks_neural_instrument_coding/sax.wav
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:12ee32c66257e1c98ed0f2f7b708a1eab638ec09f4c69dda3ec1d78047a7be4d
|
3 |
+
size 1536044
|
demos/blocks_neural_instrument_coding/sax2.wav
ADDED
Binary file (384 kB). View file
|
|
demos/blocks_neural_instrument_coding/trombone.wav
ADDED
Binary file (384 kB). View file
|
|
demos/blocks_outputs/config.json
ADDED
@@ -0,0 +1,325 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"mode": "blocks",
|
3 |
+
"components": [
|
4 |
+
{
|
5 |
+
"id": 1,
|
6 |
+
"type": "column",
|
7 |
+
"props": {
|
8 |
+
"type": "column",
|
9 |
+
"variant": "default",
|
10 |
+
"css": {},
|
11 |
+
"default_value": true
|
12 |
+
}
|
13 |
+
},
|
14 |
+
{
|
15 |
+
"id": 2,
|
16 |
+
"type": "textbox",
|
17 |
+
"props": {
|
18 |
+
"lines": 1,
|
19 |
+
"max_lines": 20,
|
20 |
+
"default_value": "",
|
21 |
+
"label": "Small Textbox",
|
22 |
+
"show_label": false,
|
23 |
+
"name": "textbox",
|
24 |
+
"css": {}
|
25 |
+
}
|
26 |
+
},
|
27 |
+
{
|
28 |
+
"id": 3,
|
29 |
+
"type": "textbox",
|
30 |
+
"props": {
|
31 |
+
"lines": 5,
|
32 |
+
"max_lines": 20,
|
33 |
+
"default_value": "",
|
34 |
+
"label": "Large Textbox",
|
35 |
+
"show_label": false,
|
36 |
+
"name": "textbox",
|
37 |
+
"css": {}
|
38 |
+
}
|
39 |
+
},
|
40 |
+
{
|
41 |
+
"id": 4,
|
42 |
+
"type": "number",
|
43 |
+
"props": {
|
44 |
+
"label": "Number",
|
45 |
+
"show_label": false,
|
46 |
+
"name": "number",
|
47 |
+
"css": {}
|
48 |
+
}
|
49 |
+
},
|
50 |
+
{
|
51 |
+
"id": 5,
|
52 |
+
"type": "checkbox",
|
53 |
+
"props": {
|
54 |
+
"default_value": false,
|
55 |
+
"label": "Checkbox",
|
56 |
+
"show_label": false,
|
57 |
+
"name": "checkbox",
|
58 |
+
"css": {}
|
59 |
+
}
|
60 |
+
},
|
61 |
+
{
|
62 |
+
"id": 6,
|
63 |
+
"type": "checkboxgroup",
|
64 |
+
"props": {
|
65 |
+
"choices": [
|
66 |
+
"One",
|
67 |
+
"Two",
|
68 |
+
"Three"
|
69 |
+
],
|
70 |
+
"default_value": [],
|
71 |
+
"label": "Checkbox Group",
|
72 |
+
"show_label": false,
|
73 |
+
"name": "checkboxgroup",
|
74 |
+
"css": {}
|
75 |
+
}
|
76 |
+
},
|
77 |
+
{
|
78 |
+
"id": 7,
|
79 |
+
"type": "radio",
|
80 |
+
"props": {
|
81 |
+
"choices": [
|
82 |
+
"One",
|
83 |
+
"Two",
|
84 |
+
"Three"
|
85 |
+
],
|
86 |
+
"default_value": "One",
|
87 |
+
"label": "Radio",
|
88 |
+
"show_label": false,
|
89 |
+
"name": "radio",
|
90 |
+
"css": {}
|
91 |
+
}
|
92 |
+
},
|
93 |
+
{
|
94 |
+
"id": 8,
|
95 |
+
"type": "dropdown",
|
96 |
+
"props": {
|
97 |
+
"choices": [
|
98 |
+
"One",
|
99 |
+
"Two",
|
100 |
+
"Three"
|
101 |
+
],
|
102 |
+
"default_value": "One",
|
103 |
+
"label": "Dropdown",
|
104 |
+
"show_label": false,
|
105 |
+
"name": "dropdown",
|
106 |
+
"css": {}
|
107 |
+
}
|
108 |
+
},
|
109 |
+
{
|
110 |
+
"id": 9,
|
111 |
+
"type": "slider",
|
112 |
+
"props": {
|
113 |
+
"minimum": 0,
|
114 |
+
"maximum": 100,
|
115 |
+
"step": 1,
|
116 |
+
"default_value": 0,
|
117 |
+
"label": "Slider",
|
118 |
+
"show_label": false,
|
119 |
+
"name": "slider",
|
120 |
+
"css": {}
|
121 |
+
}
|
122 |
+
},
|
123 |
+
{
|
124 |
+
"id": 10,
|
125 |
+
"type": "audio",
|
126 |
+
"props": {
|
127 |
+
"source": "upload",
|
128 |
+
"show_label": false,
|
129 |
+
"name": "audio",
|
130 |
+
"css": {}
|
131 |
+
}
|
132 |
+
},
|
133 |
+
{
|
134 |
+
"id": 11,
|
135 |
+
"type": "file",
|
136 |
+
"props": {
|
137 |
+
"file_count": "single",
|
138 |
+
"show_label": false,
|
139 |
+
"name": "file",
|
140 |
+
"css": {}
|
141 |
+
}
|
142 |
+
},
|
143 |
+
{
|
144 |
+
"id": 12,
|
145 |
+
"type": "video",
|
146 |
+
"props": {
|
147 |
+
"source": "upload",
|
148 |
+
"show_label": false,
|
149 |
+
"name": "video",
|
150 |
+
"css": {}
|
151 |
+
}
|
152 |
+
},
|
153 |
+
{
|
154 |
+
"id": 13,
|
155 |
+
"type": "image",
|
156 |
+
"props": {
|
157 |
+
"image_mode": "RGB",
|
158 |
+
"source": "upload",
|
159 |
+
"tool": "editor",
|
160 |
+
"show_label": false,
|
161 |
+
"name": "image",
|
162 |
+
"css": {}
|
163 |
+
}
|
164 |
+
},
|
165 |
+
{
|
166 |
+
"id": 14,
|
167 |
+
"type": "timeseries",
|
168 |
+
"props": {
|
169 |
+
"show_label": false,
|
170 |
+
"name": "timeseries",
|
171 |
+
"css": {}
|
172 |
+
}
|
173 |
+
},
|
174 |
+
{
|
175 |
+
"id": 15,
|
176 |
+
"type": "dataframe",
|
177 |
+
"props": {
|
178 |
+
"datatype": "str",
|
179 |
+
"row_count": 1,
|
180 |
+
"col_count": 3,
|
181 |
+
"default_value": [
|
182 |
+
[
|
183 |
+
"",
|
184 |
+
"",
|
185 |
+
""
|
186 |
+
],
|
187 |
+
[
|
188 |
+
"",
|
189 |
+
"",
|
190 |
+
""
|
191 |
+
],
|
192 |
+
[
|
193 |
+
"",
|
194 |
+
"",
|
195 |
+
""
|
196 |
+
]
|
197 |
+
],
|
198 |
+
"max_rows": 20,
|
199 |
+
"overflow_row_behaviour": "paginate",
|
200 |
+
"show_label": false,
|
201 |
+
"name": "dataframe",
|
202 |
+
"css": {}
|
203 |
+
}
|
204 |
+
},
|
205 |
+
{
|
206 |
+
"id": 16,
|
207 |
+
"type": "html",
|
208 |
+
"props": {
|
209 |
+
"default_value": "",
|
210 |
+
"show_label": false,
|
211 |
+
"name": "html",
|
212 |
+
"css": {}
|
213 |
+
}
|
214 |
+
},
|
215 |
+
{
|
216 |
+
"id": 17,
|
217 |
+
"type": "json",
|
218 |
+
"props": {
|
219 |
+
"default_value": "\"\"",
|
220 |
+
"show_label": false,
|
221 |
+
"name": "json",
|
222 |
+
"css": {}
|
223 |
+
}
|
224 |
+
},
|
225 |
+
{
|
226 |
+
"id": 18,
|
227 |
+
"type": "markdown",
|
228 |
+
"props": {
|
229 |
+
"default_value": "",
|
230 |
+
"name": "markdown",
|
231 |
+
"css": {}
|
232 |
+
}
|
233 |
+
},
|
234 |
+
{
|
235 |
+
"id": 19,
|
236 |
+
"type": "label",
|
237 |
+
"props": {
|
238 |
+
"show_label": false,
|
239 |
+
"name": "label",
|
240 |
+
"css": {}
|
241 |
+
}
|
242 |
+
},
|
243 |
+
{
|
244 |
+
"id": 20,
|
245 |
+
"type": "highlightedtext",
|
246 |
+
"props": {
|
247 |
+
"show_legend": false,
|
248 |
+
"default_value": "",
|
249 |
+
"show_label": false,
|
250 |
+
"name": "highlightedtext",
|
251 |
+
"css": {}
|
252 |
+
}
|
253 |
+
}
|
254 |
+
],
|
255 |
+
"theme": "default",
|
256 |
+
"enable_queue": false,
|
257 |
+
"layout": {
|
258 |
+
"id": 0,
|
259 |
+
"children": [
|
260 |
+
{
|
261 |
+
"id": 1,
|
262 |
+
"children": [
|
263 |
+
{
|
264 |
+
"id": 2
|
265 |
+
},
|
266 |
+
{
|
267 |
+
"id": 3
|
268 |
+
},
|
269 |
+
{
|
270 |
+
"id": 4
|
271 |
+
},
|
272 |
+
{
|
273 |
+
"id": 5
|
274 |
+
},
|
275 |
+
{
|
276 |
+
"id": 6
|
277 |
+
},
|
278 |
+
{
|
279 |
+
"id": 7
|
280 |
+
},
|
281 |
+
{
|
282 |
+
"id": 8
|
283 |
+
},
|
284 |
+
{
|
285 |
+
"id": 9
|
286 |
+
},
|
287 |
+
{
|
288 |
+
"id": 10
|
289 |
+
},
|
290 |
+
{
|
291 |
+
"id": 11
|
292 |
+
},
|
293 |
+
{
|
294 |
+
"id": 12
|
295 |
+
},
|
296 |
+
{
|
297 |
+
"id": 13
|
298 |
+
},
|
299 |
+
{
|
300 |
+
"id": 14
|
301 |
+
},
|
302 |
+
{
|
303 |
+
"id": 15
|
304 |
+
},
|
305 |
+
{
|
306 |
+
"id": 16
|
307 |
+
},
|
308 |
+
{
|
309 |
+
"id": 17
|
310 |
+
},
|
311 |
+
{
|
312 |
+
"id": 18
|
313 |
+
},
|
314 |
+
{
|
315 |
+
"id": 19
|
316 |
+
},
|
317 |
+
{
|
318 |
+
"id": 20
|
319 |
+
}
|
320 |
+
]
|
321 |
+
}
|
322 |
+
]
|
323 |
+
},
|
324 |
+
"dependencies": []
|
325 |
+
}
|
demos/blocks_outputs/run.py
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
|
4 |
+
def make_markdown():
|
5 |
+
return [
|
6 |
+
[
|
7 |
+
"# hello again",
|
8 |
+
"Hello my name is frank, I am liking the small turtle you have there. It would be a shame if it went missing.",
|
9 |
+
'<img src="https://images.unsplash.com/photo-1574613362884-f79513a5128c?fit=crop&w=500&q=80"/>',
|
10 |
+
],
|
11 |
+
[
|
12 |
+
"## hello again again",
|
13 |
+
"Hello my name is frank, I am liking the small turtle you have there. It would be a shame if it went missing.",
|
14 |
+
'<img src="https://images.unsplash.com/photo-1574613362884-f79513a5128c?fit=crop&w=500&q=80"/>',
|
15 |
+
],
|
16 |
+
[
|
17 |
+
"### hello thrice",
|
18 |
+
"Hello my name is frank, I am liking the small turtle you have there. It would be a shame if it went missing.",
|
19 |
+
'<img src="https://images.unsplash.com/photo-1574613362884-f79513a5128c?fit=crop&w=500&q=80"/>',
|
20 |
+
],
|
21 |
+
]
|
22 |
+
|
23 |
+
|
24 |
+
with gr.Blocks() as demo:
|
25 |
+
with gr.Column():
|
26 |
+
txt = gr.Textbox(label="Small Textbox", lines=1, show_label=False)
|
27 |
+
txt = gr.Textbox(label="Large Textbox", lines=5, show_label=False)
|
28 |
+
num = gr.Number(label="Number", show_label=False)
|
29 |
+
check = gr.Checkbox(label="Checkbox", show_label=False)
|
30 |
+
check_g = gr.CheckboxGroup(
|
31 |
+
label="Checkbox Group", choices=["One", "Two", "Three"], show_label=False
|
32 |
+
)
|
33 |
+
radio = gr.Radio(
|
34 |
+
label="Radio", choices=["One", "Two", "Three"], show_label=False
|
35 |
+
)
|
36 |
+
drop = gr.Dropdown(
|
37 |
+
label="Dropdown", choices=["One", "Two", "Three"], show_label=False
|
38 |
+
)
|
39 |
+
slider = gr.Slider(label="Slider", show_label=False)
|
40 |
+
audio = gr.Audio(show_label=False)
|
41 |
+
file = gr.File(show_label=False)
|
42 |
+
video = gr.Video(show_label=False)
|
43 |
+
image = gr.Image(show_label=False)
|
44 |
+
ts = gr.Timeseries(show_label=False)
|
45 |
+
df = gr.Dataframe(show_label=False)
|
46 |
+
html = gr.HTML(show_label=False)
|
47 |
+
json = gr.JSON(show_label=False)
|
48 |
+
md = gr.Markdown(show_label=False)
|
49 |
+
label = gr.Label(show_label=False)
|
50 |
+
highlight = gr.HighlightedText(show_label=False)
|
51 |
+
gr.Dataframe(interactive=True, col_count=(3, "fixed"), label="Dataframe")
|
52 |
+
gr.Dataframe(interactive=True, col_count=4, label="Dataframe")
|
53 |
+
gr.Dataframe(
|
54 |
+
interactive=True, headers=["One", "Two", "Three", "Four"], label="Dataframe"
|
55 |
+
)
|
56 |
+
gr.Dataframe(
|
57 |
+
interactive=True,
|
58 |
+
headers=["One", "Two", "Three", "Four"],
|
59 |
+
col_count=(4, "fixed"),
|
60 |
+
row_count=(7, "fixed"),
|
61 |
+
value=[[0, 0, 0, 0]],
|
62 |
+
label="Dataframe",
|
63 |
+
)
|
64 |
+
gr.Dataframe(
|
65 |
+
interactive=True, headers=["One", "Two", "Three", "Four"], col_count=4
|
66 |
+
)
|
67 |
+
df = gr.DataFrame(
|
68 |
+
[
|
69 |
+
[
|
70 |
+
"# hello",
|
71 |
+
"Hello my name is frank, I am liking the small turtle you have there. It would be a shame if it went missing.",
|
72 |
+
'<img src="https://images.unsplash.com/photo-1574613362884-f79513a5128c?fit=crop&w=500&q=80"/>',
|
73 |
+
],
|
74 |
+
[
|
75 |
+
"## hello",
|
76 |
+
"Hello my name is frank, I am liking the small turtle you have there. It would be a shame if it went missing.",
|
77 |
+
'<img src="https://images.unsplash.com/photo-1574613362884-f79513a5128c?fit=crop&w=500&q=80"/>',
|
78 |
+
],
|
79 |
+
[
|
80 |
+
"### hello",
|
81 |
+
"Hello my name is frank, I am liking the small turtle you have there. It would be a shame if it went missing.",
|
82 |
+
'<img src="https://images.unsplash.com/photo-1574613362884-f79513a5128c?fit=crop&w=500&q=80"/>',
|
83 |
+
],
|
84 |
+
],
|
85 |
+
headers=["One", "Two", "Three"],
|
86 |
+
wrap=True,
|
87 |
+
datatype=["markdown", "markdown", "html"],
|
88 |
+
interactive=True,
|
89 |
+
)
|
90 |
+
btn = gr.Button("Run")
|
91 |
+
btn.click(fn=make_markdown, inputs=None, outputs=df)
|
92 |
+
|
93 |
+
|
94 |
+
if __name__ == "__main__":
|
95 |
+
demo.launch()
|
demos/blocks_page_load/config.json
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"mode": "blocks",
|
3 |
+
"components": [
|
4 |
+
{
|
5 |
+
"id": 1,
|
6 |
+
"type": "textbox",
|
7 |
+
"props": {
|
8 |
+
"lines": 1,
|
9 |
+
"max_lines": 20,
|
10 |
+
"default_value": "Frank",
|
11 |
+
"label": "Name",
|
12 |
+
"show_label": true,
|
13 |
+
"name": "textbox",
|
14 |
+
"css": {}
|
15 |
+
}
|
16 |
+
},
|
17 |
+
{
|
18 |
+
"id": 2,
|
19 |
+
"type": "textbox",
|
20 |
+
"props": {
|
21 |
+
"lines": 1,
|
22 |
+
"max_lines": 20,
|
23 |
+
"default_value": "",
|
24 |
+
"label": "Output",
|
25 |
+
"show_label": true,
|
26 |
+
"name": "textbox",
|
27 |
+
"css": {}
|
28 |
+
}
|
29 |
+
}
|
30 |
+
],
|
31 |
+
"theme": "default",
|
32 |
+
"enable_queue": false,
|
33 |
+
"layout": {
|
34 |
+
"id": 0,
|
35 |
+
"children": [
|
36 |
+
{
|
37 |
+
"id": 1
|
38 |
+
},
|
39 |
+
{
|
40 |
+
"id": 2
|
41 |
+
}
|
42 |
+
]
|
43 |
+
},
|
44 |
+
"dependencies": [
|
45 |
+
{
|
46 |
+
"targets": [],
|
47 |
+
"trigger": "load",
|
48 |
+
"inputs": [
|
49 |
+
1
|
50 |
+
],
|
51 |
+
"outputs": [
|
52 |
+
2
|
53 |
+
],
|
54 |
+
"status_tracker": null,
|
55 |
+
"queue": null
|
56 |
+
}
|
57 |
+
]
|
58 |
+
}
|
demos/blocks_page_load/run.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
|
4 |
+
def print_message(n):
|
5 |
+
return "Welcome! This page has loaded for " + n
|
6 |
+
|
7 |
+
|
8 |
+
with gr.Blocks() as demo:
|
9 |
+
t = gr.Textbox("Frank", label="Name")
|
10 |
+
t2 = gr.Textbox(label="Output")
|
11 |
+
demo.load(print_message, t, t2)
|
12 |
+
|
13 |
+
|
14 |
+
if __name__ == "__main__":
|
15 |
+
demo.launch()
|
demos/blocks_plug/run.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
|
4 |
+
def change_tab():
|
5 |
+
return gr.Tabs.update(selected=2)
|
6 |
+
|
7 |
+
|
8 |
+
identity_demo, input_demo, output_demo = gr.Blocks(), gr.Blocks(), gr.Blocks()
|
9 |
+
|
10 |
+
with identity_demo:
|
11 |
+
gr.Interface(lambda x: x, "text", "text")
|
12 |
+
|
13 |
+
with input_demo:
|
14 |
+
t = gr.Textbox(label="Enter your text here")
|
15 |
+
with gr.Row():
|
16 |
+
btn = gr.Button("Submit")
|
17 |
+
clr = gr.Button("Clear")
|
18 |
+
clr.click(lambda x: "", t, t)
|
19 |
+
|
20 |
+
with output_demo:
|
21 |
+
gr.Textbox("This is a static output")
|
22 |
+
|
23 |
+
with gr.Blocks() as demo:
|
24 |
+
gr.Markdown("Three demos in one!")
|
25 |
+
with gr.Tabs(selected=1) as tabs:
|
26 |
+
with gr.TabItem("Text Identity", id=0):
|
27 |
+
identity_demo.render()
|
28 |
+
with gr.TabItem("Text Input", id=1):
|
29 |
+
input_demo.render()
|
30 |
+
with gr.TabItem("Text Static", id=2):
|
31 |
+
output_demo.render()
|
32 |
+
btn = gr.Button("Change tab")
|
33 |
+
btn.click(inputs=None, outputs=tabs, fn=change_tab)
|
34 |
+
|
35 |
+
if __name__ == "__main__":
|
36 |
+
demo.launch()
|
demos/blocks_random_slider/run.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
|
5 |
+
def func(slider_1, slider_2):
|
6 |
+
return slider_1 * 5 + slider_2
|
7 |
+
|
8 |
+
|
9 |
+
with gr.Blocks() as demo:
|
10 |
+
slider = gr.Slider(minimum=-10.2, maximum=15, label="Random Slider (Static)", randomize=True)
|
11 |
+
slider_1 = gr.Slider(minimum=100, maximum=200, label="Random Slider (Input 1)", randomize=True)
|
12 |
+
slider_2 = gr.Slider(minimum=10, maximum=23.2, label="Random Slider (Input 2)", randomize=True)
|
13 |
+
slider_3 = gr.Slider(value=3, label="Non random slider")
|
14 |
+
btn = gr.Button("Run")
|
15 |
+
btn.click(func, inputs=[slider_1, slider_2], outputs=gr.Number())
|
16 |
+
|
17 |
+
if __name__ == "__main__":
|
18 |
+
demo.launch()
|
demos/blocks_scroll/run.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
|
4 |
+
demo = gr.Blocks()
|
5 |
+
|
6 |
+
with demo:
|
7 |
+
inp = gr.Textbox(placeholder="Enter text.")
|
8 |
+
scroll_btn = gr.Button("Scroll")
|
9 |
+
no_scroll_btn = gr.Button("No Scroll")
|
10 |
+
big_block = gr.HTML("""
|
11 |
+
<div style='height: 800px; width: 100px; background-color: pink;'></div>
|
12 |
+
""")
|
13 |
+
out = gr.Textbox()
|
14 |
+
|
15 |
+
scroll_btn.click(lambda x: x,
|
16 |
+
inputs=inp,
|
17 |
+
outputs=out,
|
18 |
+
scroll_to_output=True)
|
19 |
+
no_scroll_btn.click(lambda x: x,
|
20 |
+
inputs=inp,
|
21 |
+
outputs=out)
|
22 |
+
|
23 |
+
if __name__ == "__main__":
|
24 |
+
demo.launch()
|
demos/blocks_simple_squares/config.json
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"version": "3.0.6",
|
3 |
+
"mode": "blocks",
|
4 |
+
"dev_mode": true,
|
5 |
+
"components": [
|
6 |
+
{
|
7 |
+
"id": 1,
|
8 |
+
"type": "variable",
|
9 |
+
"props": {
|
10 |
+
"value": 0,
|
11 |
+
"show_label": true,
|
12 |
+
"name": "variable",
|
13 |
+
"visible": true,
|
14 |
+
"style": {}
|
15 |
+
}
|
16 |
+
},
|
17 |
+
{
|
18 |
+
"id": 2,
|
19 |
+
"type": "number",
|
20 |
+
"props": {
|
21 |
+
"value": 0.0,
|
22 |
+
"show_label": true,
|
23 |
+
"name": "number",
|
24 |
+
"visible": true,
|
25 |
+
"style": {
|
26 |
+
"text_color": "blue",
|
27 |
+
"container_bg_color": "yellow"
|
28 |
+
}
|
29 |
+
}
|
30 |
+
},
|
31 |
+
{
|
32 |
+
"id": 3,
|
33 |
+
"type": "button",
|
34 |
+
"props": {
|
35 |
+
"value": "Next Square",
|
36 |
+
"variant": "secondary",
|
37 |
+
"name": "button",
|
38 |
+
"visible": true,
|
39 |
+
"elem_id": "btn",
|
40 |
+
"style": {
|
41 |
+
"rounded": false,
|
42 |
+
"bg_color": "purple"
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
{
|
47 |
+
"id": 4,
|
48 |
+
"type": "variable",
|
49 |
+
"props": {
|
50 |
+
"value": {
|
51 |
+
"a": "a"
|
52 |
+
},
|
53 |
+
"show_label": true,
|
54 |
+
"name": "variable",
|
55 |
+
"visible": true,
|
56 |
+
"style": {}
|
57 |
+
}
|
58 |
+
},
|
59 |
+
{
|
60 |
+
"id": 5,
|
61 |
+
"type": "json",
|
62 |
+
"props": {
|
63 |
+
"show_label": true,
|
64 |
+
"name": "json",
|
65 |
+
"visible": true,
|
66 |
+
"style": {}
|
67 |
+
}
|
68 |
+
}
|
69 |
+
],
|
70 |
+
"theme": "default",
|
71 |
+
"css": "#btn {color: red}",
|
72 |
+
"enable_queue": false,
|
73 |
+
"layout": {
|
74 |
+
"id": 0,
|
75 |
+
"children": [
|
76 |
+
{
|
77 |
+
"id": 1
|
78 |
+
},
|
79 |
+
{
|
80 |
+
"id": 2
|
81 |
+
},
|
82 |
+
{
|
83 |
+
"id": 3
|
84 |
+
},
|
85 |
+
{
|
86 |
+
"id": 4
|
87 |
+
},
|
88 |
+
{
|
89 |
+
"id": 5
|
90 |
+
}
|
91 |
+
]
|
92 |
+
},
|
93 |
+
"dependencies": [
|
94 |
+
{
|
95 |
+
"targets": [
|
96 |
+
3
|
97 |
+
],
|
98 |
+
"trigger": "click",
|
99 |
+
"inputs": [
|
100 |
+
1,
|
101 |
+
4
|
102 |
+
],
|
103 |
+
"outputs": [
|
104 |
+
1,
|
105 |
+
2,
|
106 |
+
4,
|
107 |
+
5
|
108 |
+
],
|
109 |
+
"backend_fn": true,
|
110 |
+
"js": null,
|
111 |
+
"status_tracker": null,
|
112 |
+
"queue": null
|
113 |
+
}
|
114 |
+
]
|
115 |
+
}
|
demos/blocks_simple_squares/run.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
demo = gr.Blocks(css="#btn {color: red}")
|
4 |
+
|
5 |
+
with demo:
|
6 |
+
default_json = {"a": "a"}
|
7 |
+
|
8 |
+
num = gr.Variable(value=0)
|
9 |
+
squared = gr.Number(value=0)
|
10 |
+
btn = gr.Button("Next Square", elem_id="btn").style(rounded=False)
|
11 |
+
|
12 |
+
stats = gr.Variable(value=default_json)
|
13 |
+
table = gr.JSON()
|
14 |
+
|
15 |
+
def increase(var, stats_history):
|
16 |
+
var += 1
|
17 |
+
stats_history[str(var)] = var**2
|
18 |
+
return var, var**2, stats_history, stats_history
|
19 |
+
|
20 |
+
btn.click(increase, [num, stats], [num, squared, stats, table])
|
21 |
+
|
22 |
+
if __name__ == "__main__":
|
23 |
+
demo.launch()
|
demos/blocks_static_textbox/run.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
demo = gr.Blocks()
|
4 |
+
|
5 |
+
with demo:
|
6 |
+
gr.Textbox("Hello")
|
7 |
+
gr.Number(5)
|
8 |
+
|
9 |
+
if __name__ == "__main__":
|
10 |
+
demo.launch()
|
demos/blocks_style/run.py
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
with gr.Blocks(title="Styling Examples") as demo:
|
4 |
+
with gr.Column():
|
5 |
+
txt = gr.Textbox(label="Small Textbox", lines=1).style(
|
6 |
+
rounded=False,
|
7 |
+
border=False,
|
8 |
+
container=False,
|
9 |
+
)
|
10 |
+
|
11 |
+
num = gr.Number(label="Number", show_label=False).style(
|
12 |
+
rounded=False,
|
13 |
+
border=False,
|
14 |
+
container=False,
|
15 |
+
)
|
16 |
+
slider = gr.Slider(label="Slider", show_label=False).style(
|
17 |
+
container=False,
|
18 |
+
)
|
19 |
+
check = gr.Checkbox(label="Checkbox", show_label=False).style(
|
20 |
+
rounded=False,
|
21 |
+
border=False,
|
22 |
+
container=False,
|
23 |
+
)
|
24 |
+
check_g = gr.CheckboxGroup(
|
25 |
+
label="Checkbox Group", choices=["One", "Two", "Three"], show_label=False
|
26 |
+
).style(rounded=False, container=False, item_container=False)
|
27 |
+
radio = gr.Radio(
|
28 |
+
label="Radio", choices=["One", "Two", "Three"], show_label=False
|
29 |
+
).style(
|
30 |
+
item_container=False,
|
31 |
+
container=False,
|
32 |
+
)
|
33 |
+
drop = gr.Dropdown(
|
34 |
+
label="Dropdown", choices=["One", "Two", "Three"], show_label=False
|
35 |
+
).style(
|
36 |
+
rounded=False,
|
37 |
+
border=False,
|
38 |
+
container=False,
|
39 |
+
)
|
40 |
+
image = gr.Image(show_label=False).style(
|
41 |
+
rounded=False,
|
42 |
+
)
|
43 |
+
video = gr.Video(show_label=False).style(
|
44 |
+
rounded=False,
|
45 |
+
)
|
46 |
+
audio = gr.Audio(show_label=False).style(
|
47 |
+
rounded=False,
|
48 |
+
)
|
49 |
+
file = gr.File(show_label=False).style(
|
50 |
+
rounded=False,
|
51 |
+
)
|
52 |
+
df = gr.Dataframe(show_label=False).style(
|
53 |
+
rounded=False,
|
54 |
+
)
|
55 |
+
|
56 |
+
ts = gr.Timeseries(show_label=False).style(
|
57 |
+
rounded=False,
|
58 |
+
)
|
59 |
+
label = gr.Label().style(
|
60 |
+
container=False,
|
61 |
+
)
|
62 |
+
highlight = gr.HighlightedText(
|
63 |
+
"+ hello. - goodbye", show_label=False, color_map={"+": "green", "-": "red"}
|
64 |
+
).style(rounded=False, container=False)
|
65 |
+
json = gr.JSON().style(container=False)
|
66 |
+
html = gr.HTML(show_label=False).style()
|
67 |
+
gallery = gr.Gallery().style(
|
68 |
+
rounded=False,
|
69 |
+
grid=(3, 3, 1),
|
70 |
+
height="auto",
|
71 |
+
container=False,
|
72 |
+
)
|
73 |
+
chat = gr.Chatbot("hi", color_map=("pink", "blue")).style(
|
74 |
+
rounded=False,
|
75 |
+
)
|
76 |
+
|
77 |
+
model = gr.Model3D().style(
|
78 |
+
rounded=False,
|
79 |
+
)
|
80 |
+
|
81 |
+
gr.Plot().style()
|
82 |
+
md = gr.Markdown(show_label=False).style()
|
83 |
+
|
84 |
+
highlight = gr.HighlightedText().style(
|
85 |
+
rounded=False,
|
86 |
+
)
|
87 |
+
|
88 |
+
btn = gr.Button("Run").style(
|
89 |
+
rounded=False,
|
90 |
+
full_width=True,
|
91 |
+
border=False,
|
92 |
+
)
|
93 |
+
|
94 |
+
# Not currently public
|
95 |
+
# TODO: Uncomment at next release
|
96 |
+
# gr.Dataset().style(
|
97 |
+
# rounded=False,
|
98 |
+
# margin=False,
|
99 |
+
# border=False,
|
100 |
+
# )
|
101 |
+
|
102 |
+
|
103 |
+
if __name__ == "__main__":
|
104 |
+
demo.launch()
|
demos/blocks_textbox_max_lines/run.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
|
4 |
+
def greet(name: str, repeat: float):
|
5 |
+
return "Hello " + name * int(repeat) + "!!"
|
6 |
+
|
7 |
+
|
8 |
+
demo = gr.Interface(
|
9 |
+
fn=greet, inputs=[gr.Textbox(lines=2, max_lines=4), gr.Number()], outputs="textarea"
|
10 |
+
)
|
11 |
+
|
12 |
+
if __name__ == "__main__":
|
13 |
+
demo.launch()
|
demos/blocks_update/run.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.update(
|
28 |
+
choices=species_map[species], value=species_map[species][1]
|
29 |
+
), gr.update(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.update(maximum=100)
|
36 |
+
else:
|
37 |
+
return gr.update(maximum=20)
|
38 |
+
|
39 |
+
animal.change(filter_weight, animal, weight)
|
40 |
+
weight.change(lambda w: gr.update(lines=int(w / 10) + 1), weight, details)
|
41 |
+
|
42 |
+
generate_btn.click(lambda x: x, details, output)
|
43 |
+
|
44 |
+
|
45 |
+
if __name__ == "__main__":
|
46 |
+
demo.launch()
|
demos/blocks_webcam/run.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
|
6 |
+
def snap(image):
|
7 |
+
return np.flipud(image)
|
8 |
+
|
9 |
+
|
10 |
+
demo = gr.Interface(snap, "webcam", "image")
|
11 |
+
|
12 |
+
if __name__ == "__main__":
|
13 |
+
demo.launch()
|
demos/blocks_xray/config.json
ADDED
@@ -0,0 +1,339 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"version": "3.1.1\n",
|
3 |
+
"mode": "blocks",
|
4 |
+
"dev_mode": true,
|
5 |
+
"components": [
|
6 |
+
{
|
7 |
+
"id": 1,
|
8 |
+
"type": "markdown",
|
9 |
+
"props": {
|
10 |
+
"value": "<h1>Detect Disease From Scan</h1>\n<p>With this model you can lorem ipsum</p>\n<ul>\n<li>ipsum 1</li>\n<li>ipsum 2</li>\n</ul>\n",
|
11 |
+
"name": "markdown",
|
12 |
+
"visible": true,
|
13 |
+
"style": {}
|
14 |
+
}
|
15 |
+
},
|
16 |
+
{
|
17 |
+
"id": 2,
|
18 |
+
"type": "checkboxgroup",
|
19 |
+
"props": {
|
20 |
+
"choices": [
|
21 |
+
"Covid",
|
22 |
+
"Malaria",
|
23 |
+
"Lung Cancer"
|
24 |
+
],
|
25 |
+
"value": [],
|
26 |
+
"label": "Disease to Scan For",
|
27 |
+
"show_label": true,
|
28 |
+
"name": "checkboxgroup",
|
29 |
+
"visible": true,
|
30 |
+
"style": {}
|
31 |
+
}
|
32 |
+
},
|
33 |
+
{
|
34 |
+
"id": 3,
|
35 |
+
"type": "tabs",
|
36 |
+
"props": {
|
37 |
+
"visible": true,
|
38 |
+
"style": {}
|
39 |
+
}
|
40 |
+
},
|
41 |
+
{
|
42 |
+
"id": 4,
|
43 |
+
"type": "tabitem",
|
44 |
+
"props": {
|
45 |
+
"label": "X-ray",
|
46 |
+
"visible": true,
|
47 |
+
"style": {}
|
48 |
+
}
|
49 |
+
},
|
50 |
+
{
|
51 |
+
"id": 5,
|
52 |
+
"type": "row",
|
53 |
+
"props": {
|
54 |
+
"type": "row",
|
55 |
+
"visible": true,
|
56 |
+
"style": {}
|
57 |
+
}
|
58 |
+
},
|
59 |
+
{
|
60 |
+
"id": 6,
|
61 |
+
"type": "image",
|
62 |
+
"props": {
|
63 |
+
"image_mode": "RGB",
|
64 |
+
"source": "upload",
|
65 |
+
"tool": "editor",
|
66 |
+
"streaming": false,
|
67 |
+
"mirror_webcam": true,
|
68 |
+
"show_label": true,
|
69 |
+
"name": "image",
|
70 |
+
"visible": true,
|
71 |
+
"style": {}
|
72 |
+
}
|
73 |
+
},
|
74 |
+
{
|
75 |
+
"id": 7,
|
76 |
+
"type": "json",
|
77 |
+
"props": {
|
78 |
+
"show_label": true,
|
79 |
+
"name": "json",
|
80 |
+
"visible": true,
|
81 |
+
"style": {}
|
82 |
+
}
|
83 |
+
},
|
84 |
+
{
|
85 |
+
"id": 8,
|
86 |
+
"type": "button",
|
87 |
+
"props": {
|
88 |
+
"value": "Run",
|
89 |
+
"variant": "secondary",
|
90 |
+
"name": "button",
|
91 |
+
"visible": true,
|
92 |
+
"style": {}
|
93 |
+
}
|
94 |
+
},
|
95 |
+
{
|
96 |
+
"id": 9,
|
97 |
+
"type": "statustracker",
|
98 |
+
"props": {
|
99 |
+
"cover_container": true,
|
100 |
+
"name": "statustracker",
|
101 |
+
"visible": true,
|
102 |
+
"style": {}
|
103 |
+
}
|
104 |
+
},
|
105 |
+
{
|
106 |
+
"id": 10,
|
107 |
+
"type": "tabitem",
|
108 |
+
"props": {
|
109 |
+
"label": "CT Scan",
|
110 |
+
"visible": true,
|
111 |
+
"style": {}
|
112 |
+
}
|
113 |
+
},
|
114 |
+
{
|
115 |
+
"id": 11,
|
116 |
+
"type": "row",
|
117 |
+
"props": {
|
118 |
+
"type": "row",
|
119 |
+
"visible": true,
|
120 |
+
"style": {}
|
121 |
+
}
|
122 |
+
},
|
123 |
+
{
|
124 |
+
"id": 12,
|
125 |
+
"type": "image",
|
126 |
+
"props": {
|
127 |
+
"image_mode": "RGB",
|
128 |
+
"source": "upload",
|
129 |
+
"tool": "editor",
|
130 |
+
"streaming": false,
|
131 |
+
"mirror_webcam": true,
|
132 |
+
"show_label": true,
|
133 |
+
"name": "image",
|
134 |
+
"visible": true,
|
135 |
+
"style": {}
|
136 |
+
}
|
137 |
+
},
|
138 |
+
{
|
139 |
+
"id": 13,
|
140 |
+
"type": "json",
|
141 |
+
"props": {
|
142 |
+
"show_label": true,
|
143 |
+
"name": "json",
|
144 |
+
"visible": true,
|
145 |
+
"style": {}
|
146 |
+
}
|
147 |
+
},
|
148 |
+
{
|
149 |
+
"id": 14,
|
150 |
+
"type": "button",
|
151 |
+
"props": {
|
152 |
+
"value": "Run",
|
153 |
+
"variant": "secondary",
|
154 |
+
"name": "button",
|
155 |
+
"visible": true,
|
156 |
+
"style": {}
|
157 |
+
}
|
158 |
+
},
|
159 |
+
{
|
160 |
+
"id": 15,
|
161 |
+
"type": "statustracker",
|
162 |
+
"props": {
|
163 |
+
"cover_container": true,
|
164 |
+
"name": "statustracker",
|
165 |
+
"visible": true,
|
166 |
+
"style": {}
|
167 |
+
}
|
168 |
+
},
|
169 |
+
{
|
170 |
+
"id": 16,
|
171 |
+
"type": "button",
|
172 |
+
"props": {
|
173 |
+
"value": "Upload Results",
|
174 |
+
"variant": "secondary",
|
175 |
+
"name": "button",
|
176 |
+
"visible": true,
|
177 |
+
"style": {}
|
178 |
+
}
|
179 |
+
},
|
180 |
+
{
|
181 |
+
"id": 17,
|
182 |
+
"type": "statustracker",
|
183 |
+
"props": {
|
184 |
+
"cover_container": false,
|
185 |
+
"name": "statustracker",
|
186 |
+
"visible": true,
|
187 |
+
"style": {}
|
188 |
+
}
|
189 |
+
}
|
190 |
+
],
|
191 |
+
"theme": "default",
|
192 |
+
"css": null,
|
193 |
+
"title": "Gradio",
|
194 |
+
"enable_queue": false,
|
195 |
+
"layout": {
|
196 |
+
"id": 0,
|
197 |
+
"children": [
|
198 |
+
{
|
199 |
+
"id": 1
|
200 |
+
},
|
201 |
+
{
|
202 |
+
"id": 2
|
203 |
+
},
|
204 |
+
{
|
205 |
+
"id": 3,
|
206 |
+
"children": [
|
207 |
+
{
|
208 |
+
"id": 4,
|
209 |
+
"children": [
|
210 |
+
{
|
211 |
+
"id": 5,
|
212 |
+
"children": [
|
213 |
+
{
|
214 |
+
"id": 6
|
215 |
+
},
|
216 |
+
{
|
217 |
+
"id": 7
|
218 |
+
}
|
219 |
+
]
|
220 |
+
},
|
221 |
+
{
|
222 |
+
"id": 8
|
223 |
+
},
|
224 |
+
{
|
225 |
+
"id": 9
|
226 |
+
}
|
227 |
+
]
|
228 |
+
},
|
229 |
+
{
|
230 |
+
"id": 10,
|
231 |
+
"children": [
|
232 |
+
{
|
233 |
+
"id": 11,
|
234 |
+
"children": [
|
235 |
+
{
|
236 |
+
"id": 12
|
237 |
+
},
|
238 |
+
{
|
239 |
+
"id": 13
|
240 |
+
}
|
241 |
+
]
|
242 |
+
},
|
243 |
+
{
|
244 |
+
"id": 14
|
245 |
+
},
|
246 |
+
{
|
247 |
+
"id": 15
|
248 |
+
}
|
249 |
+
]
|
250 |
+
}
|
251 |
+
]
|
252 |
+
},
|
253 |
+
{
|
254 |
+
"id": 16
|
255 |
+
},
|
256 |
+
{
|
257 |
+
"id": 17
|
258 |
+
}
|
259 |
+
]
|
260 |
+
},
|
261 |
+
"dependencies": [
|
262 |
+
{
|
263 |
+
"targets": [
|
264 |
+
8
|
265 |
+
],
|
266 |
+
"trigger": "click",
|
267 |
+
"inputs": [
|
268 |
+
2,
|
269 |
+
6
|
270 |
+
],
|
271 |
+
"outputs": [
|
272 |
+
7
|
273 |
+
],
|
274 |
+
"backend_fn": true,
|
275 |
+
"js": null,
|
276 |
+
"status_tracker": 9,
|
277 |
+
"queue": null,
|
278 |
+
"api_name": "xray_model",
|
279 |
+
"scroll_to_output": false,
|
280 |
+
"show_progress": true,
|
281 |
+
"documentation": [
|
282 |
+
[
|
283 |
+
null,
|
284 |
+
null
|
285 |
+
],
|
286 |
+
[
|
287 |
+
null
|
288 |
+
]
|
289 |
+
]
|
290 |
+
},
|
291 |
+
{
|
292 |
+
"targets": [
|
293 |
+
14
|
294 |
+
],
|
295 |
+
"trigger": "click",
|
296 |
+
"inputs": [
|
297 |
+
2,
|
298 |
+
12
|
299 |
+
],
|
300 |
+
"outputs": [
|
301 |
+
13
|
302 |
+
],
|
303 |
+
"backend_fn": true,
|
304 |
+
"js": null,
|
305 |
+
"status_tracker": 15,
|
306 |
+
"queue": null,
|
307 |
+
"api_name": "ct_model",
|
308 |
+
"scroll_to_output": false,
|
309 |
+
"show_progress": true,
|
310 |
+
"documentation": [
|
311 |
+
[
|
312 |
+
null,
|
313 |
+
null
|
314 |
+
],
|
315 |
+
[
|
316 |
+
null
|
317 |
+
]
|
318 |
+
]
|
319 |
+
},
|
320 |
+
{
|
321 |
+
"targets": [
|
322 |
+
16
|
323 |
+
],
|
324 |
+
"trigger": "click",
|
325 |
+
"inputs": [
|
326 |
+
13,
|
327 |
+
7
|
328 |
+
],
|
329 |
+
"outputs": [],
|
330 |
+
"backend_fn": true,
|
331 |
+
"js": null,
|
332 |
+
"status_tracker": 17,
|
333 |
+
"queue": null,
|
334 |
+
"api_name": null,
|
335 |
+
"scroll_to_output": false,
|
336 |
+
"show_progress": true
|
337 |
+
}
|
338 |
+
]
|
339 |
+
}
|
demos/blocks_xray/run.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
import time
|
4 |
+
|
5 |
+
|
6 |
+
def xray_model(diseases, img):
|
7 |
+
time.sleep(4)
|
8 |
+
return [{disease: random.random() for disease in diseases}]
|
9 |
+
|
10 |
+
|
11 |
+
def ct_model(diseases, img):
|
12 |
+
time.sleep(3)
|
13 |
+
return [{disease: 0.1 for disease in diseases}]
|
14 |
+
|
15 |
+
|
16 |
+
with gr.Blocks() as demo:
|
17 |
+
gr.Markdown(
|
18 |
+
"""
|
19 |
+
# Detect Disease From Scan
|
20 |
+
With this model you can lorem ipsum
|
21 |
+
- ipsum 1
|
22 |
+
- ipsum 2
|
23 |
+
"""
|
24 |
+
)
|
25 |
+
disease = gr.CheckboxGroup(
|
26 |
+
choices=["Covid", "Malaria", "Lung Cancer"], label="Disease to Scan For"
|
27 |
+
)
|
28 |
+
|
29 |
+
with gr.Tabs():
|
30 |
+
with gr.TabItem("X-ray") as x_tab:
|
31 |
+
with gr.Row():
|
32 |
+
xray_scan = gr.Image()
|
33 |
+
xray_results = gr.JSON()
|
34 |
+
xray_run = gr.Button("Run")
|
35 |
+
xray_progress = gr.StatusTracker(cover_container=True)
|
36 |
+
xray_run.click(
|
37 |
+
xray_model,
|
38 |
+
inputs=[disease, xray_scan],
|
39 |
+
outputs=xray_results,
|
40 |
+
status_tracker=xray_progress,
|
41 |
+
api_name="xray_model"
|
42 |
+
)
|
43 |
+
|
44 |
+
with gr.TabItem("CT Scan"):
|
45 |
+
with gr.Row():
|
46 |
+
ct_scan = gr.Image()
|
47 |
+
ct_results = gr.JSON()
|
48 |
+
ct_run = gr.Button("Run")
|
49 |
+
ct_progress = gr.StatusTracker(cover_container=True)
|
50 |
+
ct_run.click(
|
51 |
+
ct_model,
|
52 |
+
inputs=[disease, ct_scan],
|
53 |
+
outputs=ct_results,
|
54 |
+
status_tracker=ct_progress,
|
55 |
+
api_name="ct_model"
|
56 |
+
)
|
57 |
+
|
58 |
+
upload_btn = gr.Button("Upload Results")
|
59 |
+
upload_btn.click(
|
60 |
+
lambda ct, xr: time.sleep(5),
|
61 |
+
inputs=[ct_results, xray_results],
|
62 |
+
outputs=[],
|
63 |
+
status_tracker=gr.StatusTracker(),
|
64 |
+
)
|
65 |
+
|
66 |
+
if __name__ == "__main__":
|
67 |
+
demo.launch()
|
demos/calculator/examples/log.csv
ADDED
File without changes
|
demos/calculator/run.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
return num1 / num2
|
12 |
+
|
13 |
+
demo = gr.Interface(
|
14 |
+
calculator,
|
15 |
+
[
|
16 |
+
"number",
|
17 |
+
gr.Radio(["add", "subtract", "multiply", "divide"]),
|
18 |
+
"number"
|
19 |
+
],
|
20 |
+
"number",
|
21 |
+
examples=[
|
22 |
+
[5, "add", 3],
|
23 |
+
[4, "divide", 2],
|
24 |
+
[-4, "multiply", 2.5],
|
25 |
+
[0, "subtract", 1.2],
|
26 |
+
],
|
27 |
+
title="Toy Calculator",
|
28 |
+
description="Here's a sample toy calculator. Enjoy!",
|
29 |
+
)
|
30 |
+
if __name__ == "__main__":
|
31 |
+
demo.launch()
|
demos/calculator/screenshot.gif
ADDED
Git LFS Details
|