Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,27 +30,58 @@ def translate_to_urdu(english_text):
|
|
| 30 |
|
| 31 |
return response.choices[0].message.content.strip()
|
| 32 |
|
| 33 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
with gr.Blocks(theme=gr.themes.Soft(), title="English β Urdu Translator") as demo:
|
| 35 |
gr.Markdown(
|
| 36 |
"""
|
| 37 |
-
# π English β Urdu Translator Chatbot
|
| 38 |
-
Powered by
|
| 39 |
"""
|
| 40 |
)
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
|
| 53 |
translate_btn = gr.Button("Translate π΅π°")
|
| 54 |
translate_btn.click(translate_to_urdu, input_text, output_text)
|
| 55 |
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
return response.choices[0].message.content.strip()
|
| 32 |
|
| 33 |
+
# Demo click function
|
| 34 |
+
def demo_translate(text):
|
| 35 |
+
return text, translate_to_urdu(text)
|
| 36 |
+
|
| 37 |
+
# UI
|
| 38 |
with gr.Blocks(theme=gr.themes.Soft(), title="English β Urdu Translator") as demo:
|
| 39 |
gr.Markdown(
|
| 40 |
"""
|
| 41 |
+
# π English β Urdu Translator Chatbot
|
| 42 |
+
**Powered by Groq LLM**
|
| 43 |
"""
|
| 44 |
)
|
| 45 |
|
| 46 |
+
input_text = gr.Textbox(
|
| 47 |
+
label="English Text",
|
| 48 |
+
placeholder="Enter English sentence here...",
|
| 49 |
+
lines=4
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
output_text = gr.Textbox(
|
| 53 |
+
label="Urdu Translation",
|
| 54 |
+
lines=4
|
| 55 |
+
)
|
| 56 |
|
| 57 |
translate_btn = gr.Button("Translate π΅π°")
|
| 58 |
translate_btn.click(translate_to_urdu, input_text, output_text)
|
| 59 |
|
| 60 |
+
gr.Markdown("### πΉ Try Demo Examples (Click & Translate)")
|
| 61 |
+
|
| 62 |
+
demo_sentences = [
|
| 63 |
+
"Education is the key to success.",
|
| 64 |
+
"Artificial intelligence is changing the world.",
|
| 65 |
+
"Please submit your assignment before Friday.",
|
| 66 |
+
"Healthcare systems need modern technology.",
|
| 67 |
+
"Pakistan is a beautiful country with rich culture.",
|
| 68 |
+
"I am learning machine learning and data science."
|
| 69 |
+
]
|
| 70 |
+
|
| 71 |
+
with gr.Row():
|
| 72 |
+
for sentence in demo_sentences[:3]:
|
| 73 |
+
gr.Button(sentence).click(
|
| 74 |
+
demo_translate,
|
| 75 |
+
outputs=[input_text, output_text],
|
| 76 |
+
inputs=[]
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
with gr.Row():
|
| 80 |
+
for sentence in demo_sentences[3:]:
|
| 81 |
+
gr.Button(sentence).click(
|
| 82 |
+
demo_translate,
|
| 83 |
+
outputs=[input_text, output_text],
|
| 84 |
+
inputs=[]
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
demo.launch()
|