Spaces:
Sleeping
Sleeping
File size: 995 Bytes
1f7513b dcad8f5 1f7513b 10b7b4a 1f7513b 10b7b4a 1f7513b 10b7b4a 1f7513b 9d0350e dc32a4e 1f7513b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
'''
对话机器人demo
'''
'''
通过t5模型进行翻译
'''
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="t5-base")
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():
France = gr.Textbox(label="France text")
translate_btn.click(fn=translate, inputs=[english], outputs=[France])
examples = gr.Examples(examples=["I went to the supermarket yesterday.", "Helen is a good swimmer."], inputs=[english])
demo.launch(server_port=9001)
#demo.launch(server_port=9000, share=True) # share is not supported in Space
|