Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import os
|
|
| 2 |
import gradio as gr
|
| 3 |
from groq import Groq
|
| 4 |
|
|
|
|
| 5 |
client = Groq(
|
| 6 |
api_key=os.environ.get("GROQ_API_KEY")
|
| 7 |
)
|
|
@@ -12,9 +13,9 @@ def chat_fn(user_message, history):
|
|
| 12 |
|
| 13 |
messages = []
|
| 14 |
|
| 15 |
-
for
|
| 16 |
-
messages.append({"role": "user", "content":
|
| 17 |
-
messages.append({"role": "assistant", "content":
|
| 18 |
|
| 19 |
messages.append({"role": "user", "content": user_message})
|
| 20 |
|
|
@@ -25,37 +26,18 @@ def chat_fn(user_message, history):
|
|
| 25 |
|
| 26 |
bot_reply = response.choices[0].message.content
|
| 27 |
|
| 28 |
-
history.append(
|
| 29 |
return history
|
| 30 |
|
| 31 |
|
| 32 |
-
|
| 33 |
-
body {
|
| 34 |
-
background-color: #f8fafc;
|
| 35 |
-
color: #0f172a;
|
| 36 |
-
font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
.gradio-container {
|
| 40 |
-
max-width: 1200px;
|
| 41 |
-
margin: auto;
|
| 42 |
-
padding: 20px;
|
| 43 |
-
}
|
| 44 |
-
|
| 45 |
-
#chatbot {
|
| 46 |
-
background-color: #ffffff;
|
| 47 |
-
border-radius: 16px;
|
| 48 |
-
padding: 20px;
|
| 49 |
-
min-height: 65vh;
|
| 50 |
-
border: 1px solid #e5e7eb;
|
| 51 |
-
}
|
| 52 |
-
"""
|
| 53 |
-
|
| 54 |
-
with gr.Blocks(css=custom_css) as demo:
|
| 55 |
gr.Markdown("### Groq Chat")
|
| 56 |
|
| 57 |
-
chatbot = gr.Chatbot(
|
| 58 |
-
user_input = gr.Textbox(
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
user_input.submit(
|
| 61 |
chat_fn,
|
|
@@ -63,4 +45,5 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 63 |
outputs=chatbot
|
| 64 |
)
|
| 65 |
|
|
|
|
| 66 |
demo.launch()
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from groq import Groq
|
| 4 |
|
| 5 |
+
# Create Groq client
|
| 6 |
client = Groq(
|
| 7 |
api_key=os.environ.get("GROQ_API_KEY")
|
| 8 |
)
|
|
|
|
| 13 |
|
| 14 |
messages = []
|
| 15 |
|
| 16 |
+
for pair in history:
|
| 17 |
+
messages.append({"role": "user", "content": pair[0]})
|
| 18 |
+
messages.append({"role": "assistant", "content": pair[1]})
|
| 19 |
|
| 20 |
messages.append({"role": "user", "content": user_message})
|
| 21 |
|
|
|
|
| 26 |
|
| 27 |
bot_reply = response.choices[0].message.content
|
| 28 |
|
| 29 |
+
history.append([user_message, bot_reply])
|
| 30 |
return history
|
| 31 |
|
| 32 |
|
| 33 |
+
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
gr.Markdown("### Groq Chat")
|
| 35 |
|
| 36 |
+
chatbot = gr.Chatbot()
|
| 37 |
+
user_input = gr.Textbox(
|
| 38 |
+
placeholder="Type a message and press Enter",
|
| 39 |
+
show_label=False
|
| 40 |
+
)
|
| 41 |
|
| 42 |
user_input.submit(
|
| 43 |
chat_fn,
|
|
|
|
| 45 |
outputs=chatbot
|
| 46 |
)
|
| 47 |
|
| 48 |
+
demo.queue()
|
| 49 |
demo.launch()
|