Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -113,43 +113,195 @@ def clear_memory():
|
|
| 113 |
os.remove(MEMORY_FILE)
|
| 114 |
return [], "π§Ή Chat memory cleared! Start fresh."
|
| 115 |
|
| 116 |
-
# π Custom CSS for
|
| 117 |
custom_css = """
|
| 118 |
-
@import url('https://fonts.googleapis.com/css2?family=
|
| 119 |
-
|
| 120 |
-
body {
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
.
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
.
|
| 142 |
-
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
"""
|
| 145 |
|
| 146 |
-
# π¨ Gradio Interface with
|
| 147 |
-
with gr.Blocks(theme=gr.themes.Soft(primary_hue="
|
| 148 |
-
gr.Markdown("# π **EduAI β Your
|
| 149 |
|
| 150 |
with gr.Row():
|
| 151 |
-
# Sidebar (
|
| 152 |
-
with gr.Column(scale=1, min_width=
|
| 153 |
gr.Markdown("### π§ **Main Menu**", elem_classes="menu-title")
|
| 154 |
|
| 155 |
with gr.Accordion("π Subject Tutor", open=False):
|
|
@@ -182,7 +334,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal"), css=custom_css) as ifac
|
|
| 182 |
Helps learners understand **Science, ICT, English, and more** in a simple, friendly way! π¬
|
| 183 |
""", elem_classes="about-text")
|
| 184 |
|
| 185 |
-
# Main Chat Area (
|
| 186 |
with gr.Column(scale=4, elem_classes="main-chat"):
|
| 187 |
context_display = gr.Markdown(
|
| 188 |
"π **You are in General Mode.** Ask EduAI anything about your studies!",
|
|
@@ -191,16 +343,16 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal"), css=custom_css) as ifac
|
|
| 191 |
|
| 192 |
chatbot = gr.Chatbot(
|
| 193 |
label="EduAI Chat",
|
| 194 |
-
height=
|
| 195 |
render_markdown=True,
|
| 196 |
type="messages",
|
| 197 |
latex_delimiters=[{"left": "$$", "right": "$$", "display": True}, {"left": "\\[", "right": "\\]", "display": True}]
|
| 198 |
)
|
| 199 |
|
| 200 |
with gr.Row():
|
| 201 |
-
msg = gr.Textbox(label="Ask EduAI:", placeholder="
|
| 202 |
-
file_input = gr.File(label="π Upload a
|
| 203 |
-
send = gr.Button("Send
|
| 204 |
|
| 205 |
# Event Handlers
|
| 206 |
subj.change(update_context, inputs=subj, outputs=context_display)
|
|
|
|
| 113 |
os.remove(MEMORY_FILE)
|
| 114 |
return [], "π§Ή Chat memory cleared! Start fresh."
|
| 115 |
|
| 116 |
+
# π Enhanced Custom CSS for a sleek, modern, and visually appealing UI
|
| 117 |
custom_css = """
|
| 118 |
+
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
|
| 119 |
+
|
| 120 |
+
body {
|
| 121 |
+
font-family: 'Poppins', sans-serif;
|
| 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 {
|
| 129 |
+
background: transparent;
|
| 130 |
+
box-shadow: none;
|
| 131 |
+
}
|
| 132 |
+
.header-title {
|
| 133 |
+
font-size: 40px;
|
| 134 |
+
text-align: center;
|
| 135 |
+
margin-bottom: 30px;
|
| 136 |
+
font-weight: 700;
|
| 137 |
+
color: #ffffff;
|
| 138 |
+
text-shadow: 0 2px 4px rgba(0,0,0,0.3);
|
| 139 |
+
letter-spacing: -1px;
|
| 140 |
+
}
|
| 141 |
+
.sidebar {
|
| 142 |
+
background: rgba(255, 255, 255, 0.95);
|
| 143 |
+
backdrop-filter: blur(15px);
|
| 144 |
+
padding: 25px;
|
| 145 |
+
border-radius: 20px;
|
| 146 |
+
box-shadow: 0 8px 32px rgba(0,0,0,0.2);
|
| 147 |
+
border: 1px solid rgba(255,255,255,0.2);
|
| 148 |
+
margin-right: 20px;
|
| 149 |
+
}
|
| 150 |
+
.menu-title {
|
| 151 |
+
font-size: 22px;
|
| 152 |
+
font-weight: 600;
|
| 153 |
+
margin-bottom: 20px;
|
| 154 |
+
color: #333;
|
| 155 |
+
text-align: center;
|
| 156 |
+
}
|
| 157 |
+
.accordion {
|
| 158 |
+
border-radius: 15px;
|
| 159 |
+
margin-bottom: 15px;
|
| 160 |
+
overflow: hidden;
|
| 161 |
+
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
| 162 |
+
}
|
| 163 |
+
.accordion-header {
|
| 164 |
+
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
| 165 |
+
color: white;
|
| 166 |
+
border-radius: 15px;
|
| 167 |
+
padding: 15px;
|
| 168 |
+
font-weight: 500;
|
| 169 |
+
cursor: pointer;
|
| 170 |
+
transition: all 0.3s ease;
|
| 171 |
+
text-align: center;
|
| 172 |
+
}
|
| 173 |
+
.accordion-header:hover {
|
| 174 |
+
background: linear-gradient(135deg, #f5576c 0%, #f093fb 100%);
|
| 175 |
+
transform: translateY(-2px);
|
| 176 |
+
box-shadow: 0 6px 20px rgba(245, 87, 108, 0.4);
|
| 177 |
+
}
|
| 178 |
+
.main-chat {
|
| 179 |
+
padding: 25px;
|
| 180 |
+
background: rgba(255, 255, 255, 0.9);
|
| 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: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
|
| 188 |
+
padding: 20px;
|
| 189 |
+
border-radius: 15px;
|
| 190 |
+
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
| 191 |
+
margin-bottom: 20px;
|
| 192 |
+
color: #333;
|
| 193 |
+
font-weight: 500;
|
| 194 |
+
text-align: center;
|
| 195 |
+
}
|
| 196 |
+
.chatbox {
|
| 197 |
+
border-radius: 15px;
|
| 198 |
+
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
| 199 |
+
background: #ffffff;
|
| 200 |
+
padding: 10px;
|
| 201 |
+
}
|
| 202 |
+
.chatbox .message.user {
|
| 203 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 204 |
+
color: white;
|
| 205 |
+
border-radius: 18px;
|
| 206 |
+
padding: 15px 20px;
|
| 207 |
+
margin: 10px 0;
|
| 208 |
+
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
|
| 209 |
+
animation: slideIn 0.5s ease-in;
|
| 210 |
+
font-weight: 400;
|
| 211 |
+
}
|
| 212 |
+
.chatbox .message.bot {
|
| 213 |
+
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
| 214 |
+
color: white;
|
| 215 |
+
border-radius: 18px;
|
| 216 |
+
padding: 15px 20px;
|
| 217 |
+
margin: 10px 0;
|
| 218 |
+
box-shadow: 0 4px 12px rgba(240, 147, 251, 0.3);
|
| 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: 25px;
|
| 228 |
+
padding: 15px 20px;
|
| 229 |
+
width: 100%;
|
| 230 |
+
border: 2px solid #ddd;
|
| 231 |
+
transition: all 0.3s ease;
|
| 232 |
+
font-size: 16px;
|
| 233 |
+
background: #ffffff;
|
| 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: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 242 |
+
color: white;
|
| 243 |
+
border-radius: 25px;
|
| 244 |
+
padding: 15px 30px;
|
| 245 |
+
border: none;
|
| 246 |
+
font-weight: 600;
|
| 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 |
+
transform: scale(1.05);
|
| 253 |
+
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
|
| 254 |
+
}
|
| 255 |
+
.btn-clear {
|
| 256 |
+
background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
|
| 257 |
+
color: white;
|
| 258 |
+
border-radius: 15px;
|
| 259 |
+
padding: 10px 20px;
|
| 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 |
+
transform: scale(1.05);
|
| 268 |
+
box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
|
| 269 |
+
}
|
| 270 |
+
.file-upload {
|
| 271 |
+
border: 2px dashed #667eea;
|
| 272 |
+
border-radius: 15px;
|
| 273 |
+
padding: 20px;
|
| 274 |
+
text-align: center;
|
| 275 |
+
background: rgba(255, 255, 255, 0.8);
|
| 276 |
+
transition: all 0.3s ease;
|
| 277 |
+
color: #333;
|
| 278 |
+
}
|
| 279 |
+
.file-upload:hover {
|
| 280 |
+
background: rgba(102, 126, 234, 0.1);
|
| 281 |
+
border-color: #764ba2;
|
| 282 |
+
}
|
| 283 |
+
.about-text {
|
| 284 |
+
font-size: 14px;
|
| 285 |
+
color: #555;
|
| 286 |
+
line-height: 1.6;
|
| 287 |
+
text-align: center;
|
| 288 |
+
}
|
| 289 |
+
.radio {
|
| 290 |
+
margin: 15px 0;
|
| 291 |
+
}
|
| 292 |
+
.radio label {
|
| 293 |
+
font-weight: 400;
|
| 294 |
+
color: #333;
|
| 295 |
+
}
|
| 296 |
"""
|
| 297 |
|
| 298 |
+
# π¨ Gradio Interface with refined UI
|
| 299 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), css=custom_css) as iface:
|
| 300 |
+
gr.Markdown("# π **EduAI β Your Sleek Study Companion**", elem_classes="header-title")
|
| 301 |
|
| 302 |
with gr.Row():
|
| 303 |
+
# Sidebar (sleek and modern)
|
| 304 |
+
with gr.Column(scale=1, min_width=300, elem_classes="sidebar"):
|
| 305 |
gr.Markdown("### π§ **Main Menu**", elem_classes="menu-title")
|
| 306 |
|
| 307 |
with gr.Accordion("π Subject Tutor", open=False):
|
|
|
|
| 334 |
Helps learners understand **Science, ICT, English, and more** in a simple, friendly way! π¬
|
| 335 |
""", elem_classes="about-text")
|
| 336 |
|
| 337 |
+
# Main Chat Area (visually appealing and modern)
|
| 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 |
|
| 344 |
chatbot = gr.Chatbot(
|
| 345 |
label="EduAI Chat",
|
| 346 |
+
height=600,
|
| 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 study question here...", elem_classes="chat-input")
|
| 354 |
+
file_input = gr.File(label="π Upload a file", file_types=[".pdf", ".docx", ".png", ".jpg"], elem_classes="file-upload")
|
| 355 |
+
send = gr.Button("Send π", elem_classes="btn-send")
|
| 356 |
|
| 357 |
# Event Handlers
|
| 358 |
subj.change(update_context, inputs=subj, outputs=context_display)
|