wenjiao commited on
Commit
5a03d97
·
1 Parent(s): 51240a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -25
app.py CHANGED
@@ -1,31 +1,45 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  def initialize_interface():
4
- # Create a JavaScript snippet to detect the browser language
5
  detect_language_js = """
6
- var language = window.navigator.userLanguage || window.navigator.language;
7
- if (language === "zh-CN") {
8
- document.getElementById("container").innerHTML = `
9
- <div>
10
- <label for="select_radio">你想使用哪种风格?</label>
11
- <input type="radio" name="select_radio" value="卡通" checked> 卡通
12
- <input type="radio" name="select_radio" value="风景"> 风景
13
- <input type="radio" name="select_radio" value="肖像"> 肖像
14
- <input type="radio" name="select_radio" value="生活"> 生活
15
- </div>
16
- `;
17
- } else {
18
- document.getElementById("container").innerHTML = `
19
- <div>
20
- <label for="select_detail">Providing your cartoon photos, scenes and decorations can be redesigned for your cartoon characters.</label>
21
- <input type="text" id="select_detail" value="" style="width: 300px;">
22
- </div>
23
- `;
24
- }
25
- """
26
-
27
- # Create a Gradio interface with a dummy input and WebView output
28
- interface = gr.Interface(fn=lambda x: None, inputs="text", outputs="webview")
29
- interface.launch(share=True, update_fn=detect_language_js, webview_size=(600, 200))
30
 
31
  initialize_interface()
 
 
 
 
1
  import gradio as gr
2
+ import os
3
+
4
+
5
+ def combine(a, b):
6
+ return a + " " + b
7
+
8
+
9
+ def mirror(x):
10
+ return x
11
+
12
+ md = "test"
13
+ CN_md = "测试"
14
+
15
 
16
  def initialize_interface():
 
17
  detect_language_js = """
18
+ var language = window.navigator.userLanguage || window.navigator.language; """
19
+ print('language', language)
20
+
21
+ with gr.Blocks() as demo:
22
+ gr.Markdown(md)
23
+
24
+ change_language_radio = gr.Radio(["Chinese", "English"])
25
+ language = gr.Textbox(label="Language")
26
+ txt = gr.Textbox(label="Input", lines=2)
27
+ txt_2 = gr.Textbox(label="Input 2")
28
+ txt_3 = gr.Textbox(value="", label="Output")
29
+ btn = gr.Button(value="Submit")
30
+ btn.click(combine, inputs=[txt, txt_2], outputs=[txt_3])
31
+
32
+ with gr.Row():
33
+ im = gr.Image()
34
+ im_2 = gr.Image()
35
+
36
+ btn = gr.Button(value="Mirror Image")
37
+ btn.click(mirror, inputs=[im], outputs=[im_2])
38
+
39
+ change_language_radio.change(None, [], [language], _js="() => navigator.language")
40
+
 
41
 
42
  initialize_interface()
43
+
44
+ if __name__ == "__main__":
45
+ demo.launch()