Wfafa commited on
Commit
83b8cac
ยท
verified ยท
1 Parent(s): 627902e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +122 -73
app.py CHANGED
@@ -43,7 +43,7 @@ def save_memory(memory):
43
 
44
  memory = load_memory()
45
 
46
- # ๐Ÿ’ฌ Chat function (removed file_input handling)
47
  def chat_with_model(message, history, context):
48
  if not isinstance(history, list):
49
  history = []
@@ -115,7 +115,11 @@ def clear_memory():
115
  os.remove(MEMORY_FILE)
116
  return [], "๐Ÿงน Chat memory cleared! Start fresh."
117
 
118
- # ๐Ÿ–Œ Custom CSS (unchanged, but input-row simplified)
 
 
 
 
119
  custom_css = """
120
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');
121
 
@@ -123,29 +127,68 @@ body {
123
  font-family: 'Inter', sans-serif;
124
  margin: 0;
125
  padding: 0;
126
- background: #0f0f0f;
127
  color: #e0e0e0;
128
- min-height: 100vh;
 
129
  }
130
  .gradio-container {
131
  background: transparent;
132
  box-shadow: none;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  }
134
  .header-title {
135
- font-size: 28px;
136
- text-align: center;
137
- margin-bottom: 20px;
138
  font-weight: 600;
139
  color: #007BFF;
140
  text-shadow: 0 0 10px rgba(0, 123, 255, 0.5);
141
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  .sidebar {
143
- background: #1a1a1a;
 
 
 
 
 
 
144
  padding: 20px;
145
- border-radius: 12px;
146
- box-shadow: 0 4px 12px rgba(0,0,0,0.5);
147
  border: 1px solid #333;
148
- width: 280px;
 
 
 
 
 
 
149
  }
150
  .menu-title {
151
  font-size: 18px;
@@ -172,14 +215,19 @@ body {
172
  color: #0f0f0f;
173
  }
174
  .main-chat {
 
 
 
 
 
175
  padding: 20px;
176
- background: #0f0f0f;
177
  display: flex;
178
  flex-direction: column;
179
- height: calc(100vh - 100px);
180
  }
181
  .context-box {
182
- background: #1a1a1a;
183
  padding: 15px;
184
  border-radius: 10px;
185
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
@@ -192,7 +240,7 @@ body {
192
  flex: 1;
193
  border-radius: 10px;
194
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
195
- background: #1a1a1a;
196
  border: 1px solid #333;
197
  padding: 15px;
198
  overflow-y: auto;
@@ -268,7 +316,7 @@ body {
268
  border-radius: 20px;
269
  padding: 12px 16px;
270
  border: 1px solid #555;
271
- background: #1a1a1a;
272
  color: #e0e0e0;
273
  transition: border-color 0.3s;
274
  font-size: 14px;
@@ -303,76 +351,77 @@ body {
303
  }
304
  """
305
 
306
- # ๐ŸŽจ Gradio Interface without file uploader
307
  with gr.Blocks(theme=gr.themes.Base(), css=custom_css) as iface:
308
- gr.Markdown("# ๐Ÿค– **EduAI**", elem_classes="header-title")
309
-
310
- with gr.Row():
311
- with gr.Column(scale=1, elem_classes="sidebar"):
312
- gr.Markdown("### ๐Ÿงญ **Menu**", elem_classes="menu-title")
313
-
314
- with gr.Accordion("๐Ÿ“š Subject Tutor", open=False):
315
- subj = gr.Radio(
316
- ["Science ๐Ÿงช", "ICT ๐Ÿ’ป", "English ๐Ÿ“˜", "Mathematics โž—"],
317
- label="Choose a subject",
318
- type="index"
319
- )
320
-
321
- with gr.Accordion("๐Ÿ—“ Study Planner", open=False):
322
- planner = gr.Radio(
323
- ["View Plan ๐Ÿ“…", "Add Task โœ๏ธ", "Study Tips ๐Ÿ’ก"],
324
- label="Planner Options",
325
- type="index"
326
- )
327
-
328
- with gr.Accordion("๐ŸŒ Languages", open=False):
329
- lang = gr.Radio(
330
- ["Learn Sinhala ๐Ÿ‡ฑ๐Ÿ‡ฐ", "Learn Tamil ๐Ÿ‡ฎ๐Ÿ‡ณ", "Learn English ๐Ÿ‡ฌ๐Ÿ‡ง", "Learn Spanish ๐Ÿ‡ช๐Ÿ‡ธ"],
331
- label="Language Options",
332
- type="index"
333
- )
334
-
335
- with gr.Accordion("โš™๏ธ Settings", open=False):
336
- clear_btn = gr.Button("๐Ÿงน Clear Memory", elem_classes="btn-clear")
337
-
338
- with gr.Accordion("๐Ÿ‘ฉโ€๐ŸŽ“ About", open=False):
339
- gr.Markdown("""
340
- EduAI โ€“ developed by **Wafa Fazly** using a pre-trained AI model.
341
- Helps learners understand **Science, ICT, English, and more** in a simple, friendly way! ๐Ÿ’ฌ
342
- """, elem_classes="about-text")
343
-
344
- with gr.Column(scale=4, elem_classes="main-chat"):
345
- context_display = gr.Markdown(
346
- "๐Ÿ“˜ **You are in General Mode.** Ask EduAI anything about your studies!",
347
- elem_classes="context-box"
348
  )
349
 
350
- chatbot = gr.Chatbot(
351
- label="",
352
- height=500,
353
- render_markdown=True,
354
- type="messages",
355
- latex_delimiters=[{"left": "$$", "right": "$$", "display": True}, {"left": "\\[", "right": "\\]", "display": True}]
356
  )
