awaheed's picture
Create app.py
45ac425
Raw History Blame Contribute Delete
796 Bytes
import gradio as gr
from transformers import pipeline
pipe = pipeline(task="translation", model="t5-base")
# function
def translate(text):
return pipe(text)[0]["translation_text"]
# UI
# 1 row, 2 columns
# english, german, button, examples
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
txt_english = gr.Textbox(label="English Text")
btn_translate = gr.Button(value="Translate")
with gr.Column():
txt_german = gr.Textbox(label="German Text")
btn_translate.click(
fn=translate,
inputs=txt_english,
outputs=txt_german
)
examples = gr.Examples(
examples=["Welcome","hello","Everything is going to be an AI"],
inputs=[txt_english]
)
# lauch demo
demo.launch()