Wfafa commited on
Commit
dc70d7b
·
verified ·
1 Parent(s): 83b8cac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -52
app.py CHANGED
@@ -115,11 +115,7 @@ def clear_memory():
115
  os.remove(MEMORY_FILE)
116
  return [], "🧹 Chat memory cleared! Start fresh."
117
 
118
- # Toggle sidebar visibility
119
- def toggle_sidebar():
120
- return gr.update(visible=True) if not gr.get_state("sidebar_visible") else gr.update(visible=False)
121
-
122
- # 🖌 Custom CSS for full-screen, immersive UI with overlay sidebar
123
  custom_css = """
124
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');
125
 
@@ -127,8 +123,8 @@ body {
127
  font-family: 'Inter', sans-serif;
128
  margin: 0;
129
  padding: 0;
130
- background: linear-gradient(135deg, #0f0f0f 0%, #1a1a1a 100%);
131
- color: #e0e0e0;
132
  height: 100vh;
133
  overflow: hidden;
134
  }
@@ -142,33 +138,37 @@ body {
142
  top: 0;
143
  left: 0;
144
  right: 0;
145
- background: rgba(15, 15, 15, 0.9);
146
  backdrop-filter: blur(10px);
147
  padding: 15px 20px;
148
  display: flex;
149
  justify-content: space-between;
150
  align-items: center;
151
  z-index: 1000;
152
- border-bottom: 1px solid #333;
 
153
  }
154
  .header-title {
155
  font-size: 24px;
156
  font-weight: 600;
157
- color: #007BFF;
158
- text-shadow: 0 0 10px rgba(0, 123, 255, 0.5);
159
  }
160
  .toggle-btn {
161
- background: #007BFF;
162
  color: white;
163
  border: none;
164
  border-radius: 8px;
165
  padding: 10px;
166
  cursor: pointer;
167
  font-size: 18px;
168
- transition: background 0.3s;
 
169
  }
170
  .toggle-btn:hover {
171
- background: #0056b3;
 
 
172
  }
173
  .sidebar {
174
  position: fixed;
@@ -176,12 +176,12 @@ body {
176
  left: 0;
177
  width: 300px;
178
  height: calc(100vh - 70px);
179
- background: rgba(26, 26, 26, 0.95);
180
  backdrop-filter: blur(15px);
181
  padding: 20px;
182
  border-radius: 0 12px 12px 0;
183
- box-shadow: 4px 0 12px rgba(0,0,0,0.5);
184
- border: 1px solid #333;
185
  border-left: none;
186
  z-index: 999;
187
  transform: translateX(-100%);
@@ -194,25 +194,27 @@ body {
194
  font-size: 18px;
195
  font-weight: 500;
196
  margin-bottom: 15px;
197
- color: #007BFF;
198
  }
199
  .accordion {
200
  border-radius: 10px;
201
  margin-bottom: 10px;
202
- box-shadow: 0 2px 6px rgba(0,0,0,0.3);
203
  }
204
  .accordion-header {
205
- background: #2a2a2a;
206
- color: #e0e0e0;
207
  border-radius: 10px;
208
  padding: 12px;
209
  font-weight: 500;
210
  cursor: pointer;
211
- transition: background 0.3s;
212
  }
213
  .accordion-header:hover {
214
- background: #007BFF;
215
- color: #0f0f0f;
 
 
216
  }
217
  .main-chat {
218
  position: fixed;
@@ -227,21 +229,21 @@ body {
227
  z-index: 1;
228
  }
229
  .context-box {
230
- background: rgba(26, 26, 26, 0.9);
231
  padding: 15px;
232
  border-radius: 10px;
233
- box-shadow: 0 2px 6px rgba(0,0,0,0.3);
234
  margin-bottom: 15px;
235
- border: 1px solid #333;
236
- color: #e0e0e0;
237
  font-size: 14px;
238
  }
239
  .chatbox {
240
  flex: 1;
241
  border-radius: 10px;
242
- box-shadow: 0 2px 6px rgba(0,0,0,0.3);
243
- background: rgba(26, 26, 26, 0.9);
244
- border: 1px solid #333;
245
  padding: 15px;
246
  overflow-y: auto;
247
  }
@@ -265,7 +267,7 @@ body {
265
  height: 40px;
266
  border-radius: 50%;
267
  margin: 0 10px;
268
- background: #007BFF;
269
  display: flex;
270
  align-items: center;
271
  justify-content: center;
@@ -274,7 +276,8 @@ body {
274
  font-size: 16px;
275
  }
276
  .message.ai .avatar {
277
- background: #333;
 
278
  }
279
  .message .bubble {
280
  max-width: 70%;
@@ -283,13 +286,13 @@ body {
283
  position: relative;
284
  }
285
  .message.user .bubble {
286
- background: #007BFF;
287
  color: white;
288
  }
289
  .message.ai .bubble {
290
- background: #2a2a2a;
291
- color: #e0e0e0;
292
- border: 1px solid #333;
293
  }
294
  .timestamp {
295
  font-size: 10px;
@@ -300,7 +303,7 @@ body {
300
  .typing {
301
  display: none;
302
  font-style: italic;
303
- color: #aaa;
304
  padding: 10px;
305
  animation: pulse 1.5s infinite;
306
  }
@@ -315,43 +318,55 @@ body {
315
  width: 100%;
316
  border-radius: 20px;
317
  padding: 12px 16px;
318
- border: 1px solid #555;
319
- background: rgba(26, 26, 26, 0.9);
320
- color: #e0e0e0;
321
- transition: border-color 0.3s;
322
  font-size: 14px;
323
  }
324
  .chat-input:focus {
325
- border-color: #007BFF;
326
  outline: none;
 
327
  }
328
  .btn-clear {
329
- background: #f44336;
330
  color: white;
331
  border-radius: 10px;
332
  padding: 10px 15px;
333
  border: none;
334
  font-weight: 500;
335
  cursor: pointer;
336
- transition: background 0.3s;
 
337
  }
338
  .btn-clear:hover {
339
- background: #d32f2f;
 
 
340
  }
341
  .about-text {
342
  font-size: 14px;
343
- color: #aaa;
344
  line-height: 1.5;
345
  }
346
  .radio {
347
  margin: 10px 0;
348
  }
349
  .radio label {
350
- color: #e0e0e0;
 
 
 
 
 
 
 
 
351
  }
352
  """
