Spaces:
Running
Running
File size: 22,693 Bytes
be76c74 e188a74 be76c74 e188a74 be76c74 e188a74 be76c74 e188a74 be76c74 e188a74 be76c74 e188a74 be76c74 e188a74 be76c74 e188a74 be76c74 b82f276 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Legal Assistant | Citizen Dashboard</title>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-dark: #030617;
--sidebar-bg: #050a24;
--accent-blue: #3b82f6;
--accent-purple: #9333ea;
--text-primary: #f1f5f9;
--text-dim: #94a3b8;
--glass-bg: rgba(255, 255, 255, 0.03);
--glass-border: rgba(255, 255, 255, 0.08);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
body {
background-color: var(--bg-dark);
color: var(--text-primary);
height: 100vh;
display: flex;
overflow: hidden;
}
/* SIDEBAR (ZONE 1) */
.sidebar {
width: 280px;
background: var(--sidebar-bg);
border-right: 1px solid var(--glass-border);
display: flex;
flex-direction: column;
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
z-index: 100;
}
.sidebar-header {
padding: 30px 20px;
}
.new-chat-btn {
width: 100%;
padding: 14px;
background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
border: none;
border-radius: 12px;
color: white;
font-weight: 600;
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 10px 20px rgba(59, 130, 246, 0.2);
}
.new-chat-btn:hover {
transform: translateY(-2px);
box-shadow: 0 15px 25px rgba(59, 130, 246, 0.3);
}
.history-label {
padding: 0 20px 10px;
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 2px;
color: var(--text-dim);
font-weight: 700;
}
.history-list {
flex: 1;
overflow-y: auto;
padding: 10px;
}
.history-item {
padding: 12px 15px;
border-radius: 10px;
margin-bottom: 5px;
cursor: pointer;
transition: all 0.2s;
font-size: 0.85rem;
color: var(--text-dim);
display: flex;
align-items: center;
gap: 10px;
border: 1px solid transparent;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.history-item:hover {
background: var(--glass-bg);
color: white;
border-color: var(--glass-border);
}
.item-active {
background: rgba(59, 130, 246, 0.1) !important;
color: var(--accent-blue) !important;
border-color: rgba(59, 130, 246, 0.2) !important;
}
.sidebar-footer {
padding: 20px;
border-top: 1px solid var(--glass-border);
}
.user-badge {
display: flex;
align-items: center;
gap: 12px;
padding: 10px;
background: var(--glass-bg);
border-radius: 12px;
}
.user-avatar {
width: 32px;
height: 32px;
background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
font-weight: 700;
font-size: 0.8rem;
color: white;
}
/* MAIN CONTENT (ZONE 2) */
.main-chat {
flex: 1;
display: flex;
flex-direction: column;
position: relative;
background: radial-gradient(circle at top right, rgba(59, 130, 246, 0.03), transparent);
}
/* TOP BAR */
.top-bar {
height: 70px;
background: rgba(3, 6, 23, 0.82);
backdrop-filter: blur(25px);
-webkit-backdrop-filter: blur(25px);
border-bottom: 1px solid var(--glass-border);
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 40px;
z-index: 50;
}
.system-branding {
display: flex;
align-items: center;
gap: 15px;
}
.status-pill {
display: flex;
align-items: center;
gap: 8px;
font-size: 0.75rem;
background: rgba(34, 197, 94, 0.1);
color: #22c55e;
padding: 4px 12px;
border-radius: 20px;
font-weight: 600;
border: 1px solid rgba(34, 197, 94, 0.2);
}
.status-dot {
width: 6px;
height: 6px;
background: #22c55e;
border-radius: 50%;
animation: pulse-dot 2s infinite;
}
@keyframes pulse-dot {
0% { transform: scale(1); opacity: 1; }
50% { transform: scale(1.5); opacity: 0.4; }
100% { transform: scale(1); opacity: 1; }
}
/* MESSAGES AREA */
.messages-container {
flex: 1;
overflow-y: auto;
padding: 40px 10%;
display: flex;
flex-direction: column;
gap: 30px;
scroll-behavior: smooth;
}
.message {
max-width: 850px;
animation: message-slide 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
position: relative;
}
@keyframes message-slide {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
/* USER MSG */
.user-msg {
align-self: flex-end;
background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
padding: 16px 24px;
border-radius: 20px 20px 4px 20px;
max-width: 70%;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
font-size: 1rem;
line-height: 1.6;
color: white;
}
/* AI MSG */
.ai-msg {
align-self: flex-start;
background: var(--glass-bg);
border: 1px solid var(--glass-border);
padding: 30px;
border-radius: 20px 20px 20px 4px;
max-width: 85%;
font-size: 1.05rem;
line-height: 1.8;
color: #e2e8f0;
}
.ai-msg h3 {
color: var(--accent-blue);
font-size: 1.3rem;
margin-bottom: 20px;
display: flex;
align-items: center;
gap: 12px;
font-weight: 600;
}
.ai-msg p {
margin-bottom: 18px;
}
.ai-msg ul {
margin: 20px 0;
list-style: none;
}
.ai-msg li {
position: relative;
padding-left: 28px;
margin-bottom: 15px;
}
.ai-msg li::before {
content: "→";
position: absolute;
left: 0;
color: var(--accent-blue);
font-weight: 700;
}
.highlight {
background: rgba(59, 130, 246, 0.08);
border-left: 4px solid var(--accent-blue);
padding: 22px;
margin: 25px 0;
border-radius: 0 16px 16px 0;
font-weight: 500;
color: #fff;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}
/* TYPING INDICATOR */
.typing {
display: flex;
flex-direction: column;
gap: 10px;
padding: 16px 24px;
background: var(--glass-bg);
border-radius: 20px;
width: fit-content;
margin: 20px 10%;
border: 1px solid var(--glass-border);
animation: pulse-border 2s infinite ease-in-out;
}
.typing-text {
font-size: 0.85rem;
color: var(--accent-blue);
font-weight: 500;
letter-spacing: 0.5px;
}
.typing-dots {
display: flex;
gap: 6px;
}
.typing-dots span {
width: 7px;
height: 7px;
background: var(--accent-blue);
border-radius: 50%;
animation: typing-blink 1.4s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-blink {
0%, 100% { opacity: 0.3; transform: scale(0.8); }
50% { opacity: 1; transform: scale(1.1); }
}
@keyframes pulse-border {
0%, 100% { border-color: var(--glass-border); }
50% { border-color: var(--accent-blue); box-shadow: 0 0 20px rgba(59, 130, 246, 0.1); }
}
/* INPUT AREA */
.input-area {
padding: 30px 10%;
background: linear-gradient(to top, var(--bg-dark) 50%, transparent);
border-top: 1px solid var(--glass-border);
z-index: 60;
}
.input-box {
position: relative;
background: rgba(255, 255, 255, 0.04);
border: 1px solid var(--glass-border);
border-radius: 18px;
padding: 6px;
display: flex;
align-items: center;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
.input-box:focus-within {
border-color: var(--accent-blue);
box-shadow: 0 0 30px rgba(59, 130, 246, 0.2);
background: rgba(255, 255, 255, 0.06);
}
.input-box input {
flex: 1;
background: transparent;
border: none;
padding: 16px 24px;
color: white;
font-size: 1.05rem;
outline: none;
font-weight: 400;
}
.input-box input::placeholder { color: var(--text-dim); }
.send-btn {
background: var(--accent-blue);
color: white;
border: none;
width: 50px;
height: 50px;
border-radius: 14px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
margin-right: 6px;
}
.send-btn:hover {
background: var(--accent-purple);
transform: scale(1.1) rotate(5deg);
}
/* SCROLLBAR */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
.hidden { display: none !important; }
@media (max-width: 1024px) {
.sidebar { width: 0; transform: translateX(-100%); position: absolute; }
.messages-container, .input-area { padding: 30px 5%; }
.top-bar { padding: 0 20px; }
}
</style>
</head>
<body>
<!-- ZONE 1: SIDEBAR -->
<aside class="sidebar" id="sidebar">
<div class="sidebar-header">
<button class="new-chat-btn" id="newChatBtn">
<span>+</span> New Case
</button>
</div>
<div class="history-label">Case Archives</div>
<div class="history-list" id="historyList">
<!-- Threads pop here -->
</div>
<div class="sidebar-footer">
<div class="user-badge">
<div class="user-avatar" id="avatarName">CT</div>
<div>
<div id="usernameLabel" style="font-size: 0.85rem; font-weight: 600;">Citizen</div>
<div style="font-size: 0.7rem; color: var(--text-dim);">Active Consultation</div>
</div>
</div>
<a href="/role" style="display: block; margin-top: 15px; color: var(--text-dim); text-decoration: none; font-size: 0.8rem; text-align: center; font-weight: 500;">← Change Role</a>
</div>
</aside>
<!-- ZONE 2: MAIN AREA -->
<main class="main-chat">
<header class="top-bar">
<div class="system-branding">
<span style="font-weight: 700; color: white;">⚖️ AI Legal Assistant</span>
<div class="status-pill">
<div class="status-dot"></div>
System Ready
</div>
</div>
<div style="font-size: 0.85rem; color: var(--text-dim); font-weight: 500;">Citizen Framework v4.0 PRO</div>
</header>
<div id="welcomeScreen" style="position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 40px; z-index: 1;">
<div style="font-size: 4rem; margin-bottom: 25px; animation: float 6s ease-in-out infinite;">🤖</div>
<h1 style="font-size: 2.8rem; font-weight: 700; margin-bottom: 12px; letter-spacing: -1px;">Intelligence at your service.</h1>
<p style="color: var(--text-dim); max-width: 550px; line-height: 1.7; font-size: 1.1rem;">Describe your legal issue, ask about sections, or get procedural guidance. Your Indian Law expert is ready to assist.</p>
</div>
<div class="messages-container" id="chatContainer">
<!-- Messages stream here -->
</div>
<div class="typing hidden" id="typingIndicator">
<div class="typing-text">Law Bot is thinking...</div>
<div class="typing-dots">
<span></span><span></span><span></span>
</div>
</div>
<div class="input-area">
<div class="input-box">
<input type="text" id="messageInput" placeholder="How can I help you navigate the law today?" autocomplete="off">
<button class="send-btn" id="sendButton">
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="22" y1="2" x2="11" y2="13"></line><polygon points="22 2 15 22 11 13 2 9 22 2"></polygon></svg>
</button>
</div>
<p style="text-align: center; font-size: 0.75rem; color: var(--text-dim); margin-top: 18px; font-weight: 400; opacity: 0.8;">⚠️ AI can provide guidance based on IPC/BNS/CrPC. For critical judicial matters, always consult a certified advocate.</p>
</div>
</main>
<script>
let ws;
const chatContainer = document.getElementById('chatContainer');
const messageInput = document.getElementById('messageInput');
const sendButton = document.getElementById('sendButton');
const typingIndicator = document.getElementById('typingIndicator');
const welcomeScreen = document.getElementById('welcomeScreen');
const historyList = document.getElementById('historyList');
let currentAiMessage = '';
let currentAiMessageElement = null;
let currentCaseId = crypto.randomUUID();
const activeRole = 'Citizen';
function formatResponse(text) {
let formatted = text;
// Header mapping (### titles)
formatted = formatted.replace(/### (.*?)\s*(\n|$)/g, "<h3>⚖️ $1</h3>");
// Highlight boxes (! at start of line)
formatted = formatted.replace(/^! (.*?)$/gm, '<div class="highlight">$1</div>');
// Bullet points
formatted = formatted.replace(/^\d+\.\s(.*?)$/gm, "<li>$1</li>");
formatted = formatted.replace(/^\*\s(.*?)$/gm, "<li>$1</li>");
formatted = formatted.replace(/- (.*?)$/gm, "<li>$1</li>");
formatted = formatted.replace(/<li>(.*?)<\/li>(?!<li>)/g, "<ul><li>$1</li></ul>");
// Bold and Newlines
formatted = formatted.replace(/\*\*(.*?)\*\*/g, "<strong>$1</strong>");
formatted = formatted.replace(/\n/g, "<br>");
return formatted;
}
function connectWS() {
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
ws = new WebSocket(`${protocol}//${window.location.host}/conversational_chat?role=${activeRole}`);
ws.onmessage = (event) => {
typingIndicator.classList.add('hidden');
welcomeScreen.classList.add('hidden');
if (event.data === '[DONE]') {
saveInteraction(currentCaseId, messageInput.value, currentAiMessage);
return;
}
if (!currentAiMessageElement) {
currentAiMessage = event.data;
createNewMessage('ai', currentAiMessage);
} else {
currentAiMessage += event.data;
currentAiMessageElement.innerHTML = formatResponse(currentAiMessage);
}
chatContainer.scrollTop = chatContainer.scrollHeight;
};
ws.onclose = () => {
console.log("WebSocket Disconnected. Reconnecting...");
setTimeout(connectWS, 2000);
};
}
function createNewMessage(type, content) {
welcomeScreen.classList.add('hidden');
const msgDiv = document.createElement('div');
msgDiv.className = `message ${type}-msg`;
if (type === 'ai') {
msgDiv.innerHTML = formatResponse(content);
currentAiMessageElement = msgDiv;
} else {
msgDiv.textContent = content;
}
chatContainer.appendChild(msgDiv);
chatContainer.scrollTop = chatContainer.scrollHeight;
}
function sendMessage() {
const text = messageInput.value.trim();
if (!text || ws.readyState !== WebSocket.OPEN) return;
createNewMessage('user', text);
ws.send(text);
messageInput.value = '';
currentAiMessage = '';
currentAiMessageElement = null;
typingIndicator.classList.remove('hidden');
chatContainer.scrollTop = chatContainer.scrollHeight;
}
async function saveInteraction(caseId, query, response) {
const token = localStorage.getItem('token');
if (!token) return;
try {
await fetch('/api/save-interaction', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({ caseId, query, response, role: activeRole })
});
loadHistory();
} catch (err) { console.error(err); }
}
async function loadHistory() {
const token = localStorage.getItem('token');
if (!token) return;
try {
const res = await fetch(`/api/interactions?role=${activeRole}`, {
headers: { 'Authorization': `Bearer ${token}` }
});
const data = await res.json();
historyList.innerHTML = '';
data.forEach(item => {
const div = document.createElement('div');
div.className = 'history-item';
const preview = item.query.substring(0, 30) + "...";
div.innerHTML = `<span>📂</span> ${preview}`;
div.onclick = () => loadThread(item.case_id);
historyList.appendChild(div);
});
} catch (err) { console.error(err); }
}
async function loadThread(caseId) {
const token = localStorage.getItem('token');
try {
const res = await fetch(`/api/interactions/${caseId}?role=${activeRole}`, {
headers: { 'Authorization': `Bearer ${token}` }
});
const thread = await res.json();
currentCaseId = caseId;
chatContainer.innerHTML = '';
welcomeScreen.classList.add('hidden');
thread.forEach(msg => {
createNewMessage('user', msg.query);
createNewMessage('ai', msg.response);
});
currentAiMessageElement = null;
} catch (err) { console.error(err); }
}
async function fetchUserStatus() {
const token = localStorage.getItem('token');
if (!token) return;
try {
const res = await fetch('/api/user-status', {
headers: { 'Authorization': `Bearer ${token}` }
});
const status = await res.json();
document.getElementById('usernameLabel').innerText = status.username.charAt(0).toUpperCase() + status.username.slice(1);
document.getElementById('avatarName').innerText = status.username.substring(0, 2).toUpperCase();
} catch (err) { console.error(err); }
}
sendButton.onclick = sendMessage;
messageInput.onkeypress = (e) => { if (e.key === 'Enter') sendMessage(); };
document.getElementById('newChatBtn').onclick = () => {
currentCaseId = crypto.randomUUID();
chatContainer.innerHTML = '';
welcomeScreen.classList.remove('hidden');
};
connectWS();
loadHistory();
fetchUserStatus();
</script>
</body>
</html> |