Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -156,6 +156,7 @@ custom_css = """
|
|
| 156 |
/* Main container and background */
|
| 157 |
.gradio-container {
|
| 158 |
background-color: rgb(240, 236, 230) !important;
|
|
|
|
| 159 |
}
|
| 160 |
|
| 161 |
/* Centered chat interface */
|
|
@@ -181,73 +182,128 @@ custom_css = """
|
|
| 181 |
.gradio-chatbot {
|
| 182 |
flex: 1;
|
| 183 |
overflow-y: auto;
|
|
|
|
|
|
|
| 184 |
}
|
| 185 |
|
| 186 |
-
/*
|
| 187 |
-
.gradio-chatbot .message {
|
| 188 |
-
|
| 189 |
-
padding: 12px !important;
|
| 190 |
-
color: black !important;
|
| 191 |
-
box-shadow: 0 1px 2px rgba(0,0,0,0.05) !important;
|
| 192 |
}
|
| 193 |
|
| 194 |
-
/*
|
| 195 |
-
.gradio-chatbot .message.bot {
|
| 196 |
background-color: rgb(240, 185, 103) !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
}
|
| 198 |
|
| 199 |
-
/* User
|
| 200 |
-
.gradio-chatbot .message.user {
|
| 201 |
background-color: rgb(242, 238, 233) !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
}
|
| 203 |
|
| 204 |
-
/* Hide
|
| 205 |
.gradio-chatbot .avatar-container {
|
| 206 |
display: none !important;
|
| 207 |
}
|
| 208 |
|
| 209 |
/* Input textbox styling */
|
| 210 |
-
.
|
| 211 |
background-color: rgb(242, 238, 233) !important;
|
| 212 |
border: 2px solid rgb(28, 18, 5) !important;
|
| 213 |
border-radius: 20px !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
color: black !important;
|
| 215 |
padding: 15px !important;
|
| 216 |
font-size: 16px !important;
|
| 217 |
box-shadow: none !important;
|
|
|
|
| 218 |
}
|
| 219 |
|
| 220 |
-
|
| 221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
display: none !important;
|
| 223 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
"""
|
| 225 |
|
| 226 |
-
with gr.Blocks(css=custom_css) as demo:
|
| 227 |
with gr.Column(elem_classes=["chat-container"]):
|
| 228 |
# Model Name in the top-left corner
|
| 229 |
gr.HTML('<div class="model-name">🎓 EduBot</div>')
|
| 230 |
|
| 231 |
# The main chatbot interface
|
| 232 |
chatbot = gr.Chatbot(
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
|
|
|
| 237 |
)
|
| 238 |
|
| 239 |
# The user input textbox
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
|
|
|
|
|
|
|
|
|
| 246 |
|
| 247 |
def respond_and_update(message, history):
|
| 248 |
"""Main function to handle user submission."""
|
|
|
|
|
|
|
|
|
|
| 249 |
# Add user message to history
|
| 250 |
-
history.append(
|
| 251 |
# Yield history to show the user message immediately, and clear the textbox
|
| 252 |
yield history, ""
|
| 253 |
|
|
@@ -255,11 +311,22 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 255 |
full_response = ""
|
| 256 |
for response_chunk in respond_with_enhanced_streaming(message, history):
|
| 257 |
full_response = response_chunk
|
| 258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
yield history, ""
|
| 260 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
# Set up the "send on Enter" event
|
| 262 |
msg.submit(respond_and_update, [msg, chatbot], [chatbot, msg])
|
|
|
|
|
|
|
|
|
|
| 263 |
|
| 264 |
if __name__ == "__main__":
|
| 265 |
logger.info("Starting EduBot...")
|
|
|
|
| 156 |
/* Main container and background */
|
| 157 |
.gradio-container {
|
| 158 |
background-color: rgb(240, 236, 230) !important;
|
| 159 |
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
| 160 |
}
|
| 161 |
|
| 162 |
/* Centered chat interface */
|
|
|
|
| 182 |
.gradio-chatbot {
|
| 183 |
flex: 1;
|
| 184 |
overflow-y: auto;
|
| 185 |
+
border: none !important;
|
| 186 |
+
background-color: transparent !important;
|
| 187 |
}
|
| 188 |
|
| 189 |
+
/* Message container styling */
|
| 190 |
+
.gradio-chatbot .message-wrap {
|
| 191 |
+
margin: 0.5rem 0 !important;
|
|
|
|
|
|
|
|
|
|
| 192 |
}
|
| 193 |
|
| 194 |
+
/* Bot message styling */
|
| 195 |
+
.gradio-chatbot .message.bot .markdown {
|
| 196 |
background-color: rgb(240, 185, 103) !important;
|
| 197 |
+
color: black !important;
|
| 198 |
+
border-radius: 18px !important;
|
| 199 |
+
padding: 12px 16px !important;
|
| 200 |
+
box-shadow: 0 1px 2px rgba(0,0,0,0.05) !important;
|
| 201 |
+
border: none !important;
|
| 202 |
+
max-width: 80%;
|
| 203 |
+
margin-left: 0;
|
| 204 |
+
margin-right: auto;
|
| 205 |
}
|
| 206 |
|
| 207 |
+
/* User message styling */
|
| 208 |
+
.gradio-chatbot .message.user .markdown {
|
| 209 |
background-color: rgb(242, 238, 233) !important;
|
| 210 |
+
color: black !important;
|
| 211 |
+
border-radius: 18px !important;
|
| 212 |
+
padding: 12px 16px !important;
|
| 213 |
+
box-shadow: 0 1px 2px rgba(0,0,0,0.05) !important;
|
| 214 |
+
border: none !important;
|
| 215 |
+
max-width: 80%;
|
| 216 |
+
margin-left: auto;
|
| 217 |
+
margin-right: 0;
|
| 218 |
}
|
| 219 |
|
| 220 |
+
/* Hide avatars */
|
| 221 |
.gradio-chatbot .avatar-container {
|
| 222 |
display: none !important;
|
| 223 |
}
|
| 224 |
|
| 225 |
/* Input textbox styling */
|
| 226 |
+
.input-container .wrap {
|
| 227 |
background-color: rgb(242, 238, 233) !important;
|
| 228 |
border: 2px solid rgb(28, 18, 5) !important;
|
| 229 |
border-radius: 20px !important;
|
| 230 |
+
box-shadow: none !important;
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
.input-container textarea {
|
| 234 |
+
background-color: transparent !important;
|
| 235 |
+
border: none !important;
|
| 236 |
color: black !important;
|
| 237 |
padding: 15px !important;
|
| 238 |
font-size: 16px !important;
|
| 239 |
box-shadow: none !important;
|
| 240 |
+
outline: none !important;
|
| 241 |
}
|
| 242 |
|
| 243 |
+
.input-container textarea:focus {
|
| 244 |
+
border: none !important;
|
| 245 |
+
box-shadow: none !important;
|
| 246 |
+
outline: none !important;
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
/* Hide the label */
|
| 250 |
+
.input-container label {
|
| 251 |
display: none !important;
|
| 252 |
}
|
| 253 |
+
|
| 254 |
+
/* Remove any default margins/padding */
|
| 255 |
+
.input-container {
|
| 256 |
+
margin-top: 1rem;
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
/* Clear button styling */
|
| 260 |
+
.clear-btn {
|
| 261 |
+
background-color: rgb(28, 18, 5) !important;
|
| 262 |
+
color: white !important;
|
| 263 |
+
border: none !important;
|
| 264 |
+
border-radius: 10px !important;
|
| 265 |
+
padding: 8px 16px !important;
|
| 266 |
+
margin-top: 0.5rem;
|
| 267 |
+
cursor: pointer;
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
.clear-btn:hover {
|
| 271 |
+
background-color: rgba(28, 18, 5, 0.8) !important;
|
| 272 |
+
}
|
| 273 |
"""
|
| 274 |
|
| 275 |
+
with gr.Blocks(css=custom_css, title="EduBot") as demo:
|
| 276 |
with gr.Column(elem_classes=["chat-container"]):
|
| 277 |
# Model Name in the top-left corner
|
| 278 |
gr.HTML('<div class="model-name">🎓 EduBot</div>')
|
| 279 |
|
| 280 |
# The main chatbot interface
|
| 281 |
chatbot = gr.Chatbot(
|
| 282 |
+
type="messages",
|
| 283 |
+
height=500,
|
| 284 |
+
show_copy_button=False,
|
| 285 |
+
show_share_button=False,
|
| 286 |
+
avatar_images=None
|
| 287 |
)
|
| 288 |
|
| 289 |
# The user input textbox
|
| 290 |
+
with gr.Row():
|
| 291 |
+
msg = gr.Textbox(
|
| 292 |
+
placeholder="Ask me about math, research, study strategies, or any educational topic...",
|
| 293 |
+
show_label=False,
|
| 294 |
+
lines=2,
|
| 295 |
+
elem_classes=["input-container"],
|
| 296 |
+
scale=4
|
| 297 |
+
)
|
| 298 |
+
clear = gr.Button("Clear", elem_classes=["clear-btn"], scale=1)
|
| 299 |
|
| 300 |
def respond_and_update(message, history):
|
| 301 |
"""Main function to handle user submission."""
|
| 302 |
+
if not message.strip():
|
| 303 |
+
return history, ""
|
| 304 |
+
|
| 305 |
# Add user message to history
|
| 306 |
+
history.append({"role": "user", "content": message})
|
| 307 |
# Yield history to show the user message immediately, and clear the textbox
|
| 308 |
yield history, ""
|
| 309 |
|
|
|
|
| 311 |
full_response = ""
|
| 312 |
for response_chunk in respond_with_enhanced_streaming(message, history):
|
| 313 |
full_response = response_chunk
|
| 314 |
+
# Update the last message (bot's response)
|
| 315 |
+
if len(history) > 0 and history[-1]["role"] == "user":
|
| 316 |
+
history.append({"role": "assistant", "content": full_response})
|
| 317 |
+
else:
|
| 318 |
+
history[-1] = {"role": "assistant", "content": full_response}
|
| 319 |
yield history, ""
|
| 320 |
|
| 321 |
+
def clear_chat():
|
| 322 |
+
"""Clear the chat history."""
|
| 323 |
+
return [], ""
|
| 324 |
+
|
| 325 |
# Set up the "send on Enter" event
|
| 326 |
msg.submit(respond_and_update, [msg, chatbot], [chatbot, msg])
|
| 327 |
+
|
| 328 |
+
# Set up the clear button
|
| 329 |
+
clear.click(clear_chat, outputs=[chatbot, msg])
|
| 330 |
|
| 331 |
if __name__ == "__main__":
|
| 332 |
logger.info("Starting EduBot...")
|