gradio/demo/english_translator/run.py
Freddy Boulton 3f9ec2c345
Add a guide on how to use apps like functions (#1799)
* Add examples for series and parallel

* Create demo + guide

* More formatting

* Change name of guide

* Fix typo

* Use english to german as example instead

* Expand phrase a bit
2022-07-19 17:43:53 -04:00

25 lines
700 B
Python

import gradio as gr
from transformers import pipeline
pipe = pipeline("translation", 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():
german = gr.Textbox(label="German Text")
translate_btn.click(translate, inputs=english, outputs=german)
examples = gr.Examples(examples=["I went to the supermarket yesterday.", "Helen is a good swimmer."],
inputs=[english])
if __name__ == "__main__":
demo.launch()