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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +189 -37
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 elegant, modern look (enhanced for sophistication)
117
  custom_css = """
118
- @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
119
-
120
- body { font-family: 'Inter', sans-serif; background: linear-gradient(135deg, #f8fafc, #e2e8f0); color: #334155; }
121
- .header-title { font-size: 32px; text-align: center; margin-bottom: 20px; font-weight: 700; color: #0f172a; letter-spacing: -0.5px; }
122
- .sidebar { background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(10px); padding: 20px; border-radius: 16px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); border: 1px solid #e2e8f0; }
123
- .menu-title { font-size: 20px; font-weight: 600; margin-bottom: 15px; color: #0f172a; }
124
- .accordion { border-radius: 12px; margin-bottom: 10px; }
125
- .accordion-header { background: #f1f5f9; border-radius: 12px; padding: 12px; font-weight: 500; transition: all 0.3s ease; }
126
- .accordion-header:hover { background: #e2e8f0; }
127
- .main-chat { padding: 20px; background: transparent; }
128
- .context-box { background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(10px); padding: 15px; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); margin-bottom: 15px; border: 1px solid #e2e8f0; font-size: 14px; }
129
- .chatbox { border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: #ffffff; }
130
- .chatbox .message.user { background: linear-gradient(135deg, #14b8a6, #06b6d4); color: white; border-radius: 16px; padding: 12px 16px; margin: 8px 0; box-shadow: 0 2px 6px rgba(20, 184, 166, 0.3); animation: fadeIn 0.5s ease-in; }
131
- .chatbox .message.bot { background: #f8fafc; color: #334155; border-radius: 16px; padding: 12px 16px; margin: 8px 0; box-shadow: 0 1px 4px rgba(0,0,0,0.05); border: 1px solid #e2e8f0; animation: fadeIn 0.5s ease-in; }
132
- @keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
133
- .chat-input { border-radius: 20px; padding: 12px 16px; width: 100%; border: 1px solid #d1d5db; transition: all 0.3s ease; }
134
- .chat-input:focus { outline: none; border-color: #14b8a6; box-shadow: 0 0 0 2px rgba(20, 184, 166, 0.2); }
135
- .btn-send { background: linear-gradient(135deg, #14b8a6, #06b6d4); color: white; border-radius: 20px; padding: 12px 24px; border: none; font-weight: 500; transition: all 0.3s ease; box-shadow: 0 2px 8px rgba(20, 184, 166, 0.3); }
136
- .btn-send:hover { transform: scale(1.05); box-shadow: 0 4px 12px rgba(20, 184, 166, 0.4); }
137
- .btn-clear { background: linear-gradient(135deg, #ef4444, #dc2626); color: white; border-radius: 12px; padding: 8px 16px; border: none; font-weight: 500; transition: all 0.3s ease; }
138
- .btn-clear:hover { transform: scale(1.05); box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4); }
139
- .file-upload { border: 2px dashed #14b8a6; border-radius: 12px; padding: 15px; text-align: center; background: #f8fafc; transition: all 0.3s ease; }
140
- .file-upload:hover { background: #e2e8f0; border-color: #06b6d4; }
141
- .about-text { font-size: 14px; color: #64748b; line-height: 1.5; }
142
- .radio { margin: 10px 0; }
143
- .radio label { font-weight: 400; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  """
145
 
146
- # 🎨 Gradio Interface with enhanced CSS and layout
147
- with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal"), css=custom_css) as iface:
148
- gr.Markdown("# πŸŽ“ **EduAI β€” Your Elegant Study Companion**", elem_classes="header-title")
149
 
150
  with gr.Row():
151
- # Sidebar (refined for elegance)
152
- with gr.Column(scale=1, min_width=280, elem_classes="sidebar"):
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 (enhanced for modern look)
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=550,
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="Share your study query...", elem_classes="chat-input")
202
- file_input = gr.File(label="πŸ“‚ Upload a study file", file_types=[".pdf", ".docx", ".png", ".jpg"], elem_classes="file-upload")
203
- send = gr.Button("Send ✈️", elem_classes="btn-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)