Spaces:
Build error
Build error
Download app.py from awaheed/language_translator: direct link, hf CLI and curl.
- Browser
- Download file 796 Bytes
-
https://huggingface.co/spaces/awaheed/language_translator/resolve/main/app.py
- Command line
-
hf download hf://spaces/awaheed/language_translator/app.py
-
curl -L -o app.py https://huggingface.co/spaces/awaheed/language_translator/resolve/main/app.py
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() |