translation / app.py
feaae's picture
Update app.py
541ca5d
raw
history blame
717 Bytes
import gradio as gr
from transformers import pipeline
pipe = pipeline("translation", model='facebook/m2m100_418M')
def translate(text):
return pipe(text)[0]["translation_text"]
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
english = gr.Textbox(label="English text")
translate_btn = gr.Button(value="Translate")
with gr.Column():
chinese = gr.Textbox(label="Chinese Text")
translate_btn.click(translate, inputs=english, outputs=chinese, api_name="translate-to-chinese")
examples = gr.Examples(examples=["I went to the supermarket yesterday.", "Helen is a good swimmer."],
inputs=[english])
demo.launch()