|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
pipe_en_to_ur = pipeline("translation_en_to_urdu", model="Helsinki-NLP/opus-mt-en-ur") |
|
pipe_ur_to_en = pipeline("translation_ur_to_en", model="Helsinki-NLP/opus-mt-ur-en") |
|
|
|
def translate_to_urdu(text): |
|
return pipe_en_to_ur(text)[0]['translation_text'] |
|
|
|
def translate_to_english(text): |
|
return pipe_ur_to_en(text)[0]['translation_text'] |
|
|
|
with gr.Blocks() as demo: |
|
with gr.Row(): |
|
with gr.Column(): |
|
english = gr.Textbox(label="English text") |
|
urdu = gr.Textbox(label="Urdu text") |
|
with gr.Column(): |
|
translate_to_urdu_btn = gr.Button(value="Translate to Urdu") |
|
translate_to_english_btn = gr.Button(value="Translate to English") |
|
|
|
translate_to_urdu_btn.click(translate_to_urdu, inputs=english, outputs=urdu, api_name="translate-to-urdu") |
|
translate_to_english_btn.click(translate_to_english, inputs=urdu, outputs=english, api_name="translate-to-english") |
|
|
|
|
|
|
|
demo.launch() |
|
|