shanzaejaz commited on
Commit
7cfe646
·
verified ·
1 Parent(s): 396a9fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -2,15 +2,15 @@ import os
2
  import gradio as gr
3
  from groq import Groq
4
 
5
- # Initialize Groq client
6
  client = Groq(api_key=os.getenv("GROQ_API_KEY"))
7
 
8
  def translate_english_to_urdu(text):
9
- if text.strip() == "":
10
  return ""
11
 
12
  response = client.chat.completions.create(
13
- model="llama-3.1-8b-instant", # ✅ UPDATED MODEL
14
  messages=[
15
  {
16
  "role": "system",
@@ -18,7 +18,7 @@ def translate_english_to_urdu(text):
18
  },
19
  {
20
  "role": "user",
21
- "content": f"Translate this English text to Urdu:\n{text}"
22
  }
23
  ],
24
  temperature=0.2
@@ -26,21 +26,21 @@ def translate_english_to_urdu(text):
26
 
27
  return response.choices[0].message.content.strip()
28
 
29
- # Gradio UI
30
- app = gr.Interface(
31
  fn=translate_english_to_urdu,
32
  inputs=gr.Textbox(
33
  lines=5,
34
- label="English Text",
35
- placeholder="Enter English text here..."
36
  ),
37
  outputs=gr.Textbox(
38
  lines=5,
39
  label="Urdu Translation"
40
  ),
41
- title="English → Urdu Translator (GROQ)",
42
- description="Fast English to Urdu translation using Groq LLMs",
43
  )
44
 
45
  if __name__ == "__main__":
46
- app.launch()
 
2
  import gradio as gr
3
  from groq import Groq
4
 
5
+ # Initialize Groq client (API key comes from HF Secrets)
6
  client = Groq(api_key=os.getenv("GROQ_API_KEY"))
7
 
8
  def translate_english_to_urdu(text):
9
+ if not text or text.strip() == "":
10
  return ""
11
 
12
  response = client.chat.completions.create(
13
+ model="llama-3.1-8b-instant", # ✅ Active & updated model
14
  messages=[
15
  {
16
  "role": "system",
 
18
  },
19
  {
20
  "role": "user",
21
+ "content": f"Translate the following English text into Urdu:\n{text}"
22
  }
23
  ],
24
  temperature=0.2
 
26
 
27
  return response.choices[0].message.content.strip()
28
 
29
+ # Gradio Interface
30
+ demo = gr.Interface(
31
  fn=translate_english_to_urdu,
32
  inputs=gr.Textbox(
33
  lines=5,
34
+ placeholder="Enter English text here...",
35
+ label="English"
36
  ),
37
  outputs=gr.Textbox(
38
  lines=5,
39
  label="Urdu Translation"
40
  ),
41
+ title="English → Urdu Translator",
42
+ description="Fast English to Urdu translation using GROQ LLMs",
43
  )
44
 
45
  if __name__ == "__main__":
46
+ demo.launch()