File size: 1,245 Bytes
55099ce
 
 
 
7cfe646
55099ce
 
 
7cfe646
55099ce
 
 
7cfe646
55099ce
 
 
 
 
 
 
7cfe646
396a9fb
 
 
 
 
 
 
7cfe646
 
396a9fb
 
 
7cfe646
 
396a9fb
 
 
 
 
7cfe646
 
396a9fb
 
 
7cfe646
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import gradio as gr
from groq import Groq

# Initialize Groq client (API key comes from HF Secrets)
client = Groq(api_key=os.getenv("GROQ_API_KEY"))

def translate_english_to_urdu(text):
    if not text or text.strip() == "":
        return ""

    response = client.chat.completions.create(
        model="llama-3.1-8b-instant",  # ✅ Active & updated model
        messages=[
            {
                "role": "system",
                "content": "You are a professional English to Urdu translator. Translate accurately and naturally."
            },
            {
                "role": "user",
                "content": f"Translate the following English text into Urdu:\n{text}"
            }
        ],
        temperature=0.2
    )

    return response.choices[0].message.content.strip()

# Gradio Interface
demo = gr.Interface(
    fn=translate_english_to_urdu,
    inputs=gr.Textbox(
        lines=5,
        placeholder="Enter English text here...",
        label="English"
    ),
    outputs=gr.Textbox(
        lines=5,
        label="Urdu Translation"
    ),
    title="English → Urdu Translator",
    description="Fast English to Urdu translation using GROQ LLMs",
)

if __name__ == "__main__":
    demo.launch()