feaae commited on
Commit
bdf8701
·
1 Parent(s): d99b487

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -6
app.py CHANGED
@@ -2,22 +2,35 @@ import gradio as gr
2
 
3
  from transformers import pipeline
4
 
5
- pipe = pipeline("translation_en_to_zh", model='facebook/m2m100_418M')
6
 
 
 
 
 
 
 
7
 
8
- def translate(text):
 
 
 
 
 
9
  return pipe(text)[0]["translation_text"]
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()
 
2
 
3
  from transformers import pipeline
4
 
 
5
 
6
+ model_list = [
7
+ "facebook/m2m100_418M",
8
+ "Helsinki-NLP/opus-mt-en-zh",
9
+ "liam168/trans-opus-mt-en-zh",
10
+ "facebook/nllb-200-3.3B"
11
+ ]
12
 
13
+ #init
14
+ for model_name in model_list:
15
+ pipeline("translation_en_to_zh", model=model_name)
16
+
17
+ def translate(text, model_name):
18
+ pipe = pipeline("translation_en_to_zh", model=model_name)
19
  return pipe(text)[0]["translation_text"]
20
 
21
  with gr.Blocks() as demo:
22
  with gr.Row():
23
  with gr.Column():
24
+ englishtxt_model_input = [
25
+ gr.Textbox(label="English text"),
26
+ gr.Dropdown(model_list, value="facebook/m2m100_418M", label="Model")
27
+ ]
28
  translate_btn = gr.Button(value="Translate")
29
  with gr.Column():
30
+ chinese_output = gr.Textbox(label="Chinese Text")
31
 
32
+ translate_btn.click(translate, inputs=englishtxt_model_input, outputs=chinese_output, api_name="translate-to-chinese")
33
  examples = gr.Examples(examples=["I went to the supermarket yesterday.", "Helen is a good swimmer."],
34
  inputs=[english])
35
 
36
+ demo.launch()