gradiospace / app.py
wayne0019's picture
Rename test.py to app.py
d808309
raw
history blame
1.02 kB
'''
对话机器人demo
'''
'''
通过t5模型进行翻译demo
'''
import gradio as gr
from transformers import pipeline
# pipe = pipeline("translation", model="t5-base") # default is English to German
# pipe = pipeline("translation_en_to_fr", model="t5-base") # translate English to France
pipe = pipeline("translation_en_to_fr", model="/Users/wayne/.cache/huggingface/hub/models--t5-base-lwf/snapshots/fe6d9bf207cd3337512ca838a8b453f87a9178ef")
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="German text")
translate_btn.click(fn=translate, inputs=[english], outputs=[german])
examples = gr.Examples(examples=["I went to the supermarket yesterday.", "Helen is a good swimmer."], inputs=[english])
demo.launch(server_port=8888)