Shirpi commited on
Commit
83f7e3d
·
verified ·
1 Parent(s): 41cdfa4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -42
app.py CHANGED
@@ -109,6 +109,7 @@ def generate_with_retry(prompt, image_data=None, file_text=None, history_message
109
  return "⚠️ System Busy. Please try again."
110
 
111
  # --- UI TEMPLATE ---
 
112
  HTML_TEMPLATE = """
113
  <!DOCTYPE html>
114
  <html lang="en">
@@ -147,20 +148,27 @@ HTML_TEMPLATE = """
147
  background: var(--bg); color: var(--text); font-family: 'Outfit', sans-serif;
148
  overflow: hidden;
149
  font-size: 17px;
 
 
150
  -webkit-user-select: none;
151
  -moz-user-select: none;
152
  -ms-user-select: none;
153
  user-select: none;
 
154
  }
155
 
 
156
  textarea, input {
157
  -webkit-user-select: text !important;
158
  user-select: text !important;
 
159
  }
160
 
 
161
  .user-content, .ai-content, code, pre, p, h1, h2, span, div {
162
  -webkit-user-select: none !important;
163
  user-select: none !important;
 
164
  }
165
 
166
  #app-container {
@@ -340,7 +348,7 @@ HTML_TEMPLATE = """
340
  <div class="login-box">
341
  <h1 class="app-title" style="margin-bottom:10px;">Student's AI</h1>
342
  <input type="text" id="username-input" placeholder="Your Name" style="width:100%; padding:15px; border-radius:12px; border:1px solid #333; background:#111; color:#fff; text-align:center; outline:none; margin-bottom:20px; font-size: 16px;">
343
- <button id="start-btn" style="width:100%; padding:15px; border-radius:12px; border:none; background:#fff; font-weight:800; cursor:pointer; font-size: 16px;">Start Learning</button>
344
  </div>
345
  </div>
346
 
@@ -401,14 +409,13 @@ HTML_TEMPLATE = """
401
  return `<div class="msg ai-msg"><div class="ai-content"><h1>Hi ${name},</h1><p>Ready to master your studies today?</p></div></div>`;
402
  }
403
 
404
- // --- AUTH LOGIC (FIXED) ---
405
  function checkLogin() {
406
  try {
407
  const stored = localStorage.getItem("student_ai_user");
408
  if (stored) { currentUser = stored; showApp(); }
409
  } catch(e) { console.log("Storage access denied"); }
410
  }
411
-
412
  function handleLogin() {
413
  const input = document.getElementById("username-input");
414
  const name = input.value.trim();
@@ -421,13 +428,7 @@ HTML_TEMPLATE = """
421
  setTimeout(() => input.style.border = "1px solid #333", 2000);
422
  }
423
  }
424
-
425
- document.getElementById('start-btn').addEventListener('click', handleLogin);
426
-
427
- function handleLogout() {
428
- try { localStorage.removeItem("student_ai_user"); } catch(e){}
429
- location.reload();
430
- }
431
 
432
  function showApp() {
433
  document.getElementById("login-overlay").style.display = "none";
@@ -435,8 +436,7 @@ HTML_TEMPLATE = """
435
  loadHistory();
436
  if(!currentChatId) {
437
  const box = document.getElementById("chat-box");
438
- if(box.innerHTML === "") {
439
- box.innerHTML = getIntroHtml(currentUser);
440
  }
441
  }
442
  }
@@ -611,7 +611,6 @@ HTML_TEMPLATE = """
611
  }
612
 
613
  async function deleteChat(cid) {
614
- // FIX: Instant delete visually first
615
  const el = document.getElementById('chat-' + cid);
616
  if(el) el.remove();
617
 
@@ -690,31 +689,6 @@ HTML_TEMPLATE = """
690
  box.scrollTop = box.scrollHeight;
691
  }
692
 
693
- @app.route('/manifest.json')
694
- def manifest():
695
- data = {
696
- "name": "Student's AI",
697
- "short_name": "StudentAI",
698
- "start_url": "/",
699
- "display": "standalone",
700
- "orientation": "portrait",
701
- "background_color": "#09090b",
702
- "theme_color": "#09090b",
703
- "icons": [
704
- {
705
- "src": "https://cdn-icons-png.flaticon.com/512/4712/4712035.png",
706
- "sizes": "192x192",
707
- "type": "image/png"
708
- },
709
- {
710
- "src": "https://cdn-icons-png.flaticon.com/512/4712/4712035.png",
711
- "sizes": "512x512",
712
- "type": "image/png"
713
- }
714
- ]
715
- }
716
- return Response(json.dumps(data), mimetype='application/json')
717
-
718
  checkLogin();
719
  </script>
720
  </body>
@@ -788,7 +762,7 @@ def chat():
788
  def manifest():
