Spaces:
Configuration error
Configuration error
File size: 1,557 Bytes
de03546 e6a51c5 de03546 9a7c916 de03546 | 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | import os
import gradio as gr
from groq import Groq
# Load Groq API Key from environment variable
GROQ_API_KEY = os.getenv("Translator")
# Initialize Groq client
client = Groq(api_key=Translator)
def translate_text(text):
if not text.strip():
return "Please enter some English text."
try:
response = client.chat.completions.create(
model="llama-3.1-8b-instant", # Fast + good quality
messages=[
{
"role": "system",
"content": "You are a professional English to Urdu translator. Translate the user input into fluent and natural Urdu."
},
{
"role": "user",
"content": text
}
],
temperature=0.3
)
return response.choices[0].message.content
except Exception as e:
return f"Error: {str(e)}"
# Gradio UI
with gr.Blocks(title="English to Urdu Translator") as app:
gr.Markdown("## 🌍 English → Urdu Translator")
gr.Markdown("Powered by Groq API + LLaMA 3")
with gr.Row():
input_text = gr.Textbox(
label="Enter English Text",
placeholder="Type something in English...",
lines=5
)
translate_button = gr.Button("Translate")
output_text = gr.Textbox(
label="Urdu Translation",
lines=5
)
translate_button.click(
fn=translate_text,
inputs=input_text,
outputs=output_text
)
app.launch() |