Puck commited on
Commit
3e2371a
·
verified ·
1 Parent(s): bec54c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -1
app.py CHANGED
@@ -13,6 +13,9 @@ def translate_en_to_zh(text):
13
  translation = en_zh_translator(text)
14
  return translation[0]['translation_text']
15
 
 
 
 
16
  with gr.Blocks() as demo:
17
  input_text = gr.Textbox(lines=2, placeholder="Enter text here...", label="Input Text")
18
  output_text = gr.Textbox(lines=2, label="Translated Text")
@@ -20,8 +23,10 @@ with gr.Blocks() as demo:
20
  with gr.Row():
21
  zh_to_en_button = gr.Button("Chinese to English")
22
  en_to_zh_button = gr.Button("English to Chinese")
 
23
 
24
  zh_to_en_button.click(translate_zh_to_en, inputs=input_text, outputs=output_text)
25
  en_to_zh_button.click(translate_en_to_zh, inputs=input_text, outputs=output_text)
 
26
 
27
- demo.launch()
 
13
  translation = en_zh_translator(text)
14
  return translation[0]['translation_text']
15
 
16
+ def swap_text(input_text, output_text):
17
+ return output_text, input_text
18
+
19
  with gr.Blocks() as demo:
20
  input_text = gr.Textbox(lines=2, placeholder="Enter text here...", label="Input Text")
21
  output_text = gr.Textbox(lines=2, label="Translated Text")
 
23
  with gr.Row():
24
  zh_to_en_button = gr.Button("Chinese to English")
25
  en_to_zh_button = gr.Button("English to Chinese")
26
+ swap_button = gr.Button("Swap")
27
 
28
  zh_to_en_button.click(translate_zh_to_en, inputs=input_text, outputs=output_text)
29
  en_to_zh_button.click(translate_en_to_zh, inputs=input_text, outputs=output_text)
30
+ swap_button.click(swap_text, inputs=[input_text, output_text], outputs=[input_text, output_text])
31
 
32
+ demo.launch()