Shirpi commited on
Commit
33d60f5
·
verified ·
1 Parent(s): c5d0bfa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -40
app.py CHANGED
@@ -239,7 +239,7 @@ HTML_TEMPLATE = """
239
  -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain; min-height: 0;
240
  }
241
 
242
- /* --- LOCKED INTRO TEXT --- */
243
  #intro-container {
244
  position: absolute;
245
  top: 140px;
@@ -293,7 +293,9 @@ HTML_TEMPLATE = """
293
  padding-top: 150px;
294
  transition: opacity 0.5s ease; opacity: 1; pointer-events: auto;
295
  }
296
- .overlay.hidden { opacity: 0; pointer-events: none; }
 
 
297
 
298
  .login-box {
299
  width: 90%; max-width: 350px; text-align: center;
@@ -364,7 +366,7 @@ HTML_TEMPLATE = """
364
  <header>
365
  <div class="menu-btn" onclick="toggleSidebar()"><i class="fas fa-bars"></i></div>
366
  <span class="app-title">Student's AI</span>
367
- <div class="settings-icon" onclick="openSettings()"><i class="fas fa-cog"></i></div>
368
  </header>
369
 
370
  <div id="chat-box"></div>
@@ -409,15 +411,18 @@ HTML_TEMPLATE = """
409
 
410
  if (storedUser) {
411
  currentUser = storedUser;
412
- document.getElementById("login-overlay").classList.add('hidden');
 
 
413
 
414
  if (storedContext) {
415
  userContext = storedContext;
416
  document.getElementById("selection-overlay").classList.add('hidden');
417
  showApp();
418
  } else {
419
- // User exists but context missing (New Feature)
420
- document.getElementById("selection-overlay").classList.remove('hidden');
 
421
  updateEduOptions();
422
  }
423
  }
@@ -430,9 +435,15 @@ HTML_TEMPLATE = """
430
  if(name) {
431
  try { localStorage.setItem("student_ai_user", name); } catch(e){}
432
  currentUser = name;
433
- // Hide Login -> Show Selection
434
- document.getElementById("login-overlay").classList.add('hidden');
435
- document.getElementById("selection-overlay").classList.remove('hidden');
 
 
 
 
 
 
436
  updateEduOptions();
437
  } else {
438
  input.style.border = "1px solid red";
@@ -464,7 +475,6 @@ HTML_TEMPLATE = """
464
  const year = document.getElementById('edu-year').value;
465
  const subject = document.getElementById('edu-subject').value;
466
 
467
- // Save Context
468
  userContext = `${level}, ${year}, ${subject}`;
469
  try { localStorage.setItem("student_ai_context", userContext); } catch(e){}
470
 
@@ -481,7 +491,7 @@ HTML_TEMPLATE = """
481
  localStorage.removeItem("student_ai_user");
482
  localStorage.removeItem("student_ai_context");
483
  } catch(e){}
484
- location.reload(); // Simple reload to reset
485
  }
486
 
487
  function showApp() {
@@ -580,7 +590,7 @@ HTML_TEMPLATE = """
580
  file_text: fileText,
581
  username: currentUser,
582
  chat_id: currentChatId,
583
- user_context: userContext // SENDING CONTEXT TO BACKEND
584
  })
585
  });
586
  const data = await res.json();
@@ -812,14 +822,13 @@ def chat():
812
  u, cid, msg = d.get("username"), d.get("chat_id"), d.get("message")
813
  img_data = d.get("image")
814
  file_text = d.get("file_text")
815
- user_context = d.get("user_context", "") # Capture User Context
816
 
817
  if u not in user_db: user_db[u] = {}
818
  if cid not in user_db[u]: user_db[u][cid] = {"messages": []}
819
 
820
  user_db[u][cid]["messages"].append({"role": "user", "content": msg})
821
 
822
- # PASS USER CONTEXT TO GENERATION FUNCTION
823
  reply = generate_with_retry(msg, img_data, file_text, user_db[u][cid]["messages"][:-1], user_context)
824
 
825
  user_db[u][cid]["messages"].append({"role": "model", "content": reply})
@@ -832,30 +841,6 @@ def chat():
832
  save_db(user_db)
833
  return jsonify({"response": reply, "new_title": new_title})
834
 