357
 
358
- typing_indicator = gr.Markdown("", elem_classes="typing")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
359
 
360
- with gr.Row(elem_classes="input-row"):
361
- msg = gr.Textbox(placeholder="Message EduAI...", elem_classes="chat-input", show_label=False)
362
 
363
- # Event Handlers with typing indicator
364
- def start_typing():
365
- return "EduAI is typing..."
366
 
367
- def stop_typing():
368
- return ""
369
 
370
  subj.change(update_context, inputs=subj, outputs=context_display)
371
  planner.change(update_context, inputs=planner, outputs=context_display)
372
  lang.change(update_context, inputs=lang, outputs=context_display)
373
- msg.submit(start_typing, outputs=typing_indicator).then(
374
  chat_with_model, inputs=[msg, chatbot, context_display], outputs=[chatbot, chatbot]
375
- ).then(stop_typing, outputs=typing_indicator)
376
  clear_btn.click(clear_memory, outputs=[chatbot, context_display])
377
 
378
  iface.launch()
 
43
 
44
  memory = load_memory()
45
 
46
+ # ๐Ÿ’ฌ Chat function (unchanged)
47
  def chat_with_model(message, history, context):
48
  if not isinstance(history, list):
49
  history = []
 
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
  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
  }
135
  .gradio-container {
136
  background: transparent;
137
  box-shadow: none;
138
+ height: 100vh;
139
+ }
140
+ .header {
141
+ position: fixed;
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;
175
+ top: 70px;
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%);
188
+ transition: transform 0.3s ease;
189
+ }
190
+ .sidebar.visible {
191
+ transform: translateX(0);
192
  }
193
  .menu-title {
194
  font-size: 18px;
 
215
  color: #0f0f0f;
216
  }
217
  .main-chat {
218
+ position: fixed;
219
+ top: 70px;
220
+ left: 0;
221
+ right: 0;
222
+ bottom: 0;
223
  padding: 20px;
224
+ background: transparent;
225
  display: flex;
226
  flex-direction: column;
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);
 
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;
 
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;
 
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")
358
+ toggle_btn = gr.Button("โ˜ฐ", elem_classes="toggle-btn")
359
+
360
+ sidebar = gr.Column(scale=1, elem_classes="sidebar", visible=False)
361
+ with sidebar:
362
+ gr.Markdown("### ๐Ÿงญ **Menu**", elem_classes="menu-title")
363
+
364
+ with gr.Accordion("๐Ÿ“š Subject Tutor", open=False):
365
+ subj = gr.Radio(
366
+ ["Science ๐Ÿงช", "ICT ๐Ÿ’ป", "English ๐Ÿ“˜", "Mathematics โž—"],
367
+ label="Choose a subject",
368
+ type="index"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
369
  )
370
 
371
+ with gr.Accordion("๐Ÿ—“ Study Planner", open=False):
372
+ planner = gr.Radio(
373
+ ["View Plan ๐Ÿ“…", "Add Task โœ๏ธ", "Study Tips ๐Ÿ’ก"],
374
+ label="Planner Options",
375
+ type="index"
 
376
  )
377
 
378
+ with gr.Accordion("๐ŸŒ Languages", open=False):
379
+ lang = gr.Radio(
380
+ ["Learn Sinhala ๐Ÿ‡ฑ๐Ÿ‡ฐ", "Learn Tamil ๐Ÿ‡ฎ๐Ÿ‡ณ", "Learn English ๐Ÿ‡ฌ๐Ÿ‡ง", "Learn Spanish ๐Ÿ‡ช๐Ÿ‡ธ"],
381
+ label="Language Options",
382
+ type="index"
383
+ )
384
+
385
+ with gr.Accordion("โš™๏ธ Settings", open=False):
386
+ clear_btn = gr.Button("๐Ÿงน Clear Memory", elem_classes="btn-clear")
387
+
388
+ with gr.Accordion("๐Ÿ‘ฉโ€๐ŸŽ“ About", open=False):
389
+ gr.Markdown("""
390
+ EduAI โ€“ developed by **Wafa Fazly** using a pre-trained AI model.
391
+ Helps learners understand **Science, ICT, English, and more** in a simple, friendly way! ๐Ÿ’ฌ
392
+ """, elem_classes="about-text")
393
+
394
+ with gr.Column(scale=4, elem_classes="main-chat"):
395
+ context_display = gr.Markdown(
396
+ "๐Ÿ“˜ **You are in General Mode.** Ask EduAI anything about your studies!",
397
+ elem_classes="context-box"
398
+ )
399
+
400
+ chatbot = gr.Chatbot(
401
+ label="",
402
+ height=500,
403
+ render_markdown=True,
404
+ type="messages",
405
+ latex_delimiters=[{"left": "$$", "right": "$$", "display": True}, {"left": "\\[", "right": "\\]", "display": True}]
406
+ )
407
+
408
+ typing_indicator = gr.Markdown("", elem_classes="typing")
409
 
410
+ with gr.Row(elem_classes="input-row"):
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)
420
  planner.change(update_context, inputs=planner, outputs=context_display)
421
  lang.change(update_context, inputs=lang, outputs=context_display)
422
+ msg.submit(lambda: "EduAI is typing...", outputs=typing_indicator).then(
423
  chat_with_model, inputs=[msg, chatbot, context_display], outputs=[chatbot, chatbot]
424
+ ).then(lambda: "", outputs=typing_indicator)
425
  clear_btn.click(clear_memory, outputs=[chatbot, context_display])
426
 
427
  iface.launch()