freddyaboulton HF staff commited on
Commit
06b48bf
1 Parent(s): e0e341b

Upload with huggingface_hub

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +8 -0
  2. app.py +38 -0
  3. demos/blocks_component_shortcut/__pycache__/run.cpython-310.pyc +0 -0
  4. demos/blocks_component_shortcut/run.py +31 -0
  5. demos/blocks_essay/__pycache__/run.cpython-310.pyc +0 -0
  6. demos/blocks_essay/__pycache__/run.cpython-39.pyc +0 -0
  7. demos/blocks_essay/run.py +22 -0
  8. demos/blocks_essay_update/__pycache__/run.cpython-310.pyc +0 -0
  9. demos/blocks_essay_update/run.py +19 -0
  10. demos/blocks_flashcards/__pycache__/run.cpython-310.pyc +0 -0
  11. demos/blocks_flashcards/run.py +92 -0
  12. demos/blocks_flipper/__pycache__/run.cpython-310.pyc +0 -0
  13. demos/blocks_flipper/run.py +27 -0
  14. demos/blocks_flipper/screenshot.gif +3 -0
  15. demos/blocks_form/__pycache__/run.cpython-310.pyc +0 -0
  16. demos/blocks_form/__pycache__/run.cpython-39.pyc +0 -0
  17. demos/blocks_form/run.py +33 -0
  18. demos/blocks_gpt/__pycache__/run.cpython-310.pyc +0 -0
  19. demos/blocks_gpt/run.py +16 -0
  20. demos/blocks_hello/__pycache__/run.cpython-310.pyc +0 -0
  21. demos/blocks_hello/run.py +17 -0
  22. demos/blocks_inputs/__init__.py +0 -0
  23. demos/blocks_inputs/__pycache__/run.cpython-310.pyc +0 -0
  24. demos/blocks_inputs/__pycache__/run.cpython-39.pyc +0 -0
  25. demos/blocks_inputs/config.json +99 -0
  26. demos/blocks_inputs/gradio_cached_examples/10/log.csv +3 -0
  27. demos/blocks_inputs/gradio_cached_examples/12/component 0/0.png +0 -0
  28. demos/blocks_inputs/gradio_cached_examples/12/log.csv +2 -0
  29. demos/blocks_inputs/gradio_cached_examples/18/log.csv +3 -0
  30. demos/blocks_inputs/gradio_cached_examples/18/output 0/0.png +0 -0
  31. demos/blocks_inputs/gradio_cached_examples/18/output 0/1.png +0 -0
  32. demos/blocks_inputs/lion.jpg +0 -0
  33. demos/blocks_inputs/run.py +36 -0
  34. demos/blocks_joined/__pycache__/run.cpython-310.pyc +0 -0
  35. demos/blocks_joined/files/cheetah1.jpg +0 -0
  36. demos/blocks_joined/run.py +58 -0
  37. demos/blocks_js_methods/__pycache__/run.cpython-310.pyc +0 -0
  38. demos/blocks_js_methods/run.py +28 -0
  39. demos/blocks_kinematics/__pycache__/run.cpython-310.pyc +0 -0
  40. demos/blocks_kinematics/config.json +124 -0
  41. demos/blocks_kinematics/run.py +40 -0
  42. demos/blocks_layout/__pycache__/run.cpython-310.pyc +0 -0
  43. demos/blocks_layout/run.py +31 -0
  44. demos/blocks_mask/__pycache__/run.cpython-310.pyc +0 -0
  45. demos/blocks_mask/lion.jpg +0 -0
  46. demos/blocks_mask/run.py +26 -0
  47. demos/blocks_multiple_event_triggers/__pycache__/run.cpython-310.pyc +0 -0
  48. demos/blocks_multiple_event_triggers/run.py +35 -0
  49. demos/blocks_neural_instrument_coding/__pycache__/run.cpython-310.pyc +0 -0
  50. demos/blocks_neural_instrument_coding/__pycache__/run.cpython-39.pyc +0 -0
