Rooni commited on
Commit
43537c4
·
1 Parent(s): 33bd531

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +140 -21
app.py CHANGED
@@ -1,30 +1,149 @@
 
 
1
  import gradio as gr
2
 
3
- with gr.Blocks(theme='YTheme/PastelDark') as demo:
4
- with gr.Row():
5
- gr.Markdown("# Предпросмотр темы: `YTheme/PastelDark`"
6
- " Чтобы использовать эту тему, установите `theme='YTheme/PastelDark'` в `gr.Blocks()` или `gr.Interface()`."
7
- " Вы можете добавить `@` и выражение семантической версии, например, @>=1.0.0,<2.0.0, чтобы закрепить за собой данную версию"
8
- " темы.")
9
- with gr.Row():
10
- with gr.Column():
11
- gr.Markdown("### Пример Markdown")
12
- gr.Textbox(label="Текстовое поле")
13
- with gr.Column():
14
- gr.Image(value="https://via.placeholder.com/150", label="Пример изображения")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  with gr.Row():
16
- gr.Button("Кнопка")
 
 
 
17
  with gr.Row():
18
- gr.Checkbox(label="Чекбокс")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  with gr.Row():
20
- with gr.Column():
21
- gr.Radio(choices=["Опция 1", "Опция 2"], label="Радио кнопки")
22
- with gr.Column():
23
- gr.Dropdown(choices=["Выбор 1", "Выбор 2"], label="Выпадающий список")
 
 
24
  with gr.Row():
25
- gr.Slider(minimum=0, maximum=10, label="Ползунок")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  with gr.Row():
27
- gr.TextArea(label="Многострочное текстовое поле")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  if __name__ == "__main__":
30
- demo.launch()
 
1
+ import time
2
+
3
  import gradio as gr
4
 
5
+
6
+ from gradio.themes.utils.theme_dropdown import create_theme_dropdown
7
+
8
+ dropdown, js = create_theme_dropdown()
9
+
10
+ THEME = 'YTheme/PastelDark'
11
+
12
+ with gr.Blocks(theme=THEME) as demo:
13
+ with gr.Row().style(equal_height=True):
14
+ with gr.Column(scale=10):
15
+ gr.Markdown(
16
+ f"""
17
+ # Theme preview: `{THEME}`
18
+ To use this theme, set `theme='{THEME}'` in `gr.Blocks()` or `gr.Interface()`.
19
+ You can append an `@` and a semantic version expression, e.g. @>=1.0.0,<2.0.0 to pin to a given version
20
+ of this theme.
21
+ """
22
+ )
23
+ with gr.Column(scale=3):
24
+ with gr.Box():
25
+ dropdown.render()
26
+ toggle_dark = gr.Button(value="Toggle Dark").style(full_width=True)
27
+
28
+ dropdown.change(None, dropdown, None, _js=js)
29
+ toggle_dark.click(
30
+ None,
31
+ _js="""
32
+ () => {
33
+ document.body.classList.toggle('dark');
34
+ }
35
+ """,
36
+ )
37
+
38
+ name = gr.Textbox(
39
+ label="Name",
40
+ info="Full name, including middle name. No special characters.",
41
+ placeholder="John Doe",
42
+ value="John Doe",
43
+ interactive=True,
44
+ )
45
+
46
  with gr.Row():
47
+ slider1 = gr.Slider(label="Slider 1")
48
+ slider2 = gr.Slider(label="Slider 2")
49
+ gr.CheckboxGroup(["A", "B", "C"], label="Checkbox Group")
50
+
51
  with gr.Row():
52
+ with gr.Column(variant="panel", scale=1):
53
+ gr.Markdown("## Panel 1")
54
+ radio = gr.Radio(
55
+ ["A", "B", "C"],
56
+ label="Radio",
57
+ info="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
58
+ )
59
+ drop = gr.Dropdown(["Option 1", "Option 2", "Option 3"], show_label=False)
60
+ drop_2 = gr.Dropdown(
61
+ ["Option A", "Option B", "Option C"],
62
+ multiselect=True,
63
+ value=["Option A"],
64
+ label="Dropdown",
65
+ interactive=True,
66
+ )
67
+ check = gr.Checkbox(label="Go")
68
+ with gr.Column(variant="panel", scale=2):
69
+ img = gr.Image(
70
+ f"https://huggingface.co/spaces/{THEME}/resolve/main/header-image.jpg", label="Image"
71
+ ).style(height=320)
72
+ with gr.Row():
73
+ go_btn = gr.Button("Go", label="Primary Button", variant="primary")
74
+ clear_btn = gr.Button(
75
+ "Clear", label="Secondary Button", variant="secondary"
76
+ )
77
+
78
+ def go(*args):
79
+ time.sleep(3)
80
+ return f"https://huggingface.co/spaces/{THEME}/resolve/main/header-image.jpg"
81
+
82
+ go_btn.click(go, [radio, drop, drop_2, check, name], img, api_name="go")
83
+
84
+ def clear():
85
+ time.sleep(0.2)
86
+ return None
87
+
88
+ clear_btn.click(clear, None, img)
89
+
90
+ with gr.Row():
91
+ btn1 = gr.Button("Button 1").style(size="sm")
92
+ btn2 = gr.UploadButton().style(size="sm")
93
+ stop_btn = gr.Button("Stop", label="Stop Button", variant="stop").style(
94
+ size="sm"
95
+ )
96
+
97
  with gr.Row():
98
+ gr.Dataframe(value=[[1, 2, 3], [4, 5, 6], [7, 8, 9]], label="Dataframe")
99
+ gr.JSON(
100
+ value={"a": 1, "b": 2, "c": {"test": "a", "test2": [1, 2, 3]}}, label="JSON"
101
+ )
102
+ gr.Label(value={"cat": 0.7, "dog": 0.2, "fish": 0.1})
103
+ gr.File()
104
  with gr.Row():
105
+ gr.ColorPicker()
106
+ gr.Video("https://gradio-static-files.s3.us-west-2.amazonaws.com/world.mp4")
107
+ gr.Gallery(
108
+ [
109
+ (
110
+ "https://gradio-static-files.s3.us-west-2.amazonaws.com/lion.jpg",
111
+ "lion",
112
+ ),
113
+ (
114
+ "https://gradio-static-files.s3.us-west-2.amazonaws.com/logo.png",
115
+ "logo",
116
+ ),
117
+ (
118
+ "https://gradio-static-files.s3.us-west-2.amazonaws.com/tower.jpg",
119
+ "tower",
120
+ ),
121
+ ]
122
+ ).style(height="200px", grid=2)
123
+
124
  with gr.Row():
125
+ with gr.Column(scale=2):
126
+ chatbot = gr.Chatbot([("Hello", "Hi")], label="Chatbot")
127
+ chat_btn = gr.Button("Add messages")
128
+
129
+ def chat(history):
130
+ time.sleep(2)
131
+ yield [["How are you?", "I am good."]]
132
+
133
+ chat_btn.click(
134
+ lambda history: history
135
+ + [["How are you?", "I am good."]]
136
+ + (time.sleep(2) or []),
137
+ chatbot,
138
+ chatbot,
139
+ )
140
+ with gr.Column(scale=1):
141
+ with gr.Accordion("Advanced Settings"):
142
+ gr.Markdown("Hello")
143
+ gr.Number(label="Chatbot control 1")
144
+ gr.Number(label="Chatbot control 2")
145
+ gr.Number(label="Chatbot control 3")
146
+
147
 
148
  if __name__ == "__main__":
149
+ demo.queue().launch()