File size: 1,047 Bytes
7632848 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import gradio as gr
from transformers import pipeline
# Initialize the translation pipelines
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()
|