Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,37 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from groq import Groq
|
| 3 |
|
| 4 |
-
# ===============================
|
| 5 |
-
# 🔑 HARDCODE YOUR GROQ API KEY HERE
|
| 6 |
-
# ===============================
|
| 7 |
-
GROQ_API_KEY = "
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
| 9 |
client = None
|
| 10 |
status = ""
|
| 11 |
|
| 12 |
-
# ============================================================
|
| 13 |
-
# Initialize Groq Client
|
| 14 |
-
# ============================================================
|
| 15 |
try:
|
| 16 |
print("DEBUG → Initializing Groq client...")
|
| 17 |
client = Groq(api_key=GROQ_API_KEY)
|
|
|
|
| 18 |
print("DEBUG → Groq client initialized successfully!")
|
| 19 |
-
status = "Groq client initialized! Your API key is working."
|
| 20 |
except Exception as e:
|
| 21 |
-
|
| 22 |
-
|
| 23 |
|
| 24 |
|
| 25 |
-
# ===============================
|
| 26 |
-
# Chat
|
| 27 |
-
# ===============================
|
| 28 |
def chat(message, history):
|
| 29 |
if client is None:
|
| 30 |
return "Groq client not initialized! Check your API key."
|
| 31 |
|
| 32 |
try:
|
| 33 |
response = client.chat.completions.create(
|
| 34 |
-
model="llama-3.
|
| 35 |
messages=[{"role": "user", "content": message}],
|
| 36 |
temperature=0.3,
|
| 37 |
max_tokens=500,
|
|
@@ -39,16 +39,16 @@ def chat(message, history):
|
|
| 39 |
return response.choices[0].message.content
|
| 40 |
|
| 41 |
except Exception as e:
|
| 42 |
-
print("DEBUG → Chat
|
| 43 |
return f"Groq API Error: {e}"
|
| 44 |
|
| 45 |
|
| 46 |
-
# ===============================
|
| 47 |
-
# Gradio
|
| 48 |
-
# ===============================
|
| 49 |
-
with gr.Blocks(title="Groq
|
| 50 |
-
gr.Markdown("# 🔑
|
| 51 |
-
gr.Markdown(status)
|
| 52 |
gr.ChatInterface(chat)
|
| 53 |
|
| 54 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from groq import Groq
|
| 3 |
|
| 4 |
+
# ===============================
|
| 5 |
+
# 🔑 HARDCODE YOUR GROQ API KEY HERE
|
| 6 |
+
# ===============================
|
| 7 |
+
GROQ_API_KEY = "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" # <- Replace with your new Groq key
|
| 8 |
+
|
| 9 |
+
# ===============================
|
| 10 |
+
# Initialize Groq client
|
| 11 |
+
# ===============================
|
| 12 |
client = None
|
| 13 |
status = ""
|
| 14 |
|
|
|
|
|
|
|
|
|
|
| 15 |
try:
|
| 16 |
print("DEBUG → Initializing Groq client...")
|
| 17 |
client = Groq(api_key=GROQ_API_KEY)
|
| 18 |
+
status = "Groq client initialized! ✅"
|
| 19 |
print("DEBUG → Groq client initialized successfully!")
|
|
|
|
| 20 |
except Exception as e:
|
| 21 |
+
status = f"Error initializing Groq client: {e}"
|
| 22 |
+
print("DEBUG → Groq initialization error:", e)
|
| 23 |
|
| 24 |
|
| 25 |
+
# ===============================
|
| 26 |
+
# Chat function
|
| 27 |
+
# ===============================
|
| 28 |
def chat(message, history):
|
| 29 |
if client is None:
|
| 30 |
return "Groq client not initialized! Check your API key."
|
| 31 |
|
| 32 |
try:
|
| 33 |
response = client.chat.completions.create(
|
| 34 |
+
model="llama-3.3-70b-versatile", # <- UPDATED SUPPORTED MODEL
|
| 35 |
messages=[{"role": "user", "content": message}],
|
| 36 |
temperature=0.3,
|
| 37 |
max_tokens=500,
|
|
|
|
| 39 |
return response.choices[0].message.content
|
| 40 |
|
| 41 |
except Exception as e:
|
| 42 |
+
print("DEBUG → Chat API error:", str(e))
|
| 43 |
return f"Groq API Error: {e}"
|
| 44 |
|
| 45 |
|
| 46 |
+
# ===============================
|
| 47 |
+
# Gradio interface
|
| 48 |
+
# ===============================
|
| 49 |
+
with gr.Blocks(title="Groq Chat") as demo:
|
| 50 |
+
gr.Markdown("# 🔑 Chat with Groq")
|
| 51 |
+
gr.Markdown(f"**Status:** {status}")
|
| 52 |
gr.ChatInterface(chat)
|
| 53 |
|
| 54 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|