Wfafa commited on
Commit
23be795
Β·
verified Β·
1 Parent(s): 3648623

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -122
app.py CHANGED
@@ -113,16 +113,16 @@ def clear_memory():
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 {
@@ -130,178 +130,150 @@ body {
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,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 (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,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=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)
 
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)