Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from transformers import pipeline | |
| LANGUAGES = ["Spanish", "French", "German"] | |
| default_lang = "Spanish" | |
| title = "🦸TraveLingo" | |
| description = "Your AI-powered native translation buddy" | |
| more_description = "Give 🦸TraveLingo a try and get your English sentence translated to the destination language on the fly!" | |
| pipeline_1 = pipeline("translation", model="Helsinki-NLP/opus-mt-en-es") | |
| pipeline_2 = pipeline("translation", model="Helsinki-NLP/opus-mt-en-fr") | |
| pipeline_3 = pipeline("translation", model="Helsinki-NLP/opus-mt-en-de") | |
| def fn(text, lang_choice): | |
| if lang_choice=="Spanish": | |
| return pipeline_1(text)[0]["translation_text"] | |
| elif lang_choice=="French": | |
| return pipeline_2(text)[0]["translation_text"] | |
| elif lang_choice=="German": | |
| return pipeline_3(text)[0]["translation_text"] | |
| with gr.Blocks() as blocks: | |
| gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>" | |
| + title | |
| + "</h1>") | |
| gr.Markdown("<h3 style='text-align: center;'>" | |
| + description | |
| + "</h3>") | |
| gr.Markdown("<h5 style='text-align: center; margin-bottom: 1rem'>" | |
| + more_description | |
| + "</h3>") | |
| with gr.Row():# equal_height=False | |
| with gr.Column():# variant="panel" | |
| textbox = gr.Textbox( | |
| label="English Sentence", | |
| placeholder = "Hi, my name is Harish and I live in Bangalore.", | |
| max_lines=3, | |
| ) | |
| radio = gr.Radio( | |
| label="Destination Language", | |
| choices=LANGUAGES, | |
| value=default_lang | |
| ) | |
| with gr.Row():# mobile_collapse=False | |
| submit = gr.Button("Translate", variant="primary") | |
| output = gr.Text(label="Translated Sentence", interactive=False) | |
| submit.click( | |
| fn, | |
| [textbox, radio], | |
| output, | |
| ) | |
| blocks.launch() |