Spaces:
Runtime error
Runtime error
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() |