Spaces:
Running
Running
application file
Browse files- app.py +42 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
import yaml
|
5 |
+
from gradio_i18n import dump_blocks, gettext, translate_blocks
|
6 |
+
|
7 |
+
|
8 |
+
def greet(name, age, gender, school):
|
9 |
+
return f"hello {name}! Age: {age}"
|
10 |
+
|
11 |
+
|
12 |
+
trans_file = "translations.yaml"
|
13 |
+
if not os.path.exists(trans_file):
|
14 |
+
lang_store = {}
|
15 |
+
else:
|
16 |
+
lang_store = yaml.safe_load(open(trans_file))
|
17 |
+
|
18 |
+
|
19 |
+
with gr.Blocks() as block:
|
20 |
+
with gr.Accordion(label=gettext("Accordion")):
|
21 |
+
name = gr.Textbox(label=gettext("Submit"), value="World")
|
22 |
+
greeting = gr.Textbox(placeholder=gettext("text"))
|
23 |
+
age = gr.Slider(
|
24 |
+
minimum=0,
|
25 |
+
maximum=100,
|
26 |
+
value=50,
|
27 |
+
label=gettext("Age"),
|
28 |
+
)
|
29 |
+
|
30 |
+
gender = gr.Radio(choices=["male", "female"], label=gettext("Gender"))
|
31 |
+
school = gr.Dropdown(["MIT", "Stanford", "CMU"], label=gettext("School"))
|
32 |
+
|
33 |
+
btn = gr.Button(value=gettext("Submit"))
|
34 |
+
btn.click(greet, [name, age, gender, school], [greeting])
|
35 |
+
|
36 |
+
translate_blocks(block, lang_store)
|
37 |
+
|
38 |
+
trans = dump_blocks(block, langs=["zh", "en"], include_translations=lang_store)
|
39 |
+
yaml.safe_dump(trans, open(trans_file, "w"), allow_unicode=True)
|
40 |
+
|
41 |
+
block.launch()
|
42 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
pyyaml
|
2 |
+
gradio
|
3 |
+
gradio-i18n
|