AliArshad commited on
Commit
7632848
1 Parent(s): 96bbfa5
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Initialize the translation pipelines
5
+ pipe_en_to_ur = pipeline("translation_en_to_urdu", model="Helsinki-NLP/opus-mt-en-ur")
6
+ pipe_ur_to_en = pipeline("translation_ur_to_en", model="Helsinki-NLP/opus-mt-ur-en")
7
+
8
+ def translate_to_urdu(text):
9
+ return pipe_en_to_ur(text)[0]['translation_text']
10
+
11
+ def translate_to_english(text):
12
+ return pipe_ur_to_en(text)[0]['translation_text']
13
+
14
+ with gr.Blocks() as demo:
15
+ with gr.Row():
16
+ with gr.Column():
17
+ english = gr.Textbox(label="English text")
18
+ urdu = gr.Textbox(label="Urdu text")
19
+ with gr.Column():
20
+ translate_to_urdu_btn = gr.Button(value="Translate to Urdu")
21
+ translate_to_english_btn = gr.Button(value="Translate to English")
22
+
23
+ translate_to_urdu_btn.click(translate_to_urdu, inputs=english, outputs=urdu, api_name="translate-to-urdu")
24
+ translate_to_english_btn.click(translate_to_english, inputs=urdu, outputs=english, api_name="translate-to-english")
25
+
26
+
27
+
28
+ demo.launch()