File size: 797 Bytes
cc50a9c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import gradio as gr
from transformers import pipeline

def translate(text,src,dst):
    model_name = f"Helsinki-NLP/opus-mt-{src}-{dst}"
    pipe = pipeline("translation", model=model_name)
    return pipe(text)[0]["translation_text"]

demo = gr.Interface(
    translate,
    [
        gr.Textbox(label="Texte a traduire"),
        gr.Radio(["fr", "en","de","ru"], label="Langue source",value="fr"),
        gr.Radio(["fr", "en","de","ru"], label="Langue cible",value="en"),
    ],
    "text",
    examples=[
        ["Quel age as-tu?","fr","en"],
        ["How old are you?","en","fr"],
        ["Mein Name ist Wolfgang und ich lebe in Berlin.","de","fr"],
        ["Меня зовут Сара и я живу в Лондоне.","ru","fr"],
    ]
)

if __name__ == "__main__":
    demo.launch()