353
 
354
- # 🎨 Gradio Interface with full-screen, immersive layout
355
  with gr.Blocks(theme=gr.themes.Base(), css=custom_css) as iface:
356
  with gr.Row(elem_classes="header"):
357
  gr.Markdown("# 🤖 **EduAI**", elem_classes="header-title")
@@ -411,9 +426,6 @@ with gr.Blocks(theme=gr.themes.Base(), css=custom_css) as iface:
411
  msg = gr.Textbox(placeholder="Message EduAI...", elem_classes="chat-input", show_label=False)
412
 
413
  # Event Handlers
414
- def toggle_sidebar_visibility():
415
- return gr.update(visible=True) if sidebar.visible else gr.update(visible=False)
416
-
417
  toggle_btn.click(lambda: gr.update(visible=not sidebar.visible), outputs=sidebar)
418
 
419
  subj.change(update_context, inputs=subj, outputs=context_display)
 
115
  os.remove(MEMORY_FILE)
116
  return [], "🧹 Chat memory cleared! Start fresh."
117
 
118
+ # 🖌 Custom CSS for light theme, full-screen, responsive, cyan buttons with animations
 
 
 
 
119
  custom_css = """
120
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');
121
 
 
123
  font-family: 'Inter', sans-serif;
124
  margin: 0;
125
  padding: 0;
126
+ background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
127
+ color: #334155;
128
  height: 100vh;
129
  overflow: hidden;
130
  }
 
138
  top: 0;
139
  left: 0;
140
  right: 0;
141
+ background: rgba(255, 255, 255, 0.95);
142
  backdrop-filter: blur(10px);
143
  padding: 15px 20px;
144
  display: flex;
145
  justify-content: space-between;
146
  align-items: center;
147
  z-index: 1000;
148
+ border-bottom: 1px solid #e2e8f0;
149
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
150
  }
151
  .header-title {
152
  font-size: 24px;
153
  font-weight: 600;
154
+ color: #00BCD4;
155
+ text-shadow: 0 0 10px rgba(0, 188, 212, 0.3);
156
  }
157
  .toggle-btn {
158
+ background: #00BCD4;
159
  color: white;
160
  border: none;
161
  border-radius: 8px;
162
  padding: 10px;
163
  cursor: pointer;
164
  font-size: 18px;
165
+ transition: all 0.3s ease;
166
+ box-shadow: 0 2px 6px rgba(0, 188, 212, 0.3);
167
  }
168
  .toggle-btn:hover {
169
+ background: #0097a7;
170
+ transform: scale(1.1);
171
+ box-shadow: 0 4px 12px rgba(0, 188, 212, 0.4);
172
  }
173
  .sidebar {
174
  position: fixed;
 
176
  left: 0;
177
  width: 300px;
178
  height: calc(100vh - 70px);
179
+ background: rgba(255, 255, 255, 0.95);
180
  backdrop-filter: blur(15px);
181
  padding: 20px;
182
  border-radius: 0 12px 12px 0;
183
+ box-shadow: 4px 0 12px rgba(0,0,0,0.1);
184
+ border: 1px solid #e2e8f0;
185
  border-left: none;
186
  z-index: 999;
187
  transform: translateX(-100%);
 
194
  font-size: 18px;
195
  font-weight: 500;
196
  margin-bottom: 15px;
197
+ color: #00BCD4;
198
  }
199
  .accordion {
200
  border-radius: 10px;
201
  margin-bottom: 10px;
202
+ box-shadow: 0 2px 6px rgba(0,0,0,0.1);
203
  }
204
  .accordion-header {
205
+ background: #f1f5f9;
206
+ color: #334155;
207
  border-radius: 10px;
208
  padding: 12px;
209
  font-weight: 500;
210
  cursor: pointer;
211
+ transition: all 0.3s ease;
212
  }
213
  .accordion-header:hover {
214
+ background: #00BCD4;
215
+ color: white;
216
+ transform: translateY(-2px);
217
+ box-shadow: 0 4px 12px rgba(0, 188, 212, 0.3);
218
  }
219
  .main-chat {
220
  position: fixed;
 
229
  z-index: 1;
230
  }
231
  .context-box {
232
+ background: rgba(255, 255, 255, 0.9);
233
  padding: 15px;
234
  border-radius: 10px;
235
+ box-shadow: 0 2px 6px rgba(0,0,0,0.1);
236
  margin-bottom: 15px;
237
+ border: 1px solid #e2e8f0;
238
+ color: #334155;
239
  font-size: 14px;
240
  }
241
  .chatbox {
242
  flex: 1;
243
  border-radius: 10px;
244
+ box-shadow: 0 2px 6px rgba(0,0,0,0.1);
245
+ background: rgba(255, 255, 255, 0.9);
246
+ border: 1px solid #e2e8f0;
247
  padding: 15px;
248
  overflow-y: auto;
249
  }
 
267
  height: 40px;
268
  border-radius: 50%;
269
  margin: 0 10px;
270
+ background: #00BCD4;
271
  display: flex;
272
  align-items: center;
273
  justify-content: center;
 
276
  font-size: 16px;
277
  }
278
  .message.ai .avatar {
279
+ background: #e2e8f0;
280
+ color: #334155;
281
  }
282
  .message .bubble {
283
  max-width: 70%;
 
286
  position: relative;
287
  }
288
  .message.user .bubble {
289
+ background: #00BCD4;
290
  color: white;
291
  }
292
  .message.ai .bubble {
293
+ background: #f8fafc;
294
+ color: #334155;
295
+ border: 1px solid #e2e8f0;
296
  }
297
  .timestamp {
298
  font-size: 10px;
 
303
  .typing {
304
  display: none;
305
  font-style: italic;
306
+ color: #64748b;
307
  padding: 10px;
308
  animation: pulse 1.5s infinite;
309
  }
 
318
  width: 100%;
319
  border-radius: 20px;
320
  padding: 12px 16px;
321
+ border: 1px solid #cbd5e1;
322
+ background: rgba(255, 255, 255, 0.9);
323
+ color: #334155;
324
+ transition: all 0.3s ease;
325
  font-size: 14px;
326
  }
327
  .chat-input:focus {
328
+ border-color: #00BCD4;
329
  outline: none;
330
+ box-shadow: 0 0 0 2px rgba(0, 188, 212, 0.2);
331
  }
332
  .btn-clear {
333
+ background: #00BCD4;
334
  color: white;
335
  border-radius: 10px;
336
  padding: 10px 15px;
337
  border: none;
338
  font-weight: 500;
339
  cursor: pointer;
340
+ transition: all 0.3s ease;
341
+ box-shadow: 0 2px 6px rgba(0, 188, 212, 0.3);
342
  }
343
  .btn-clear:hover {
344
+ background: #0097a7;
345
+ transform: scale(1.05);
346
+ box-shadow: 0 4px 12px rgba(0, 188, 212, 0.4);
347
  }
348
  .about-text {
349
  font-size: 14px;
350
+ color: #64748b;
351
  line-height: 1.5;
352
  }
353
  .radio {
354
  margin: 10px 0;
355
  }
356
  .radio label {
357
+ color: #334155;
358
+ }
359
+ @media (max-width: 768px) {
360
+ .sidebar {
361
+ width: 250px;
362
+ }
363
+ .header-title {
364
+ font-size: 20px;
365
+ }
366
  }
367
  """
368
 
369
+ # 🎨 Gradio Interface with light theme, full-screen, responsive, cyan buttons with animations
370
  with gr.Blocks(theme=gr.themes.Base(), css=custom_css) as iface:
371
  with gr.Row(elem_classes="header"):
372
  gr.Markdown("# 🤖 **EduAI**", elem_classes="header-title")
 
426
  msg = gr.Textbox(placeholder="Message EduAI...", elem_classes="chat-input", show_label=False)
427
 
428
  # Event Handlers
 
 
 
429
  toggle_btn.click(lambda: gr.update(visible=not sidebar.visible), outputs=sidebar)
430
 
431
  subj.change(update_context, inputs=subj, outputs=context_display)