Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,19 +20,9 @@ def chat_with_groq(user_message, history):
|
|
| 20 |
if not user_message or not user_message.strip():
|
| 21 |
return history, ""
|
| 22 |
|
| 23 |
-
|
| 24 |
-
history.append({
|
| 25 |
-
|
| 26 |
-
"content": user_message
|
| 27 |
-
})
|
| 28 |
-
|
| 29 |
-
# Add thinking placeholder
|
| 30 |
-
history.append({
|
| 31 |
-
"role": "assistant",
|
| 32 |
-
"content": "⚡ Groq is thinking..."
|
| 33 |
-
})
|
| 34 |
-
|
| 35 |
-
# Prepare messages for Groq
|
| 36 |
messages = [
|
| 37 |
{"role": msg["role"], "content": msg["content"]}
|
| 38 |
for msg in history[:-1]
|
|
@@ -43,12 +33,10 @@ def chat_with_groq(user_message, history):
|
|
| 43 |
model="llama-3.3-70b-versatile",
|
| 44 |
messages=messages,
|
| 45 |
)
|
| 46 |
-
|
| 47 |
history[-1] = {
|
| 48 |
"role": "assistant",
|
| 49 |
"content": completion.choices[0].message.content
|
| 50 |
}
|
| 51 |
-
|
| 52 |
except Exception as e:
|
| 53 |
history[-1] = {
|
| 54 |
"role": "assistant",
|
|
@@ -64,9 +52,10 @@ def clear_chat():
|
|
| 64 |
return [], ""
|
| 65 |
|
| 66 |
# =====================================================
|
| 67 |
-
# CSS (Light +
|
| 68 |
# =====================================================
|
| 69 |
custom_css = """
|
|
|
|
| 70 |
:root {
|
| 71 |
--bg: #f9fafb;
|
| 72 |
--surface: #ffffff;
|
|
@@ -88,6 +77,7 @@ custom_css = """
|
|
| 88 |
}
|
| 89 |
}
|
| 90 |
|
|
|
|
| 91 |
body {
|
| 92 |
background-color: var(--bg);
|
| 93 |
}
|
|
@@ -96,9 +86,11 @@ body {
|
|
| 96 |
max-width: 1100px !important;
|
| 97 |
margin: auto;
|
| 98 |
padding: 24px;
|
|
|
|
| 99 |
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
| 100 |
}
|
| 101 |
|
|
|
|
| 102 |
h1 {
|
| 103 |
color: var(--text);
|
| 104 |
text-align: center;
|
|
@@ -112,15 +104,18 @@ h1 {
|
|
| 112 |
margin-bottom: 20px;
|
| 113 |
}
|
| 114 |
|
|
|
|
| 115 |
.chatbot {
|
| 116 |
background: var(--surface);
|
| 117 |
border-radius: 16px;
|
| 118 |
padding: 16px;
|
| 119 |
height: 70vh;
|
| 120 |
-
|
| 121 |
border: 1px solid var(--border);
|
|
|
|
| 122 |
}
|
| 123 |
|
|
|
|
| 124 |
.message {
|
| 125 |
max-width: 72%;
|
| 126 |
padding: 12px 14px;
|
|
@@ -128,6 +123,7 @@ h1 {
|
|
| 128 |
margin-bottom: 10px;
|
| 129 |
line-height: 1.6;
|
| 130 |
font-size: 15px;
|
|
|
|
| 131 |
}
|
| 132 |
|
| 133 |
.message.user {
|
|
@@ -144,6 +140,7 @@ h1 {
|
|
| 144 |
border-bottom-left-radius: 4px;
|
| 145 |
}
|
| 146 |
|
|
|
|
| 147 |
textarea {
|
| 148 |
background: var(--surface) !important;
|
| 149 |
color: var(--text) !important;
|
|
@@ -157,6 +154,7 @@ textarea::placeholder {
|
|
| 157 |
color: var(--muted);
|
| 158 |
}
|
| 159 |
|
|
|
|
| 160 |
button {
|
| 161 |
background: var(--user) !important;
|
| 162 |
color: white !important;
|
|
@@ -168,13 +166,27 @@ button {
|
|
| 168 |
button:hover {
|
| 169 |
opacity: 0.9;
|
| 170 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
"""
|
| 172 |
|
| 173 |
# =====================================================
|
| 174 |
# Gradio UI
|
| 175 |
# =====================================================
|
| 176 |
-
with gr.Blocks(title="GROQ
|
| 177 |
-
gr.Markdown("# 🤖 GROQ
|
| 178 |
gr.Markdown(
|
| 179 |
"<div class='subtitle'>Fast, reliable AI powered by Groq & LLaMA-3.3</div>"
|
| 180 |
)
|
|
@@ -196,7 +208,7 @@ with gr.Blocks(title="GROQ AI CHATBOT") as demo:
|
|
| 196 |
clear.click(clear_chat, outputs=[chatbot, txt], show_progress=False)
|
| 197 |
|
| 198 |
# =====================================================
|
| 199 |
-
# Launch (
|
| 200 |
# =====================================================
|
| 201 |
if __name__ == "__main__":
|
| 202 |
demo.launch(css=custom_css)
|
|
|
|
| 20 |
if not user_message or not user_message.strip():
|
| 21 |
return history, ""
|
| 22 |
|
| 23 |
+
history.append({"role": "user", "content": user_message})
|
| 24 |
+
history.append({"role": "assistant", "content": "⚡ Groq is thinking..."})
|
| 25 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
messages = [
|
| 27 |
{"role": msg["role"], "content": msg["content"]}
|
| 28 |
for msg in history[:-1]
|
|
|
|
| 33 |
model="llama-3.3-70b-versatile",
|
| 34 |
messages=messages,
|
| 35 |
)
|
|
|
|
| 36 |
history[-1] = {
|
| 37 |
"role": "assistant",
|
| 38 |
"content": completion.choices[0].message.content
|
| 39 |
}
|
|
|
|
| 40 |
except Exception as e:
|
| 41 |
history[-1] = {
|
| 42 |
"role": "assistant",
|
|
|
|
| 52 |
return [], ""
|
| 53 |
|
| 54 |
# =====================================================
|
| 55 |
+
# CSS (Light/Dark + Gradio 6 UI FIX)
|
| 56 |
# =====================================================
|
| 57 |
custom_css = """
|
| 58 |
+
/* ---------- Color System ---------- */
|
| 59 |
:root {
|
| 60 |
--bg: #f9fafb;
|
| 61 |
--surface: #ffffff;
|
|
|
|
| 77 |
}
|
| 78 |
}
|
| 79 |
|
| 80 |
+
/* ---------- Base Layout ---------- */
|
| 81 |
body {
|
| 82 |
background-color: var(--bg);
|
| 83 |
}
|
|
|
|
| 86 |
max-width: 1100px !important;
|
| 87 |
margin: auto;
|
| 88 |
padding: 24px;
|
| 89 |
+
overflow-x: hidden !important;
|
| 90 |
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
| 91 |
}
|
| 92 |
|
| 93 |
+
/* ---------- Typography ---------- */
|
| 94 |
h1 {
|
| 95 |
color: var(--text);
|
| 96 |
text-align: center;
|
|
|
|
| 104 |
margin-bottom: 20px;
|
| 105 |
}
|
| 106 |
|
| 107 |
+
/* ---------- Chatbot ---------- */
|
| 108 |
.chatbot {
|
| 109 |
background: var(--surface);
|
| 110 |
border-radius: 16px;
|
| 111 |
padding: 16px;
|
| 112 |
height: 70vh;
|
| 113 |
+
width: 100% !important;
|
| 114 |
border: 1px solid var(--border);
|
| 115 |
+
overflow-y: auto;
|
| 116 |
}
|
| 117 |
|
| 118 |
+
/* ---------- Messages ---------- */
|
| 119 |
.message {
|
| 120 |
max-width: 72%;
|
| 121 |
padding: 12px 14px;
|
|
|
|
| 123 |
margin-bottom: 10px;
|
| 124 |
line-height: 1.6;
|
| 125 |
font-size: 15px;
|
| 126 |
+
box-sizing: border-box;
|
| 127 |
}
|
| 128 |
|
| 129 |
.message.user {
|
|
|
|
| 140 |
border-bottom-left-radius: 4px;
|
| 141 |
}
|
| 142 |
|
| 143 |
+
/* ---------- Input ---------- */
|
| 144 |
textarea {
|
| 145 |
background: var(--surface) !important;
|
| 146 |
color: var(--text) !important;
|
|
|
|
| 154 |
color: var(--muted);
|
| 155 |
}
|
| 156 |
|
| 157 |
+
/* ---------- Buttons ---------- */
|
| 158 |
button {
|
| 159 |
background: var(--user) !important;
|
| 160 |
color: white !important;
|
|
|
|
| 166 |
button:hover {
|
| 167 |
opacity: 0.9;
|
| 168 |
}
|
| 169 |
+
|
| 170 |
+
/* ---------- GRADIO 6 FIXES ---------- */
|
| 171 |
+
.chatbot-toolbar,
|
| 172 |
+
.chatbot-actions,
|
| 173 |
+
button[aria-label="Copy"],
|
| 174 |
+
button[aria-label="Share"],
|
| 175 |
+
button[aria-label="Clear"] {
|
| 176 |
+
display: none !important;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.chatbot .scroll-to-bottom {
|
| 180 |
+
right: 16px !important;
|
| 181 |
+
bottom: 80px !important;
|
| 182 |
+
}
|
| 183 |
"""
|
| 184 |
|
| 185 |
# =====================================================
|
| 186 |
# Gradio UI
|
| 187 |
# =====================================================
|
| 188 |
+
with gr.Blocks(title="GROQ CHATBOT") as demo:
|
| 189 |
+
gr.Markdown("# 🤖 GROQ CHATBOT")
|
| 190 |
gr.Markdown(
|
| 191 |
"<div class='subtitle'>Fast, reliable AI powered by Groq & LLaMA-3.3</div>"
|
| 192 |
)
|
|
|
|
| 208 |
clear.click(clear_chat, outputs=[chatbot, txt], show_progress=False)
|
| 209 |
|
| 210 |
# =====================================================
|
| 211 |
+
# Launch (Gradio 6)
|
| 212 |
# =====================================================
|
| 213 |
if __name__ == "__main__":
|
| 214 |
demo.launch(css=custom_css)
|