Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -98,4 +98,37 @@ demo = gr.ChatInterface(
|
|
| 98 |
type="messages"
|
| 99 |
)
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
demo.launch(share=True)
|
|
|
|
| 98 |
type="messages"
|
| 99 |
)
|
| 100 |
|
| 101 |
+
demo.launch(share=True)
|
| 102 |
+
import gradio as gr
|
| 103 |
+
from groq import Groq
|
| 104 |
+
|
| 105 |
+
client = Groq(api_key="YOUR_GROQ_API_KEY")
|
| 106 |
+
|
| 107 |
+
SYSTEM_PROMPT = """
|
| 108 |
+
You are a helpful AI assistant.
|
| 109 |
+
You remember full conversation and answer continuously.
|
| 110 |
+
"""
|
| 111 |
+
|
| 112 |
+
def chat(message, history):
|
| 113 |
+
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 114 |
+
|
| 115 |
+
# ✅ FIX: correct Gradio "messages" format handling
|
| 116 |
+
for msg in history:
|
| 117 |
+
messages.append(msg)
|
| 118 |
+
|
| 119 |
+
messages.append({"role": "user", "content": message})
|
| 120 |
+
|
| 121 |
+
response = client.chat.completions.create(
|
| 122 |
+
model="llama-3.3-70b-versatile",
|
| 123 |
+
messages=messages
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
return response.choices[0].message.content
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
demo = gr.ChatInterface(
|
| 130 |
+
fn=chat,
|
| 131 |
+
type="messages" # 🔥 IMPORTANT FIX
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
demo.launch(share=True)
|