789
  data = {
790
  "name": "Student's AI",
791
- "short_name": "Student's AI",
792
  "start_url": "/",
793
  "display": "standalone",
794
  "orientation": "portrait",
@@ -796,11 +770,12 @@ def manifest():
796
  "theme_color": "#09090b",
797
  "icons": [
798
  {
799
- "src": "https://huggingface.co/spaces/Shirpi/Student-s_AI/resolve/main/1000177401.png",
 
800
  "type": "image/png"
801
  },
802
  {
803
- "src": "https://huggingface.co/spaces/Shirpi/Student-s_AI/resolve/main/1000177401.png",
804
  "sizes": "512x512",
805
  "type": "image/png"
806
  }
@@ -809,4 +784,5 @@ def manifest():
809
  return Response(json.dumps(data), mimetype='application/json')
810
 
811
  if __name__ == '__main__':
812
- app.run(host='0.0.0.0', port=7860)
 
 
109
  return "⚠️ System Busy. Please try again."
110
 
111
  # --- UI TEMPLATE ---
112
+ # (Idhu HTML string variable dhaan, HTML file finish aagura edam idhu)
113
  HTML_TEMPLATE = """
114
  <!DOCTYPE html>
115
  <html lang="en">
 
148
  background: var(--bg); color: var(--text); font-family: 'Outfit', sans-serif;
149
  overflow: hidden;
150
  font-size: 17px;
151
+
152
+ /* No Selection Allowed */
153
  -webkit-user-select: none;
154
  -moz-user-select: none;
155
  -ms-user-select: none;
156
  user-select: none;
157
+ -webkit-touch-callout: none;
158
  }
159
 
160
+ /* Allow Selection in Inputs */
161
  textarea, input {
162
  -webkit-user-select: text !important;
163
  user-select: text !important;
164
+ -webkit-touch-callout: default !important;
165
  }
166
 
167
+ /* Prevent long press on content */
168
  .user-content, .ai-content, code, pre, p, h1, h2, span, div {
169
  -webkit-user-select: none !important;
170
  user-select: none !important;
171
+ -webkit-touch-callout: none !important;
172
  }
173
 
174
  #app-container {
 
348
  <div class="login-box">
349
  <h1 class="app-title" style="margin-bottom:10px;">Student's AI</h1>
350
  <input type="text" id="username-input" placeholder="Your Name" style="width:100%; padding:15px; border-radius:12px; border:1px solid #333; background:#111; color:#fff; text-align:center; outline:none; margin-bottom:20px; font-size: 16px;">
351
+ <button onclick="handleLogin()" style="width:100%; padding:15px; border-radius:12px; border:none; background:#fff; font-weight:800; cursor:pointer; font-size: 16px;">Start Learning</button>
352
  </div>
353
  </div>
354
 
 
409
  return `<div class="msg ai-msg"><div class="ai-content"><h1>Hi ${name},</h1><p>Ready to master your studies today?</p></div></div>`;
410
  }
411
 
412
+ // --- AUTH LOGIC ---
413
  function checkLogin() {
414
  try {
415
  const stored = localStorage.getItem("student_ai_user");
416
  if (stored) { currentUser = stored; showApp(); }
417
  } catch(e) { console.log("Storage access denied"); }
418
  }
 
419
  function handleLogin() {
420
  const input = document.getElementById("username-input");
421
  const name = input.value.trim();
 
428
  setTimeout(() => input.style.border = "1px solid #333", 2000);
429
  }
430
  }
431
+ function handleLogout() { localStorage.removeItem("student_ai_user"); location.reload(); }
 
 
 
 
 
 
432
 
433
  function showApp() {
434
  document.getElementById("login-overlay").style.display = "none";
 
436
  loadHistory();
437
  if(!currentChatId) {
438
  const box = document.getElementById("chat-box");
439
+ if(box.innerHTML === "") {ntroHtml(currentUser);
 
440
  }
441
  }
442
  }
 
611
  }
612
 
613
  async function deleteChat(cid) {
 
614
  const el = document.getElementById('chat-' + cid);
615
  if(el) el.remove();
616
 
 
689
  box.scrollTop = box.scrollHeight;
690
  }
691
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
692
  checkLogin();
693
  </script>
694
  </body>
 
762
  def manifest():
763
  data = {
764
  "name": "Student's AI",
765
+ "short_name": "StudentAI",
766
  "start_url": "/",
767
  "display": "standalone",
768
  "orientation": "portrait",
 
770
  "theme_color": "#09090b",
771
  "icons": [
772
  {
773
+ "src": "https://cdn-icons-png.flaticon.com/512/4712/4712035.png",
774
+ "sizes": "192x192",
775
  "type": "image/png"
776
  },
777
  {
778
+ "src": "https://cdn-icons-png.flaticon.com/512/4712/4712035.png",
779
  "sizes": "512x512",
780
  "type": "image/png"
781
  }
 
784
  return Response(json.dumps(data), mimetype='application/json')
785
 
786
  if __name__ == '__main__':
787
+ app.run(host='0.0.0.0', port=7860)
788
+ box.innerHTML = getI