Spaces:
Runtime error
Runtime error
File size: 803 Bytes
cc50a9c c70aa7f cc50a9c 9510815 c70aa7f cc50a9c c70aa7f cc50a9c 9510815 |
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 |
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="Text to be translated"),
gr.Radio(["fr", "en","de","ru"], label="Source",value="fr"),
gr.Radio(["fr", "en","de","ru"], label="Target",value="en"),
],
"text",
examples=[
["Mon nom est Thomas et je vis à Paris.","fr","en"],
["My name is Bob and I live in London.","en","de"],
["Mein Name ist Wolfgang und ich lebe in Berlin.","de","fr"],
["Меня зовут Наташа и я живу в Москве.","ru","en"],
]
)
demo.launch() |