Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import pipeline | |
# import os | |
# os.environ["no_proxy"] = "localhost,127.0.0.1,::1" | |
# pipe = pipeline("translation", model="t5-base") | |
pipe = pipeline("translation_en_to_zh", 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="English text") | |
translate_btn = gr.Button(value="Translate") | |
with gr.Column(): | |
german = gr.Textbox(label="Chinese Text") | |
translate_btn.click(translate, inputs=english, outputs=german, api_name="translate-to-chinese") | |
examples = gr.Examples(examples=["I went to the supermarket yesterday.", "Helen is a good swimmer."], | |
inputs=[english]) | |
demo.launch() |