Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,6 +10,7 @@ API_URL = "https://api.groq.com/openai/v1/chat/completions"
|
|
| 10 |
API_KEY = os.getenv("GROQ_API_KEY")
|
| 11 |
|
| 12 |
print(f"π API Key Found: {'Yes' if API_KEY else 'No'}")
|
|
|
|
| 13 |
|
| 14 |
# In-memory chat history storage
|
| 15 |
chat_history: List[Dict[str, str]] = []
|
|
@@ -18,7 +19,7 @@ def groq_with_memory(message: str, topic: str = "general", summarize: bool = Fal
|
|
| 18 |
"""Groq API call with chat history and optional summarization, returning chatbot format"""
|
| 19 |
|
| 20 |
if not API_KEY:
|
| 21 |
-
return [[None, "β No API Key found"]]
|
| 22 |
|
| 23 |
if not message.strip():
|
| 24 |
return [[None, "β Empty message"]]
|
|
@@ -125,7 +126,7 @@ def view_history(topic: str = None) -> str:
|
|
| 125 |
def manual_curl_example():
|
| 126 |
"""Generate curl command for manual testing"""
|
| 127 |
if not API_KEY:
|
| 128 |
-
return "β No API key to generate curl"
|
| 129 |
|
| 130 |
curl_cmd = f'''curl -X POST "{API_URL}" \\
|
| 131 |
-H "Authorization: Bearer {API_KEY}" \\
|
|
@@ -147,10 +148,10 @@ with gr.Blocks(title="Grok Debug with Memory", css="""
|
|
| 147 |
.chatbot .message.user { text-align: left; background: #e6f3ff; padding: 10px; border-radius: 10px; margin: 5px; }
|
| 148 |
.chatbot .message.assistant { text-align: right; background: #f0f0f0; padding: 10px; border-radius: 10px; margin: 5px; }
|
| 149 |
""") as demo:
|
| 150 |
-
gr.Markdown("# π
|
| 151 |
|
| 152 |
with gr.Tab("Chat with Memory"):
|
| 153 |
-
gr.Markdown("Chat with
|
| 154 |
|
| 155 |
chatbot = gr.Chatbot(
|
| 156 |
label="Conversation",
|
|
@@ -248,6 +249,10 @@ with gr.Blocks(title="Grok Debug with Memory", css="""
|
|
| 248 |
- `llama3-70b-8192`
|
| 249 |
- `mixtral-8x7b-32768`
|
| 250 |
- `gemma-7b-it`
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
""")
|
| 252 |
|
| 253 |
if __name__ == "__main__":
|
|
|
|
| 10 |
API_KEY = os.getenv("GROQ_API_KEY")
|
| 11 |
|
| 12 |
print(f"π API Key Found: {'Yes' if API_KEY else 'No'}")
|
| 13 |
+
print("Environment Variables:", {k: v for k, v in os.environ.items() if k.startswith('GROQ')}) # Debug print
|
| 14 |
|
| 15 |
# In-memory chat history storage
|
| 16 |
chat_history: List[Dict[str, str]] = []
|
|
|
|
| 19 |
"""Groq API call with chat history and optional summarization, returning chatbot format"""
|
| 20 |
|
| 21 |
if not API_KEY:
|
| 22 |
+
return [[None, "β No API Key found. Please set GROQ_API_KEY in Hugging Face Spaces Settings > Secrets. Go to https://console.groq.com/keys to get your key."]]
|
| 23 |
|
| 24 |
if not message.strip():
|
| 25 |
return [[None, "β Empty message"]]
|
|
|
|
| 126 |
def manual_curl_example():
|
| 127 |
"""Generate curl command for manual testing"""
|
| 128 |
if not API_KEY:
|
| 129 |
+
return "β No API key to generate curl. Set GROQ_API_KEY in Hugging Face Spaces Settings > Secrets."
|
| 130 |
|
| 131 |
curl_cmd = f'''curl -X POST "{API_URL}" \\
|
| 132 |
-H "Authorization: Bearer {API_KEY}" \\
|
|
|
|
| 148 |
.chatbot .message.user { text-align: left; background: #e6f3ff; padding: 10px; border-radius: 10px; margin: 5px; }
|
| 149 |
.chatbot .message.assistant { text-align: right; background: #f0f0f0; padding: 10px; border-radius: 10px; margin: 5px; }
|
| 150 |
""") as demo:
|
| 151 |
+
gr.Markdown("# π Grok API Debug Tool with Memory")
|
| 152 |
|
| 153 |
with gr.Tab("Chat with Memory"):
|
| 154 |
+
gr.Markdown("Chat with Grok, maintain history, and summarize by topic")
|
| 155 |
|
| 156 |
chatbot = gr.Chatbot(
|
| 157 |
label="Conversation",
|
|
|
|
| 249 |
- `llama3-70b-8192`
|
| 250 |
- `mixtral-8x7b-32768`
|
| 251 |
- `gemma-7b-it`
|
| 252 |
+
|
| 253 |
+
**API Key Setup:**
|
| 254 |
+
- Ensure GROQ_API_KEY is set in Hugging Face Spaces Settings > Secrets.
|
| 255 |
+
- Get your key from https://console.groq.com/keys.
|
| 256 |
""")
|
| 257 |
|
| 258 |
if __name__ == "__main__":
|