Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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",
|
| 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
|
| 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
|
| 30 |
-
|
| 31 |
fn=translate_english_to_urdu,
|
| 32 |
inputs=gr.Textbox(
|
| 33 |
lines=5,
|
| 34 |
-
|
| 35 |
-
|
| 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
|
| 43 |
)
|
| 44 |
|
| 45 |
if __name__ == "__main__":
|
| 46 |
-
|
|
|
|
| 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()
|