.gitattributes CHANGED
@@ -29,3 +29,11 @@ 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
+ gradio-3.1.4-py3-none-any.whl filter=lfs diff=lfs merge=lfs -text
33
+ demos/blocks_neural_instrument_coding/sax.wav filter=lfs diff=lfs merge=lfs -text
34
+ demos/calculator/screenshot.gif filter=lfs diff=lfs merge=lfs -text
35
+ demos/blocks_flipper/screenshot.gif filter=lfs diff=lfs merge=lfs -text
36
+ demos/hello_world_2/screenshot.gif filter=lfs diff=lfs merge=lfs -text
37
+ demos/image_mod/screenshot.png filter=lfs diff=lfs merge=lfs -text
38
+ demos/sepia_filter/screenshot.gif filter=lfs diff=lfs merge=lfs -text
39
+ demos/kitchen_sink/files/world.mp4 filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import importlib
2
+ import gradio as gr
3
+ import os
4
+ import sys
5
+ import copy
6
+ import pathlib
7
+
8
+ demo_dir = pathlib.Path(__file__).parent / "demos"
9
+
10
+
11
+ all_demos = []
12
+ for p in os.listdir("./demos"):
13
+ full_dir = os.path.join(demo_dir, p)
14
+ is_dir = os.path.isdir(full_dir)
15
+ no_requirements = not os.path.exists(os.path.join(full_dir, "requirements.txt"))
16
+ has_app = os.path.exists(os.path.join(full_dir, "run.py"))
17
+ if is_dir and no_requirements and has_app:
18
+ all_demos.append(p)
19
+
20
+ to_exclude = ["blocks_demos", "rows_and_columns", "image_classifier_interface_load", "generate_english_german",
21
+ "all_demos"]
22
+ all_demos = [d for d in all_demos if d not in to_exclude]
23
+
24
+ demo_module = None
25
+ with gr.Blocks() as mega_demo:
26
+ with gr.Tabs():
27
+ for demo_name in all_demos:
28
+ with gr.TabItem(demo_name):
29
+ old_path = copy.deepcopy(sys.path)
30
+ sys.path = [os.path.join(demo_dir, demo_name)] + sys.path
31
+ if demo_module is None:
32
+ demo_module = importlib.import_module(f"run")
33
+ else:
34
+ demo_module = importlib.reload(demo_module)
35
+ demo_module.demo
36
+ sys.path = old_path
37
+
38
+ mega_demo.launch()
demos/blocks_component_shortcut/__pycache__/run.cpython-310.pyc ADDED
Binary file (626 Bytes). View file
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/__pycache__/run.cpython-310.pyc ADDED
Binary file (741 Bytes). View file
demos/blocks_essay/__pycache__/run.cpython-39.pyc ADDED
Binary file (735 Bytes). View file
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/__pycache__/run.cpython-310.pyc ADDED
Binary file (757 Bytes). View file
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/__pycache__/run.cpython-310.pyc ADDED
Binary file (3.09 kB). View file
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/__pycache__/run.cpython-310.pyc ADDED
Binary file (1.07 kB). View file
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

  • SHA256: 21b814857d694e576b3e6db4cabe069f56e7386f7a1fabc6be81431c7176d700
  • Pointer size: 132 Bytes
  • Size of remote file: 1.11 MB
demos/blocks_form/__pycache__/run.cpython-310.pyc ADDED
Binary file (1.1 kB). View file
demos/blocks_form/__pycache__/run.cpython-39.pyc ADDED
Binary file (1.09 kB). View file
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/__pycache__/run.cpython-310.pyc ADDED
Binary file (642 Bytes). View file
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/__pycache__/run.cpython-310.pyc ADDED
Binary file (613 Bytes). View file
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/__init__.py ADDED
File without changes
demos/blocks_inputs/__pycache__/run.cpython-310.pyc ADDED
Binary file (1.17 kB). View file
demos/blocks_inputs/__pycache__/run.cpython-39.pyc ADDED
Binary file (1.16 kB). View file
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/gradio_cached_examples/10/log.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ 'Output','flag','username','timestamp'
2
+ 'hi Adam','','','2022-08-12 13:13:29.721471'
3
+ 'hello Eve','','','2022-08-12 13:13:29.722825'
demos/blocks_inputs/gradio_cached_examples/12/component 0/0.png ADDED
demos/blocks_inputs/gradio_cached_examples/12/log.csv ADDED
@@ -0,0 +1,2 @@
 
 
1
+ 'component 0','flag','username','timestamp'
2
+ 'component 0/0.png','','','2022-08-12 13:13:29.765027'
demos/blocks_inputs/gradio_cached_examples/18/log.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ 'output 0','output 1','flag','username','timestamp'
2
+ 'output 0/0.png','Hello','','','2022-08-12 13:32:08.226474'
3
+ 'output 0/1.png','Hi','','','2022-08-12 13:32:08.229111'
demos/blocks_inputs/gradio_cached_examples/18/output 0/0.png ADDED
demos/blocks_inputs/gradio_cached_examples/18/output 0/1.png ADDED
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/__pycache__/run.cpython-310.pyc ADDED
Binary file (1.38 kB). View file
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/__pycache__/run.cpython-310.pyc ADDED
Binary file (1.14 kB). View file
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/__pycache__/run.cpython-310.pyc ADDED
Binary file (1.22 kB). View file
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/__pycache__/run.cpython-310.pyc ADDED
Binary file (864 Bytes). View file
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/__pycache__/run.cpython-310.pyc ADDED
Binary file (815 Bytes). View file
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/__pycache__/run.cpython-310.pyc ADDED
Binary file (1.41 kB). View file
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/__pycache__/run.cpython-310.pyc ADDED
Binary file (3.97 kB). View file
demos/blocks_neural_instrument_coding/__pycache__/run.cpython-39.pyc ADDED
Binary file (4.04 kB). View file