bobhorn42 commited on
Commit
cc50a9c
1 Parent(s): fabba87

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ def translate(text,src,dst):
5
+ model_name = f"Helsinki-NLP/opus-mt-{src}-{dst}"
6
+ pipe = pipeline("translation", model=model_name)
7
+ return pipe(text)[0]["translation_text"]
8
+
9
+ demo = gr.Interface(
10
+ translate,
11
+ [
12
+ gr.Textbox(label="Texte a traduire"),
13
+ gr.Radio(["fr", "en","de","ru"], label="Langue source",value="fr"),
14
+ gr.Radio(["fr", "en","de","ru"], label="Langue cible",value="en"),
15
+ ],
16
+ "text",
17
+ examples=[
18
+ ["Quel age as-tu?","fr","en"],
19
+ ["How old are you?","en","fr"],
20
+ ["Mein Name ist Wolfgang und ich lebe in Berlin.","de","fr"],
21
+ ["Меня зовут Сара и я живу в Лондоне.","ru","fr"],
22
+ ]
23
+ )
24
+
25
+ if __name__ == "__main__":
26
+ demo.launch()