Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -113,16 +113,16 @@ def clear_memory():
|
|
| 113 |
os.remove(MEMORY_FILE)
|
| 114 |
return [], "π§Ή Chat memory cleared! Start fresh."
|
| 115 |
|
| 116 |
-
# π
|
| 117 |
custom_css = """
|
| 118 |
-
@import url('https://fonts.googleapis.com/css2?family=
|
| 119 |
|
| 120 |
body {
|
| 121 |
-
font-family: '
|
| 122 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 123 |
-
color: #ffffff;
|
| 124 |
margin: 0;
|
| 125 |
padding: 0;
|
|
|
|
|
|
|
| 126 |
min-height: 100vh;
|
| 127 |
}
|
| 128 |
.gradio-container {
|
|
@@ -130,178 +130,150 @@ body {
|
|
| 130 |
box-shadow: none;
|
| 131 |
}
|
| 132 |
.header-title {
|
| 133 |
-
font-size:
|
| 134 |
text-align: center;
|
| 135 |
-
margin-bottom:
|
| 136 |
-
font-weight:
|
| 137 |
-
color: #
|
| 138 |
-
text-shadow: 0
|
| 139 |
-
letter-spacing: -1px;
|
| 140 |
}
|
| 141 |
.sidebar {
|
| 142 |
-
background:
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
border: 1px solid rgba(255,255,255,0.2);
|
| 148 |
-
margin-right: 20px;
|
| 149 |
}
|
| 150 |
.menu-title {
|
| 151 |
-
font-size:
|
| 152 |
-
font-weight:
|
| 153 |
-
margin-bottom:
|
| 154 |
-
color: #
|
| 155 |
-
text-align: center;
|
| 156 |
}
|
| 157 |
.accordion {
|
| 158 |
-
border-radius:
|
| 159 |
-
margin-bottom:
|
| 160 |
-
|
| 161 |
-
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
| 162 |
}
|
| 163 |
.accordion-header {
|
| 164 |
-
background:
|
| 165 |
-
color:
|
| 166 |
-
border-radius:
|
| 167 |
-
padding:
|
| 168 |
font-weight: 500;
|
| 169 |
cursor: pointer;
|
| 170 |
-
transition:
|
| 171 |
-
text-align: center;
|
| 172 |
}
|
| 173 |
.accordion-header:hover {
|
| 174 |
-
background:
|
| 175 |
-
|
| 176 |
-
box-shadow: 0 6px 20px rgba(245, 87, 108, 0.4);
|
| 177 |
}
|
| 178 |
.main-chat {
|
| 179 |
-
padding:
|
| 180 |
-
background:
|
| 181 |
-
backdrop-filter: blur(15px);
|
| 182 |
-
border-radius: 20px;
|
| 183 |
-
box-shadow: 0 8px 32px rgba(0,0,0,0.2);
|
| 184 |
-
border: 1px solid rgba(255,255,255,0.2);
|
| 185 |
}
|
| 186 |
.context-box {
|
| 187 |
-
background:
|
| 188 |
-
padding:
|
| 189 |
-
border-radius:
|
| 190 |
-
box-shadow: 0
|
| 191 |
-
margin-bottom:
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
text-align: center;
|
| 195 |
}
|
| 196 |
.chatbox {
|
| 197 |
-
border-radius:
|
| 198 |
-
box-shadow: 0
|
| 199 |
-
background: #
|
| 200 |
-
|
| 201 |
}
|
| 202 |
.chatbox .message.user {
|
| 203 |
-
background:
|
| 204 |
-
color:
|
| 205 |
-
border-radius:
|
| 206 |
-
padding: 15px
|
| 207 |
-
margin:
|
| 208 |
-
box-shadow: 0
|
| 209 |
-
animation: slideIn 0.5s ease-in;
|
| 210 |
-
font-weight: 400;
|
| 211 |
}
|
| 212 |
.chatbox .message.bot {
|
| 213 |
-
background:
|
| 214 |
-
color:
|
| 215 |
-
border-radius:
|
| 216 |
-
padding: 15px
|
| 217 |
-
margin:
|
| 218 |
-
box-shadow: 0
|
| 219 |
-
animation: slideIn 0.5s ease-in;
|
| 220 |
-
font-weight: 400;
|
| 221 |
-
}
|
| 222 |
-
@keyframes slideIn {
|
| 223 |
-
from { opacity: 0; transform: translateX(-20px); }
|
| 224 |
-
to { opacity: 1; transform: translateX(0); }
|
| 225 |
}
|
| 226 |
.chat-input {
|
| 227 |
-
border-radius:
|
| 228 |
-
padding:
|
| 229 |
width: 100%;
|
| 230 |
-
border:
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
}
|
| 235 |
.chat-input:focus {
|
|
|
|
| 236 |
outline: none;
|
| 237 |
-
border-color: #667eea;
|
| 238 |
-
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
|
| 239 |
}
|
| 240 |
.btn-send {
|
| 241 |
-
background:
|
| 242 |
-
color:
|
| 243 |
-
border-radius:
|
| 244 |
-
padding:
|
| 245 |
border: none;
|
| 246 |
-
font-weight:
|
| 247 |
-
transition: all 0.3s ease;
|
| 248 |
-
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
|
| 249 |
cursor: pointer;
|
|
|
|
| 250 |
}
|
| 251 |
.btn-send:hover {
|
| 252 |
-
|
| 253 |
-
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
|
| 254 |
}
|
| 255 |
.btn-clear {
|
| 256 |
-
background:
|
| 257 |
color: white;
|
| 258 |
-
border-radius:
|
| 259 |
-
padding: 10px
|
| 260 |
border: none;
|
| 261 |
font-weight: 500;
|
| 262 |
-
transition: all 0.3s ease;
|
| 263 |
-
box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3);
|
| 264 |
cursor: pointer;
|
|
|
|
| 265 |
}
|
| 266 |
.btn-clear:hover {
|
| 267 |
-
|
| 268 |
-
box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
|
| 269 |
}
|
| 270 |
.file-upload {
|
| 271 |
-
border: 2px dashed #
|
| 272 |
-
border-radius:
|
| 273 |
-
padding:
|
| 274 |
text-align: center;
|
| 275 |
-
background:
|
| 276 |
-
|
| 277 |
-
|
| 278 |
}
|
| 279 |
.file-upload:hover {
|
| 280 |
-
|
| 281 |
-
border-color: #764ba2;
|
| 282 |
}
|
| 283 |
.about-text {
|
| 284 |
font-size: 14px;
|
| 285 |
-
color: #
|
| 286 |
-
line-height: 1.
|
| 287 |
-
text-align: center;
|
| 288 |
}
|
| 289 |
.radio {
|
| 290 |
-
margin:
|
| 291 |
}
|
| 292 |
.radio label {
|
| 293 |
-
|
| 294 |
-
color: #333;
|
| 295 |
}
|
| 296 |
"""
|
| 297 |
|
| 298 |
-
# π¨ Gradio Interface with
|
| 299 |
-
with gr.Blocks(theme=gr.themes.
|
| 300 |
-
gr.Markdown("# π **EduAI β Your
|
| 301 |
|
| 302 |
with gr.Row():
|
| 303 |
-
# Sidebar
|
| 304 |
-
with gr.Column(scale=1, min_width=
|
| 305 |
gr.Markdown("### π§ **Main Menu**", elem_classes="menu-title")
|
| 306 |
|
| 307 |
with gr.Accordion("π Subject Tutor", open=False):
|
|
@@ -334,7 +306,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), css=custom_css) as ifac
|
|
| 334 |
Helps learners understand **Science, ICT, English, and more** in a simple, friendly way! π¬
|
| 335 |
""", elem_classes="about-text")
|
| 336 |
|
| 337 |
-
# Main Chat Area
|
| 338 |
with gr.Column(scale=4, elem_classes="main-chat"):
|
| 339 |
context_display = gr.Markdown(
|
| 340 |
"π **You are in General Mode.** Ask EduAI anything about your studies!",
|
|
@@ -343,16 +315,16 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), css=custom_css) as ifac
|
|
| 343 |
|
| 344 |
chatbot = gr.Chatbot(
|
| 345 |
label="EduAI Chat",
|
| 346 |
-
height=
|
| 347 |
render_markdown=True,
|
| 348 |
type="messages",
|
| 349 |
latex_delimiters=[{"left": "$$", "right": "$$", "display": True}, {"left": "\\[", "right": "\\]", "display": True}]
|
| 350 |
)
|
| 351 |
|
| 352 |
with gr.Row():
|
| 353 |
-
msg = gr.Textbox(label="Ask EduAI:", placeholder="Type your
|
| 354 |
-
file_input = gr.File(label="π Upload a file", file_types=[".pdf", ".docx", ".png", ".jpg"], elem_classes="file-upload")
|
| 355 |
-
send = gr.Button("Send
|
| 356 |
|
| 357 |
# Event Handlers
|
| 358 |
subj.change(update_context, inputs=subj, outputs=context_display)
|
|
|
|
| 113 |
os.remove(MEMORY_FILE)
|
| 114 |
return [], "π§Ή Chat memory cleared! Start fresh."
|
| 115 |
|
| 116 |
+
# π Custom CSS for dark theme and professional look (inspired by previous dark UI prototype)
|
| 117 |
custom_css = """
|
| 118 |
+
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;600&display=swap');
|
| 119 |
|
| 120 |
body {
|
| 121 |
+
font-family: 'Roboto', sans-serif;
|
|
|
|
|
|
|
| 122 |
margin: 0;
|
| 123 |
padding: 0;
|
| 124 |
+
background: #1e1e1e;
|
| 125 |
+
color: #e0e0e0;
|
| 126 |
min-height: 100vh;
|
| 127 |
}
|
| 128 |
.gradio-container {
|
|
|
|
| 130 |
box-shadow: none;
|
| 131 |
}
|
| 132 |
.header-title {
|
| 133 |
+
font-size: 36px;
|
| 134 |
text-align: center;
|
| 135 |
+
margin-bottom: 20px;
|
| 136 |
+
font-weight: 600;
|
| 137 |
+
color: #4CAF50;
|
| 138 |
+
text-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
|
|
|
|
| 139 |
}
|
| 140 |
.sidebar {
|
| 141 |
+
background: #2a2a2a;
|
| 142 |
+
padding: 20px;
|
| 143 |
+
border-radius: 12px;
|
| 144 |
+
box-shadow: 0 4px 12px rgba(0,0,0,0.5);
|
| 145 |
+
border: 1px solid #333;
|
|
|
|
|
|
|
| 146 |
}
|
| 147 |
.menu-title {
|
| 148 |
+
font-size: 20px;
|
| 149 |
+
font-weight: 500;
|
| 150 |
+
margin-bottom: 15px;
|
| 151 |
+
color: #4CAF50;
|
|
|
|
| 152 |
}
|
| 153 |
.accordion {
|
| 154 |
+
border-radius: 10px;
|
| 155 |
+
margin-bottom: 10px;
|
| 156 |
+
box-shadow: 0 2px 6px rgba(0,0,0,0.3);
|
|
|
|
| 157 |
}
|
| 158 |
.accordion-header {
|
| 159 |
+
background: #333;
|
| 160 |
+
color: #e0e0e0;
|
| 161 |
+
border-radius: 10px;
|
| 162 |
+
padding: 12px;
|
| 163 |
font-weight: 500;
|
| 164 |
cursor: pointer;
|
| 165 |
+
transition: background 0.3s;
|
|
|
|
| 166 |
}
|
| 167 |
.accordion-header:hover {
|
| 168 |
+
background: #4CAF50;
|
| 169 |
+
color: #1e1e1e;
|
|
|
|
| 170 |
}
|
| 171 |
.main-chat {
|
| 172 |
+
padding: 20px;
|
| 173 |
+
background: #1e1e1e;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
}
|
| 175 |
.context-box {
|
| 176 |
+
background: #2a2a2a;
|
| 177 |
+
padding: 15px;
|
| 178 |
+
border-radius: 10px;
|
| 179 |
+
box-shadow: 0 2px 6px rgba(0,0,0,0.3);
|
| 180 |
+
margin-bottom: 15px;
|
| 181 |
+
border: 1px solid #333;
|
| 182 |
+
color: #e0e0e0;
|
|
|
|
| 183 |
}
|
| 184 |
.chatbox {
|
| 185 |
+
border-radius: 10px;
|
| 186 |
+
box-shadow: 0 2px 6px rgba(0,0,0,0.3);
|
| 187 |
+
background: #252525;
|
| 188 |
+
border: 1px solid #333;
|
| 189 |
}
|
| 190 |
.chatbox .message.user {
|
| 191 |
+
background: #4CAF50;
|
| 192 |
+
color: #1e1e1e;
|
| 193 |
+
border-radius: 12px;
|
| 194 |
+
padding: 12px 15px;
|
| 195 |
+
margin: 8px 0;
|
| 196 |
+
box-shadow: 0 2px 6px rgba(76, 175, 80, 0.3);
|
|
|
|
|
|
|
| 197 |
}
|
| 198 |
.chatbox .message.bot {
|
| 199 |
+
background: #333;
|
| 200 |
+
color: #e0e0e0;
|
| 201 |
+
border-radius: 12px;
|
| 202 |
+
padding: 12px 15px;
|
| 203 |
+
margin: 8px 0;
|
| 204 |
+
box-shadow: 0 2px 6px rgba(0,0,0,0.3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
}
|
| 206 |
.chat-input {
|
| 207 |
+
border-radius: 10px;
|
| 208 |
+
padding: 12px;
|
| 209 |
width: 100%;
|
| 210 |
+
border: 1px solid #555;
|
| 211 |
+
background: #2a2a2a;
|
| 212 |
+
color: #e0e0e0;
|
| 213 |
+
transition: border-color 0.3s;
|
| 214 |
}
|
| 215 |
.chat-input:focus {
|
| 216 |
+
border-color: #4CAF50;
|
| 217 |
outline: none;
|
|
|
|
|
|
|
| 218 |
}
|
| 219 |
.btn-send {
|
| 220 |
+
background: #4CAF50;
|
| 221 |
+
color: #1e1e1e;
|
| 222 |
+
border-radius: 10px;
|
| 223 |
+
padding: 12px 20px;
|
| 224 |
border: none;
|
| 225 |
+
font-weight: 500;
|
|
|
|
|
|
|
| 226 |
cursor: pointer;
|
| 227 |
+
transition: background 0.3s;
|
| 228 |
}
|
| 229 |
.btn-send:hover {
|
| 230 |
+
background: #45a049;
|
|
|
|
| 231 |
}
|
| 232 |
.btn-clear {
|
| 233 |
+
background: #f44336;
|
| 234 |
color: white;
|
| 235 |
+
border-radius: 10px;
|
| 236 |
+
padding: 10px 15px;
|
| 237 |
border: none;
|
| 238 |
font-weight: 500;
|
|
|
|
|
|
|
| 239 |
cursor: pointer;
|
| 240 |
+
transition: background 0.3s;
|
| 241 |
}
|
| 242 |
.btn-clear:hover {
|
| 243 |
+
background: #d32f2f;
|
|
|
|
| 244 |
}
|
| 245 |
.file-upload {
|
| 246 |
+
border: 2px dashed #4CAF50;
|
| 247 |
+
border-radius: 10px;
|
| 248 |
+
padding: 15px;
|
| 249 |
text-align: center;
|
| 250 |
+
background: #2a2a2a;
|
| 251 |
+
color: #e0e0e0;
|
| 252 |
+
transition: border-color 0.3s;
|
| 253 |
}
|
| 254 |
.file-upload:hover {
|
| 255 |
+
border-color: #45a049;
|
|
|
|
| 256 |
}
|
| 257 |
.about-text {
|
| 258 |
font-size: 14px;
|
| 259 |
+
color: #aaa;
|
| 260 |
+
line-height: 1.5;
|
|
|
|
| 261 |
}
|
| 262 |
.radio {
|
| 263 |
+
margin: 10px 0;
|
| 264 |
}
|
| 265 |
.radio label {
|
| 266 |
+
color: #e0e0e0;
|
|
|
|
| 267 |
}
|
| 268 |
"""
|
| 269 |
|
| 270 |
+
# π¨ Gradio Interface with dark theme and professional styling
|
| 271 |
+
with gr.Blocks(theme=gr.themes.Base(), css=custom_css) as iface: # Using Base theme for full custom control
|
| 272 |
+
gr.Markdown("# π **EduAI β Your Professional Study Companion**", elem_classes="header-title")
|
| 273 |
|
| 274 |
with gr.Row():
|
| 275 |
+
# Sidebar
|
| 276 |
+
with gr.Column(scale=1, min_width=250, elem_classes="sidebar"):
|
| 277 |
gr.Markdown("### π§ **Main Menu**", elem_classes="menu-title")
|
| 278 |
|
| 279 |
with gr.Accordion("π Subject Tutor", open=False):
|
|
|
|
| 306 |
Helps learners understand **Science, ICT, English, and more** in a simple, friendly way! π¬
|
| 307 |
""", elem_classes="about-text")
|
| 308 |
|
| 309 |
+
# Main Chat Area
|
| 310 |
with gr.Column(scale=4, elem_classes="main-chat"):
|
| 311 |
context_display = gr.Markdown(
|
| 312 |
"π **You are in General Mode.** Ask EduAI anything about your studies!",
|
|
|
|
| 315 |
|
| 316 |
chatbot = gr.Chatbot(
|
| 317 |
label="EduAI Chat",
|
| 318 |
+
height=500,
|
| 319 |
render_markdown=True,
|
| 320 |
type="messages",
|
| 321 |
latex_delimiters=[{"left": "$$", "right": "$$", "display": True}, {"left": "\\[", "right": "\\]", "display": True}]
|
| 322 |
)
|
| 323 |
|
| 324 |
with gr.Row():
|
| 325 |
+
msg = gr.Textbox(label="Ask EduAI:", placeholder="Type your question here...", elem_classes="chat-input")
|
| 326 |
+
file_input = gr.File(label="π Upload a study file", file_types=[".pdf", ".docx", ".png", ".jpg"], elem_classes="file-upload")
|
| 327 |
+
send = gr.Button("Send βοΈ", elem_classes="btn-send")
|
| 328 |
|
| 329 |
# Event Handlers
|
| 330 |
subj.change(update_context, inputs=subj, outputs=context_display)
|