AmirAziz1221 commited on
Commit
0f4418f
Β·
verified Β·
1 Parent(s): ddd80b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -14
app.py CHANGED
@@ -30,27 +30,58 @@ def translate_to_urdu(english_text):
30
 
31
  return response.choices[0].message.content.strip()
32
 
33
- # Gradio UI
 
 
 
 
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 **Groq LLM**
39
  """
40
  )
41
 
42
- with gr.Row():
43
- input_text = gr.Textbox(
44
- label="English Text",
45
- placeholder="Enter English sentence here...",
46
- lines=5
47
- )
48
- output_text = gr.Textbox(
49
- label="Urdu Translation",
50
- lines=5
51
- )
52
 
53
  translate_btn = gr.Button("Translate πŸ‡΅πŸ‡°")
54
  translate_btn.click(translate_to_urdu, input_text, output_text)
55
 
56
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()