Spaces:
Sleeping
Sleeping
File size: 1,641 Bytes
12a5d73 ec94136 30cf815 12a5d73 ec94136 7305a86 30cf815 7305a86 30cf815 12a5d73 ec94136 30cf815 12a5d73 7305a86 ec94136 12a5d73 30cf815 12a5d73 7305a86 12a5d73 ec94136 12a5d73 30cf815 ec94136 30cf815 12a5d73 | 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 | import gradio as gr
from groq import Groq
# ===============================
# 🔑 HARDCODE YOUR GROQ API KEY HERE
# ===============================
GROQ_API_KEY = "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" # <- Replace with your new Groq key
# ===============================
# Initialize Groq client
# ===============================
client = None
status = ""
try:
print("DEBUG → Initializing Groq client...")
client = Groq(api_key=GROQ_API_KEY)
status = "Groq client initialized! ✅"
print("DEBUG → Groq client initialized successfully!")
except Exception as e:
status = f"Error initializing Groq client: {e}"
print("DEBUG → Groq initialization error:", e)
# ===============================
# Chat function
# ===============================
def chat(message, history):
if client is None:
return "Groq client not initialized! Check your API key."
try:
response = client.chat.completions.create(
model="llama-3.3-70b-versatile", # <- UPDATED SUPPORTED MODEL
messages=[{"role": "user", "content": message}],
temperature=0.3,
max_tokens=500,
)
return response.choices[0].message.content
except Exception as e:
print("DEBUG → Chat API error:", str(e))
return f"Groq API Error: {e}"
# ===============================
# Gradio interface
# ===============================
with gr.Blocks(title="Groq Chat") as demo:
gr.Markdown("# 🔑 Chat with Groq")
gr.Markdown(f"**Status:** {status}")
gr.ChatInterface(chat)
demo.launch(server_name="0.0.0.0", server_port=7860)
|