trans-en2zh / main.py
Forceless's picture
Upload folder using huggingface_hub
26256cb
raw
history blame contribute delete
No virus
727 Bytes
import gradio as gr
from transformers import pipeline
pipe = pipeline("translation", model="Helsinki-NLP/opus-mt-en-zh")
def translate(text):
return pipe(text)[0]["translation_text"]
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
english = gr.Textbox(label="英文文本")
translate_btn = gr.Button(value="Hello")
with gr.Column():
german = gr.Textbox(label="中文翻译")
translate_btn.click(translate, inputs=english, outputs=german, api_name="translate-to-german")
examples = gr.Examples(examples=["I went to the supermarket yesterday.", "Helen is a good swimmer."],
inputs=[english])
demo.launch(share=True)