xumingliuJ commited on
Commit
7bee02a
1 Parent(s): 996e07d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from transformers import pipeline
4
+
5
+ pipe = pipeline("translation", model="Helsinki-NLP/opus-mt-en-zh")
6
+
7
+ def translate(text):
8
+ return pipe(text)[0]["translation_text"]
9
+
10
+
11
+ with gr.Blocks() as demo:
12
+ with gr.Row():
13
+ with gr.Column():
14
+ english = gr.Textbox(label="English text")
15
+ translate_btn = gr.Button(value="Translate")
16
+ with gr.Column():
17
+ chinese = gr.Textbox(label="Chinese Text")
18
+
19
+ translate_btn.click(translate, inputs=english, outputs=chinese, api_name="translate-to-chinese")
20
+ examples = gr.Examples(examples=["I went to the supermarket yesterday.", "Helen is a good swimmer."],
21
+ inputs=[english])
22
+
23
+ demo.launch(share=True)