Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -340,7 +340,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
|
| 344 |
</div>
|
| 345 |
</div>
|
| 346 |
|
|
@@ -401,16 +401,19 @@ 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 ---
|
| 405 |
function checkLogin() {
|
| 406 |
-
|
| 407 |
-
|
|
|
|
|
|
|
| 408 |
}
|
|
|
|
| 409 |
function handleLogin() {
|
| 410 |
const input = document.getElementById("username-input");
|
| 411 |
const name = input.value.trim();
|
| 412 |
if(name) {
|
| 413 |
-
localStorage.setItem("student_ai_user", name);
|
| 414 |
currentUser = name;
|
| 415 |
showApp();
|
| 416 |
} else {
|
|
@@ -418,7 +421,13 @@ HTML_TEMPLATE = """
|
|
| 418 |
setTimeout(() => input.style.border = "1px solid #333", 2000);
|
| 419 |
}
|
| 420 |
}
|
| 421 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 422 |
|
| 423 |
function showApp() {
|
| 424 |
document.getElementById("login-overlay").style.display = "none";
|
|
@@ -569,13 +578,11 @@ HTML_TEMPLATE = """
|
|
| 569 |
}
|
| 570 |
function handleHistoryTouchEnd(e) { clearTimeout(longPressTimer); }
|
| 571 |
|
| 572 |
-
// SAFE RENAME: We do NOT pass the title in the function call to avoid quotes breaking JS.
|
| 573 |
function startRename(cid) {
|
| 574 |
const item = document.getElementById('chat-' + cid);
|
| 575 |
const titleSpan = item.querySelector('.h-title');
|
| 576 |
const currentTitle = titleSpan.innerText;
|
| 577 |
|
| 578 |
-
// Create input
|
| 579 |
const input = document.createElement('input');
|
| 580 |
input.type = 'text';
|
| 581 |
input.value = currentTitle;
|
|
@@ -599,13 +606,15 @@ HTML_TEMPLATE = """
|
|
| 599 |
if(e.key === 'Enter') { input.blur(); }
|
| 600 |
});
|
| 601 |
|
| 602 |
-
// Replace span with input
|
| 603 |
titleSpan.replaceWith(input);
|
| 604 |
input.focus();
|
| 605 |
}
|
| 606 |
|
| 607 |
async function deleteChat(cid) {
|
| 608 |
-
// FIX:
|
|
|
|
|
|
|
|
|
|
| 609 |
await fetch('/delete_chat', {
|
| 610 |
method:'POST', headers:{'Content-Type':'application/json'},
|
| 611 |
body:JSON.stringify({username:currentUser, chat_id:cid})
|
|
@@ -622,7 +631,6 @@ HTML_TEMPLATE = """
|
|
| 622 |
if (data.chats) {
|
| 623 |
Object.keys(data.chats).reverse().forEach(cid => {
|
| 624 |
const title = data.chats[cid].title || "New Chat";
|
| 625 |
-
// FIX: Only passing cid to startRename, avoiding syntax errors from titles
|
| 626 |
list.innerHTML += `
|
| 627 |
<div class="history-item" id="chat-${cid}" onclick="loadChat('${cid}')" oncontextmenu="return false;"
|
| 628 |
ontouchstart="handleHistoryTouchStart(event, '${cid}')" ontouchend="handleHistoryTouchEnd(event)">
|
|
@@ -682,7 +690,6 @@ HTML_TEMPLATE = """
|
|
| 682 |
box.scrollTop = box.scrollHeight;
|
| 683 |
}
|
| 684 |
|
| 685 |
-
// --- MANIFEST FOR APP LOGO ---
|
| 686 |
@app.route('/manifest.json')
|
| 687 |
def manifest():
|
| 688 |
data = {
|
|
@@ -789,8 +796,7 @@ def manifest():
|
|
| 789 |
"theme_color": "#09090b",
|
| 790 |
"icons": [
|
| 791 |
{
|
| 792 |
-
"src": "https://huggingface.co/spaces/Shirpi/Student-s_AI/resolve/main/1000177401.png",
|
| 793 |
-
"sizes": "192x192",
|
| 794 |
"type": "image/png"
|
| 795 |
},
|
| 796 |
{
|
|
|
|
| 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 |
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();
|
| 415 |
if(name) {
|
| 416 |
+
try { localStorage.setItem("student_ai_user", name); } catch(e){}
|
| 417 |
currentUser = name;
|
| 418 |
showApp();
|
| 419 |
} else {
|
|
|
|
| 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";
|
|
|
|
| 578 |
}
|
| 579 |
function handleHistoryTouchEnd(e) { clearTimeout(longPressTimer); }
|
| 580 |
|
|
|
|
| 581 |
function startRename(cid) {
|
| 582 |
const item = document.getElementById('chat-' + cid);
|
| 583 |
const titleSpan = item.querySelector('.h-title');
|
| 584 |
const currentTitle = titleSpan.innerText;
|
| 585 |
|
|
|
|
| 586 |
const input = document.createElement('input');
|
| 587 |
input.type = 'text';
|
| 588 |
input.value = currentTitle;
|
|
|
|
| 606 |
if(e.key === 'Enter') { input.blur(); }
|
| 607 |
});
|
| 608 |
|
|
|
|
| 609 |
titleSpan.replaceWith(input);
|
| 610 |
input.focus();
|
| 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 |
+
|
| 618 |
await fetch('/delete_chat', {
|
| 619 |
method:'POST', headers:{'Content-Type':'application/json'},
|
| 620 |
body:JSON.stringify({username:currentUser, chat_id:cid})
|
|
|
|
| 631 |
if (data.chats) {
|
| 632 |
Object.keys(data.chats).reverse().forEach(cid => {
|
| 633 |
const title = data.chats[cid].title || "New Chat";
|
|
|
|
| 634 |
list.innerHTML += `
|
| 635 |
<div class="history-item" id="chat-${cid}" onclick="loadChat('${cid}')" oncontextmenu="return false;"
|
| 636 |
ontouchstart="handleHistoryTouchStart(event, '${cid}')" ontouchend="handleHistoryTouchEnd(event)">
|
|
|
|
| 690 |
box.scrollTop = box.scrollHeight;
|
| 691 |
}
|
| 692 |
|
|
|
|
| 693 |
@app.route('/manifest.json')
|
| 694 |
def manifest():
|
| 695 |
data = {
|
|
|
|
| 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 |
{
|