testingbot / app.py
Zahid0123's picture
Update app.py
30cf815 verified
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)