835
- @app.route('/manifest.json')
836
- def manifest():
837
- data = {
838
- "name": "Student's AI",
839
- "short_name": "StudentAI",
840
- "start_url": "/",
841
- "display": "standalone",
842
- "orientation": "portrait",
843
- "background_color": "#09090b",
844
- "theme_color": "#09090b",
845
- "icons": [
846
- {
847
- "src": "https://cdn-icons-png.flaticon.com/512/4712/4712035.png",
848
- "sizes": "192x192",
849
- "type": "image/png"
850
- },
851
- {
852
- "src": "https://cdn-icons-png.flaticon.com/512/4712/4712035.png",
853
- "sizes": "512x512",
854
- "type": "image/png"
855
- }
856
- ]
857
- }
858
- return Response(json.dumps(data), mimetype='application/json')
859
-
860
  if __name__ == '__main__':
861
- app.run(host='0.0.0.0', port=7860)
 
 
239
  -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain; min-height: 0;
240
  }
241
 
242
+ /* --- LOCKED INTRO TEXT (UNCHANGED) --- */
243
  #intro-container {
244
  position: absolute;
245
  top: 140px;
 
293
  padding-top: 150px;
294
  transition: opacity 0.5s ease; opacity: 1; pointer-events: auto;
295
  }
296
+
297
+ /* Force hidden to be actually hidden */
298
+ .overlay.hidden { display: none !important; opacity: 0; pointer-events: none; }
299
 
300
  .login-box {
301
  width: 90%; max-width: 350px; text-align: center;
 
366
  <header>
367
  <div class="menu-btn" onclick="toggleSidebar()"><i class="fas fa-bars"></i></div>
368
  <span class="app-title">Student's AI</span>
369
+ <div style="width:40px;" class="settings-icon" onclick="openSettings()"><i class="fas fa-cog"></i></div>
370
  </header>
371
 
372
  <div id="chat-box"></div>
 
411
 
412
  if (storedUser) {
413
  currentUser = storedUser;
414
+ // Hide Login
415
+ const loginOverlay = document.getElementById("login-overlay");
416
+ loginOverlay.classList.add('hidden');
417
 
418
  if (storedContext) {
419
  userContext = storedContext;
420
  document.getElementById("selection-overlay").classList.add('hidden');
421
  showApp();
422
  } else {
423
+ // Show Selection
424
+ const selOverlay = document.getElementById("selection-overlay");
425
+ selOverlay.classList.remove('hidden');
426
  updateEduOptions();
427
  }
428
  }
 
435
  if(name) {
436
  try { localStorage.setItem("student_ai_user", name); } catch(e){}
437
  currentUser = name;
438
+
439
+ // 1. Force Hide Login
440
+ const loginOverlay = document.getElementById("login-overlay");
441
+ loginOverlay.classList.add('hidden');
442
+
443
+ // 2. Force Show Selection
444
+ const selOverlay = document.getElementById("selection-overlay");
445
+ selOverlay.classList.remove('hidden'); // Remove hidden class
446
+
447
  updateEduOptions();
448
  } else {
449
  input.style.border = "1px solid red";
 
475
  const year = document.getElementById('edu-year').value;
476
  const subject = document.getElementById('edu-subject').value;
477
 
 
478
  userContext = `${level}, ${year}, ${subject}`;
479
  try { localStorage.setItem("student_ai_context", userContext); } catch(e){}
480
 
 
491
  localStorage.removeItem("student_ai_user");
492
  localStorage.removeItem("student_ai_context");
493
  } catch(e){}
494
+ location.reload();
495
  }
496
 
497
  function showApp() {
 
590
  file_text: fileText,
591
  username: currentUser,
592
  chat_id: currentChatId,
593
+ user_context: userContext
594
  })
595
  });
596
  const data = await res.json();
 
822
  u, cid, msg = d.get("username"), d.get("chat_id"), d.get("message")
823
  img_data = d.get("image")
824
  file_text = d.get("file_text")
825
+ user_context = d.get("user_context", "")
826
 
827
  if u not in user_db: user_db[u] = {}
828
  if cid not in user_db[u]: user_db[u][cid] = {"messages": []}
829
 
830
  user_db[u][cid]["messages"].append({"role": "user", "content": msg})
831
 
 
832
  reply = generate_with_retry(msg, img_data, file_text, user_db[u][cid]["messages"][:-1], user_context)
833
 
834
  user_db[u][cid]["messages"].append({"role": "model", "content": reply})
 
841
  save_db(user_db)
842
  return jsonify({"response": reply, "new_title": new_title})
843
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
844
  if __name__ == '__main__':
845
+ app.run(host='0.0.0.0', port=7860)
846
+