Spaces:
Sleeping
Sleeping
Update index.html
Browse files- index.html +330 -629
index.html
CHANGED
|
@@ -3,698 +3,399 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
|
| 7 |
-
<title>Sentry - Document Assistant</title>
|
| 8 |
-
<!-- jQuery -->
|
| 9 |
-
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
| 10 |
-
<!-- Font Awesome for Icons -->
|
| 11 |
-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" integrity="sha512-9usAa10IRO0HhonpyAIVpjrylPvoDwiPUiKdWk5t3PyolY1cOd4DSE0Ga+ri4AuTroPR5aQvXU9xC6qOPnzFeg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
| 12 |
<style>
|
| 13 |
-
/* --- CSS Variables for Theme --- */
|
| 14 |
-
:root {
|
| 15 |
-
--primary-color: #2f3136; /* Darker background */
|
| 16 |
-
--secondary-color: #36393f; /* Main chat container background */
|
| 17 |
-
--tertiary-color: #40444b; /* Input fields, message bubbles */
|
| 18 |
-
--text-color: #dcddde; /* Main text color (light gray) */
|
| 19 |
-
--text-muted-color: #b9bbbe; /* Slightly dimmer text */
|
| 20 |
-
--accent-color: #5865f2; /* Sentry/Discord Blurple (Updated) */
|
| 21 |
-
--accent-hover-color: #4e5ae0; /* Darker accent for hover */
|
| 22 |
-
--user-message-bg: var(--accent-color); /* User message bubble */
|
| 23 |
-
--assistant-message-bg: var(--tertiary-color); /* Assistant message bubble */
|
| 24 |
-
--input-bg: var(--tertiary-color);
|
| 25 |
-
--border-color: #202225; /* Darkest borders */
|
| 26 |
-
--success-color: #43b581; /* Green */
|
| 27 |
-
--error-color: #f04747; /* Red */
|
| 28 |
-
--font-family: 'Inter', 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
| 29 |
-
--border-radius: 8px;
|
| 30 |
-
--scrollbar-thumb-color: #202225;
|
| 31 |
-
--scrollbar-track-color: var(--secondary-color);
|
| 32 |
-
}
|
| 33 |
-
|
| 34 |
-
/* --- General Body Styling --- */
|
| 35 |
body {
|
| 36 |
-
font-family:
|
| 37 |
-
|
| 38 |
-
color:
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
min-height: 100vh;
|
| 44 |
-
padding: 15px; /* Reduced padding for smaller screens */
|
| 45 |
-
box-sizing: border-box;
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
/* --- Main Chat Container --- */
|
| 49 |
-
.chat-container {
|
| 50 |
-
background-color: var(--secondary-color);
|
| 51 |
-
border-radius: var(--border-radius);
|
| 52 |
-
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
|
| 53 |
-
width: 100%;
|
| 54 |
-
max-width: 750px; /* Slightly wider */
|
| 55 |
-
height: 90vh; /* Adjust height as needed */
|
| 56 |
-
max-height: 800px; /* Max height constraint */
|
| 57 |
-
display: flex;
|
| 58 |
-
flex-direction: column;
|
| 59 |
-
overflow: hidden; /* Contain children */
|
| 60 |
}
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
background-color: var(--primary-color);
|
| 65 |
-
padding: 15px 20px;
|
| 66 |
-
border-bottom: 1px solid var(--border-color);
|
| 67 |
text-align: center;
|
| 68 |
-
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
header h1 {
|
| 72 |
-
margin: 0;
|
| 73 |
-
font-size: 1.3em;
|
| 74 |
-
color: #fff;
|
| 75 |
-
font-weight: 600;
|
| 76 |
}
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
.upload-section {
|
| 80 |
-
padding: 12px 20px; /* Reduced padding */
|
| 81 |
-
border-bottom: 1px solid var(--border-color);
|
| 82 |
display: flex;
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
flex-shrink: 0; /* Prevent shrinking */
|
| 87 |
-
}
|
| 88 |
-
|
| 89 |
-
/* Hide default file input */
|
| 90 |
-
#pdfUpload {
|
| 91 |
-
display: none;
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
/* Style the label like a button */
|
| 95 |
-
.upload-label {
|
| 96 |
-
background-color: var(--accent-color);
|
| 97 |
-
color: white;
|
| 98 |
-
padding: 8px 15px;
|
| 99 |
-
border-radius: 5px;
|
| 100 |
-
cursor: pointer;
|
| 101 |
-
transition: background-color 0.2s ease, opacity 0.2s ease;
|
| 102 |
-
font-size: 0.9em;
|
| 103 |
-
white-space: nowrap;
|
| 104 |
-
display: inline-flex;
|
| 105 |
-
align-items: center;
|
| 106 |
-
gap: 8px; /* Space between icon and text */
|
| 107 |
}
|
| 108 |
-
|
| 109 |
-
.upload-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
opacity: 0.6;
|
| 114 |
-
cursor: not-allowed;
|
| 115 |
-
}
|
| 116 |
-
|
| 117 |
-
#uploadStatus {
|
| 118 |
-
font-size: 0.85em;
|
| 119 |
-
color: var(--text-muted-color);
|
| 120 |
-
flex-grow: 1; /* Take remaining space */
|
| 121 |
-
overflow: hidden;
|
| 122 |
-
text-overflow: ellipsis;
|
| 123 |
-
white-space: nowrap;
|
| 124 |
-
line-height: 1.3;
|
| 125 |
-
}
|
| 126 |
-
#uploadStatus i { /* Style icons in status */
|
| 127 |
-
margin-right: 5px;
|
| 128 |
-
}
|
| 129 |
-
|
| 130 |
-
/* --- Chat Area --- */
|
| 131 |
-
#chat {
|
| 132 |
-
flex-grow: 1; /* Take available space */
|
| 133 |
-
overflow-y: auto; /* Enable vertical scrolling */
|
| 134 |
padding: 20px;
|
|
|
|
| 135 |
display: flex;
|
| 136 |
flex-direction: column;
|
| 137 |
-
gap: 18px; /* Increased space between messages */
|
| 138 |
-
}
|
| 139 |
-
|
| 140 |
-
/* Scrollbar styling (Webkit) */
|
| 141 |
-
#chat::-webkit-scrollbar {
|
| 142 |
-
width: 8px;
|
| 143 |
}
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
}
|
| 148 |
-
#chat::-webkit-scrollbar-thumb {
|
| 149 |
-
background-color: var(--scrollbar-thumb-color);
|
| 150 |
-
border-radius: 4px;
|
| 151 |
-
}
|
| 152 |
-
#chat::-webkit-scrollbar-thumb:hover {
|
| 153 |
-
background-color: var(--tertiary-color); /* Slightly lighter on hover */
|
| 154 |
-
}
|
| 155 |
-
/* Scrollbar styling (Firefox) */
|
| 156 |
-
#chat {
|
| 157 |
-
scrollbar-width: thin;
|
| 158 |
-
scrollbar-color: var(--scrollbar-thumb-color) var(--scrollbar-track-color);
|
| 159 |
-
}
|
| 160 |
-
|
| 161 |
-
/* --- Message Styling --- */
|
| 162 |
-
.message {
|
| 163 |
display: flex;
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
line-height: 1.45; /* Improved readability */
|
| 169 |
-
}
|
| 170 |
-
|
| 171 |
-
@keyframes fadeIn {
|
| 172 |
-
to { opacity: 1; }
|
| 173 |
-
}
|
| 174 |
-
|
| 175 |
-
/* Common structure for icon + text block */
|
| 176 |
-
.message-inner-wrapper {
|
| 177 |
-
display: flex;
|
| 178 |
-
gap: 10px; /* Space between icon and text block */
|
| 179 |
-
width: 100%; /* Ensure wrapper takes full width */
|
| 180 |
-
}
|
| 181 |
-
|
| 182 |
-
.sender-icon {
|
| 183 |
-
font-size: 1.1em; /* Adjust icon size */
|
| 184 |
-
color: var(--text-muted-color); /* Default icon color */
|
| 185 |
-
margin-top: 2px; /* Fine-tune vertical alignment */
|
| 186 |
-
flex-shrink: 0; /* Prevent icon from shrinking */
|
| 187 |
}
|
| 188 |
-
|
| 189 |
-
|
| 190 |
display: flex;
|
| 191 |
-
flex-direction: column;
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
}
|
| 210 |
-
|
| 211 |
-
/* User Message Specific Styles */
|
| 212 |
-
.message.user {
|
| 213 |
-
margin-left: auto; /* Align bubble to the right */
|
| 214 |
-
flex-direction: row-reverse; /* Put icon on the right */
|
| 215 |
}
|
| 216 |
-
|
| 217 |
-
|
|
|
|
| 218 |
}
|
| 219 |
-
|
| 220 |
-
|
|
|
|
|
|
|
| 221 |
}
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
}
|
| 226 |
-
.message.user .message-content {
|
| 227 |
-
background-color: var(--user-message-bg);
|
| 228 |
-
color: white; /* Text color for user bubble */
|
| 229 |
-
border-bottom-right-radius: 4px; /* Subtle shape difference */
|
| 230 |
}
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
}
|
| 236 |
-
|
| 237 |
-
|
|
|
|
| 238 |
}
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
background-color: var(--assistant-message-bg);
|
| 244 |
-
border-bottom-left-radius: 4px; /* Subtle shape difference */
|
| 245 |
}
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
text-align: center;
|
| 252 |
-
width: 100%;
|
| 253 |
-
max-width: 100%;
|
| 254 |
-
font-size: 0.9em;
|
| 255 |
-
margin: 8px 0; /* Adjust spacing */
|
| 256 |
-
gap: 0; /* No gap needed */
|
| 257 |
}
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
background: none;
|
| 263 |
-
padding: 0;
|
| 264 |
-
display: inline-block; /* Center the text block */
|
| 265 |
}
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
/* --- Typing Indicator --- */
|
| 275 |
-
.typing-indicator {
|
| 276 |
display: flex;
|
| 277 |
-
|
| 278 |
-
padding:
|
| 279 |
-
opacity: 0;
|
| 280 |
-
transition: opacity 0.3s ease, height 0.3s ease;
|
| 281 |
-
height: 0; /* Start hidden */
|
| 282 |
overflow: hidden;
|
| 283 |
-
flex-shrink: 0; /* Prevent shrinking */
|
| 284 |
-
gap: 8px; /* Space between icon and text/dots */
|
| 285 |
}
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
color: var(--accent-color);
|
| 293 |
}
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
|
|
|
|
|
|
|
|
|
| 298 |
}
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
border-radius: 50%;
|
| 305 |
-
margin: 0 2px;
|
| 306 |
-
animation: typing 1.2s infinite ease-in-out;
|
| 307 |
}
|
| 308 |
-
|
| 309 |
-
.
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
0%, 100% { transform: translateY(0); opacity: 0.5; }
|
| 314 |
-
50% { transform: translateY(-5px); opacity: 1; }
|
| 315 |
}
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
.input-area {
|
| 319 |
display: flex;
|
| 320 |
-
|
| 321 |
-
border-top: 1px solid var(--border-color);
|
| 322 |
-
background-color: var(--secondary-color); /* Match chat bg */
|
| 323 |
-
flex-shrink: 0; /* Prevent shrinking */
|
| 324 |
-
gap: 10px; /* Space between textarea and button */
|
| 325 |
}
|
| 326 |
-
|
| 327 |
-
#
|
| 328 |
flex-grow: 1;
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
border:
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
resize: none; /* Prevent manual resizing */
|
| 335 |
-
font-family: var(--font-family);
|
| 336 |
-
font-size: 0.95em;
|
| 337 |
-
max-height: 120px; /* Limit growth */
|
| 338 |
-
box-sizing: border-box;
|
| 339 |
-
overflow-y: auto; /* Allow scrolling if text exceeds max height */
|
| 340 |
-
line-height: 1.4; /* Match message line height */
|
| 341 |
-
transition: border-color 0.2s ease, box-shadow 0.2s ease;
|
| 342 |
}
|
| 343 |
-
|
| 344 |
-
#
|
| 345 |
outline: none;
|
| 346 |
-
border-color:
|
| 347 |
-
box-shadow: 0 0 0 1px var(--accent-color);
|
| 348 |
}
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
}
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
#sendButton {
|
| 356 |
-
background-color: var(--accent-color);
|
| 357 |
-
color: white;
|
| 358 |
-
border: none;
|
| 359 |
-
border-radius: var(--border-radius);
|
| 360 |
-
padding: 0 15px;
|
| 361 |
-
cursor: pointer;
|
| 362 |
-
font-size: 1.1em; /* Icon size */
|
| 363 |
-
transition: background-color 0.2s ease, opacity 0.2s ease;
|
| 364 |
-
display: flex;
|
| 365 |
-
align-items: center;
|
| 366 |
-
justify-content: center;
|
| 367 |
-
height: 42px; /* Match input height approx */
|
| 368 |
-
width: 45px; /* Fixed width for the button */
|
| 369 |
-
flex-shrink: 0; /* Prevent button from shrinking */
|
| 370 |
}
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
|
|
|
|
|
|
| 374 |
}
|
| 375 |
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 380 |
}
|
| 381 |
-
|
| 382 |
</style>
|
| 383 |
</head>
|
| 384 |
<body>
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
<header>
|
| 389 |
-
<h1>SentryLabs Document Assistant</h1>
|
| 390 |
-
</header>
|
| 391 |
-
|
| 392 |
-
<!-- PDF Upload Section -->
|
| 393 |
<div class="upload-section">
|
| 394 |
-
<
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 401 |
</div>
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
</div>
|
| 415 |
-
</div>
|
| 416 |
</div>
|
| 417 |
</div>
|
| 418 |
-
|
| 419 |
-
<!-- Typing Indicator -->
|
| 420 |
-
<div class="typing-indicator" id="typingIndicator">
|
| 421 |
-
<i class="fas fa-shield-alt sender-icon"></i>
|
| 422 |
-
<span>Sentry is analyzing...</span>
|
| 423 |
-
<div class="dot"></div>
|
| 424 |
-
<div class="dot"></div>
|
| 425 |
-
<div class="dot"></div>
|
| 426 |
-
</div>
|
| 427 |
-
|
| 428 |
-
<!-- User Input Area -->
|
| 429 |
-
<div class="input-area">
|
| 430 |
-
<textarea id="userInput" placeholder="Ask Sentry about the document..." rows="1" disabled></textarea> <!-- Start disabled -->
|
| 431 |
-
<button id="sendButton" title="Send Message" disabled> <!-- Start disabled -->
|
| 432 |
-
<i class="fas fa-paper-plane"></i>
|
| 433 |
-
</button>
|
| 434 |
-
</div>
|
| 435 |
</div>
|
| 436 |
|
| 437 |
-
<!-- JavaScript -->
|
| 438 |
<script>
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
const
|
| 446 |
-
const userInput =
|
| 447 |
-
const sendButton =
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
senderName = 'Sentry';
|
| 470 |
-
senderIconHtml = '<i class="fas fa-shield-alt sender-icon"></i>';
|
| 471 |
-
}
|
| 472 |
-
|
| 473 |
-
let messageHtml;
|
| 474 |
-
|
| 475 |
-
// Handle different message types (normal, error, info)
|
| 476 |
-
if (type === 'error' || type === 'info') {
|
| 477 |
-
messageClass = 'system';
|
| 478 |
-
// Simple centered text for system messages
|
| 479 |
-
messageHtml = `<div class="message-inner-wrapper">
|
| 480 |
-
<div class="message-content ${type}">${sanitizedHtml}</div>
|
| 481 |
-
</div>`;
|
| 482 |
-
} else {
|
| 483 |
-
// Standard message structure with icon, name, content
|
| 484 |
-
const nameHtml = senderName ? `<div class="sender-name">${senderName}</div>` : '';
|
| 485 |
-
messageHtml = `
|
| 486 |
-
<div class="message-inner-wrapper">
|
| 487 |
-
${senderIconHtml}
|
| 488 |
-
<div class="message-text-block">
|
| 489 |
-
${nameHtml}
|
| 490 |
-
<div class="message-content">${sanitizedHtml}</div>
|
| 491 |
-
</div>
|
| 492 |
-
</div>
|
| 493 |
-
`;
|
| 494 |
-
}
|
| 495 |
-
|
| 496 |
-
// Create message element and append to chat
|
| 497 |
-
const messageElement = $(`<div class="message ${messageClass}">${messageHtml}</div>`);
|
| 498 |
-
chatBox.append(messageElement);
|
| 499 |
-
|
| 500 |
-
// Scroll to the bottom of the chat
|
| 501 |
-
scrollToBottom();
|
| 502 |
-
}
|
| 503 |
-
|
| 504 |
-
// Function to scroll chat box to the bottom
|
| 505 |
-
function scrollToBottom() {
|
| 506 |
-
chatBox.animate({ scrollTop: chatBox[0].scrollHeight }, 300);
|
| 507 |
-
}
|
| 508 |
-
|
| 509 |
-
// Function to show/hide typing indicator
|
| 510 |
-
function showTypingIndicator(show) {
|
| 511 |
-
if (show) {
|
| 512 |
-
typingIndicator.addClass('visible');
|
| 513 |
-
} else {
|
| 514 |
-
typingIndicator.removeClass('visible');
|
| 515 |
}
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
function adjustTextareaHeight() {
|
| 522 |
-
const textarea = userInput[0];
|
| 523 |
-
textarea.style.height = 'auto'; // Reset height to calculate scroll height accurately
|
| 524 |
-
// Calculate the height needed for the content, plus a small buffer if desired
|
| 525 |
-
const scrollHeight = textarea.scrollHeight;
|
| 526 |
-
textarea.style.height = scrollHeight + 'px';
|
| 527 |
-
|
| 528 |
-
// Apply max-height constraint from CSS
|
| 529 |
-
const maxHeight = parseInt(userInput.css('max-height'));
|
| 530 |
-
if (scrollHeight > maxHeight) {
|
| 531 |
-
textarea.style.overflowY = 'auto'; // Show scrollbar if content exceeds max height
|
| 532 |
-
} else {
|
| 533 |
-
textarea.style.overflowY = 'hidden'; // Hide scrollbar if content fits
|
| 534 |
}
|
| 535 |
-
}
|
| 536 |
-
|
| 537 |
-
// --- Event Handlers ---
|
| 538 |
-
|
| 539 |
-
// Trigger hidden file input when the styled label is clicked
|
| 540 |
-
uploadLabel.on('click', function() {
|
| 541 |
-
if (!$(this).prop('disabled')) { // Only trigger if not disabled
|
| 542 |
-
pdfUploadInput.click();
|
| 543 |
-
}
|
| 544 |
});
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 553 |
} else {
|
| 554 |
-
|
| 555 |
-
|
| 556 |
}
|
|
|
|
|
|
|
|
|
|
| 557 |
}
|
| 558 |
});
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
// Prevent sending empty messages or if PDF isn't uploaded
|
| 564 |
-
if (message === "" || !pdfUploaded) return;
|
| 565 |
-
|
| 566 |
-
// Display user's message
|
| 567 |
-
addMessage('user', message);
|
| 568 |
-
const currentUserMessage = message; // Store for history pairing
|
| 569 |
-
|
| 570 |
-
// Clear input, disable controls, show typing indicator
|
| 571 |
-
userInput.val('').prop('disabled', true);
|
| 572 |
-
sendButton.prop('disabled', true);
|
| 573 |
-
showTypingIndicator(true);
|
| 574 |
-
adjustTextareaHeight(); // Reset height after clearing
|
| 575 |
-
|
| 576 |
-
// Prepare history for the API (only completed pairs)
|
| 577 |
-
const historyForApi = chatHistory.slice(); // Send a copy
|
| 578 |
-
|
| 579 |
-
// Make the AJAX call to the backend
|
| 580 |
-
$.ajax({
|
| 581 |
-
url: '/ask_question',
|
| 582 |
-
type: 'POST',
|
| 583 |
-
contentType: 'application/json',
|
| 584 |
-
data: JSON.stringify({
|
| 585 |
-
message: currentUserMessage,
|
| 586 |
-
history: historyForApi
|
| 587 |
-
}),
|
| 588 |
-
success: function(response) {
|
| 589 |
-
if (response && response.response) {
|
| 590 |
-
// Display Sentry's response
|
| 591 |
-
addMessage('assistant', response.response);
|
| 592 |
-
// Add the completed user/assistant pair to history
|
| 593 |
-
chatHistory.push([currentUserMessage, response.response]);
|
| 594 |
-
} else {
|
| 595 |
-
// Handle cases where backend might return empty response field
|
| 596 |
-
const errorMsg = "Received an unexpected empty response from Sentry.";
|
| 597 |
-
addMessage('system', errorMsg, 'error');
|
| 598 |
-
// Record the turn with an empty assistant message for history integrity
|
| 599 |
-
chatHistory.push([currentUserMessage, ""]);
|
| 600 |
-
}
|
| 601 |
-
},
|
| 602 |
-
error: function(jqXHR, textStatus, errorThrown) {
|
| 603 |
-
// Display error message in chat
|
| 604 |
-
let errorMsg = 'An error occurred while communicating with Sentry.';
|
| 605 |
-
if (jqXHR.responseJSON && jqXHR.responseJSON.response) { // Check for error in 'response' key first
|
| 606 |
-
errorMsg = jqXHR.responseJSON.response;
|
| 607 |
-
} else if (jqXHR.responseJSON && jqXHR.responseJSON.error) { // Check 'error' key
|
| 608 |
-
errorMsg = jqXHR.responseJSON.error;
|
| 609 |
-
}
|
| 610 |
-
addMessage('system', errorMsg, 'error');
|
| 611 |
-
// Record the turn with an empty assistant message for history integrity
|
| 612 |
-
chatHistory.push([currentUserMessage, ""]);
|
| 613 |
-
},
|
| 614 |
-
complete: function() {
|
| 615 |
-
// Re-enable input, hide typing indicator
|
| 616 |
-
userInput.prop('disabled', false).focus(); // Re-enable and focus
|
| 617 |
-
showTypingIndicator(false);
|
| 618 |
-
// Re-evaluate send button state (might have typed while waiting)
|
| 619 |
-
sendButton.prop('disabled', userInput.val().trim() === '');
|
| 620 |
-
}
|
| 621 |
-
});
|
| 622 |
}
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 631 |
sendMessage();
|
| 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 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
|
| 667 |
-
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
pdfUploadInput.val('');
|
| 689 |
-
}
|
| 690 |
-
});
|
| 691 |
}
|
| 692 |
-
|
| 693 |
-
// --- Initial Page Load Setup ---
|
| 694 |
-
adjustTextareaHeight(); // Initial adjustment for placeholder
|
| 695 |
-
// Initial state is set directly in the HTML (disabled input/button)
|
| 696 |
-
|
| 697 |
});
|
| 698 |
</script>
|
| 699 |
</body>
|
| 700 |
-
</html>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>SentryLabs AI Assistant</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
body {
|
| 9 |
+
font-family: 'Segoe UI', Arial, sans-serif;
|
| 10 |
+
line-height: 1.6;
|
| 11 |
+
color: #333;
|
| 12 |
+
max-width: 1200px;
|
| 13 |
+
margin: 0 auto;
|
| 14 |
+
padding: 20px;
|
| 15 |
+
background-color: #f5f7fa;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
}
|
| 17 |
+
|
| 18 |
+
h1 {
|
| 19 |
+
color: #2c3e50;
|
|
|
|
|
|
|
|
|
|
| 20 |
text-align: center;
|
| 21 |
+
margin-bottom: 30px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
}
|
| 23 |
+
|
| 24 |
+
.container {
|
|
|
|
|
|
|
|
|
|
| 25 |
display: flex;
|
| 26 |
+
gap: 20px;
|
| 27 |
+
height: calc(100vh - 160px);
|
| 28 |
+
min-height: 500px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
}
|
| 30 |
+
|
| 31 |
+
.upload-section {
|
| 32 |
+
flex: 1;
|
| 33 |
+
background: white;
|
| 34 |
+
border-radius: 8px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
padding: 20px;
|
| 36 |
+
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
| 37 |
display: flex;
|
| 38 |
flex-direction: column;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
}
|
| 40 |
+
|
| 41 |
+
.chat-section {
|
| 42 |
+
flex: 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
display: flex;
|
| 44 |
+
flex-direction: column;
|
| 45 |
+
background: white;
|
| 46 |
+
border-radius: 8px;
|
| 47 |
+
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
}
|
| 49 |
+
|
| 50 |
+
#upload-form {
|
| 51 |
display: flex;
|
| 52 |
+
flex-direction: column;
|
| 53 |
+
gap: 15px;
|
| 54 |
+
margin-bottom: 20px;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.dropzone {
|
| 58 |
+
border: 2px dashed #2c3e50;
|
| 59 |
+
border-radius: 8px;
|
| 60 |
+
padding: 40px 20px;
|
| 61 |
+
text-align: center;
|
| 62 |
+
cursor: pointer;
|
| 63 |
+
margin-bottom: 20px;
|
| 64 |
+
background: #f9fafc;
|
| 65 |
+
flex-grow: 1;
|
| 66 |
+
display: flex;
|
| 67 |
+
flex-direction: column;
|
| 68 |
+
justify-content: center;
|
| 69 |
+
align-items: center;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
}
|
| 71 |
+
|
| 72 |
+
.dropzone:hover {
|
| 73 |
+
background: #eef2f7;
|
| 74 |
}
|
| 75 |
+
|
| 76 |
+
.dropzone p {
|
| 77 |
+
margin: 10px 0 0;
|
| 78 |
+
color: #7f8c8d;
|
| 79 |
}
|
| 80 |
+
|
| 81 |
+
input[type="file"] {
|
| 82 |
+
display: none;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
}
|
| 84 |
+
|
| 85 |
+
button {
|
| 86 |
+
background-color: #3498db;
|
| 87 |
+
color: white;
|
| 88 |
+
border: none;
|
| 89 |
+
padding: 10px 15px;
|
| 90 |
+
border-radius: 5px;
|
| 91 |
+
cursor: pointer;
|
| 92 |
+
font-weight: bold;
|
| 93 |
+
transition: background-color 0.3s;
|
| 94 |
}
|
| 95 |
+
|
| 96 |
+
button:hover {
|
| 97 |
+
background-color: #2980b9;
|
| 98 |
}
|
| 99 |
+
|
| 100 |
+
button:disabled {
|
| 101 |
+
background-color: #95a5a6;
|
| 102 |
+
cursor: not-allowed;
|
|
|
|
|
|
|
| 103 |
}
|
| 104 |
+
|
| 105 |
+
#status-message {
|
| 106 |
+
margin-top: 15px;
|
| 107 |
+
padding: 10px;
|
| 108 |
+
border-radius: 5px;
|
| 109 |
text-align: center;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
}
|
| 111 |
+
|
| 112 |
+
.success {
|
| 113 |
+
background-color: #d5f5e3;
|
| 114 |
+
color: #27ae60;
|
|
|
|
|
|
|
|
|
|
| 115 |
}
|
| 116 |
+
|
| 117 |
+
.error {
|
| 118 |
+
background-color: #fadbd8;
|
| 119 |
+
color: #c0392b;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
.chat-container {
|
| 123 |
+
flex-grow: 1;
|
|
|
|
|
|
|
| 124 |
display: flex;
|
| 125 |
+
flex-direction: column;
|
| 126 |
+
padding: 20px;
|
|
|
|
|
|
|
|
|
|
| 127 |
overflow: hidden;
|
|
|
|
|
|
|
| 128 |
}
|
| 129 |
+
|
| 130 |
+
.messages {
|
| 131 |
+
flex-grow: 1;
|
| 132 |
+
overflow-y: auto;
|
| 133 |
+
padding-right: 10px;
|
| 134 |
+
margin-bottom: 20px;
|
|
|
|
| 135 |
}
|
| 136 |
+
|
| 137 |
+
.message {
|
| 138 |
+
margin-bottom: 15px;
|
| 139 |
+
padding: 12px 16px;
|
| 140 |
+
border-radius: 8px;
|
| 141 |
+
max-width: 80%;
|
| 142 |
+
word-wrap: break-word;
|
| 143 |
}
|
| 144 |
+
|
| 145 |
+
.user {
|
| 146 |
+
background-color: #e3f2fd;
|
| 147 |
+
margin-left: auto;
|
| 148 |
+
border-bottom-right-radius: 2px;
|
|
|
|
|
|
|
|
|
|
| 149 |
}
|
| 150 |
+
|
| 151 |
+
.bot {
|
| 152 |
+
background-color: #f1f1f1;
|
| 153 |
+
margin-right: auto;
|
| 154 |
+
border-bottom-left-radius: 2px;
|
|
|
|
|
|
|
| 155 |
}
|
| 156 |
+
|
| 157 |
+
.input-container {
|
|
|
|
| 158 |
display: flex;
|
| 159 |
+
gap: 10px;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
}
|
| 161 |
+
|
| 162 |
+
#user-input {
|
| 163 |
flex-grow: 1;
|
| 164 |
+
padding: 12px;
|
| 165 |
+
border: 1px solid #ddd;
|
| 166 |
+
border-radius: 5px;
|
| 167 |
+
resize: none;
|
| 168 |
+
font-family: inherit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
}
|
| 170 |
+
|
| 171 |
+
#user-input:focus {
|
| 172 |
outline: none;
|
| 173 |
+
border-color: #3498db;
|
|
|
|
| 174 |
}
|
| 175 |
+
|
| 176 |
+
#send-button {
|
| 177 |
+
align-self: flex-end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
}
|
| 179 |
+
|
| 180 |
+
.initial-message {
|
| 181 |
+
text-align: center;
|
| 182 |
+
color: #7f8c8d;
|
| 183 |
+
margin-top: 40px;
|
| 184 |
}
|
| 185 |
|
| 186 |
+
@media (max-width: 768px) {
|
| 187 |
+
.container {
|
| 188 |
+
flex-direction: column;
|
| 189 |
+
height: auto;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
.upload-section, .chat-section {
|
| 193 |
+
width: 100%;
|
| 194 |
+
}
|
| 195 |
}
|
|
|
|
| 196 |
</style>
|
| 197 |
</head>
|
| 198 |
<body>
|
| 199 |
+
<h1>SentryLabs AI Assistant</h1>
|
| 200 |
+
|
| 201 |
+
<div class="container">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
<div class="upload-section">
|
| 203 |
+
<h2>Upload Document</h2>
|
| 204 |
+
<form id="upload-form">
|
| 205 |
+
<div class="dropzone" id="dropzone">
|
| 206 |
+
<svg width="50" height="50" viewBox="0 0 24 24" fill="none" stroke="#2c3e50" stroke-width="2">
|
| 207 |
+
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
|
| 208 |
+
<polyline points="17 8 12 3 7 8"></polyline>
|
| 209 |
+
<line x1="12" y1="3" x2="12" y2="15"></line>
|
| 210 |
+
</svg>
|
| 211 |
+
<p>Drag & drop your PDF or click to browse</p>
|
| 212 |
+
</div>
|
| 213 |
+
<input type="file" id="file-input" accept=".pdf">
|
| 214 |
+
<button type="submit" id="upload-button" disabled>Upload PDF</button>
|
| 215 |
+
</form>
|
| 216 |
+
<div id="status-message"></div>
|
| 217 |
</div>
|
| 218 |
+
|
| 219 |
+
<div class="chat-section">
|
| 220 |
+
<div class="chat-container">
|
| 221 |
+
<div class="messages" id="chat-messages">
|
| 222 |
+
<div class="initial-message">
|
| 223 |
+
<p>Upload a PDF document to start chatting with the AI assistant.</p>
|
| 224 |
+
</div>
|
| 225 |
+
</div>
|
| 226 |
+
<div class="input-container">
|
| 227 |
+
<textarea id="user-input" placeholder="Ask a question about the document..." rows="2" disabled></textarea>
|
| 228 |
+
<button id="send-button" disabled>Send</button>
|
| 229 |
+
</div>
|
|
|
|
|
|
|
| 230 |
</div>
|
| 231 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
</div>
|
| 233 |
|
|
|
|
| 234 |
<script>
|
| 235 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 236 |
+
const dropzone = document.getElementById('dropzone');
|
| 237 |
+
const fileInput = document.getElementById('file-input');
|
| 238 |
+
const uploadForm = document.getElementById('upload-form');
|
| 239 |
+
const uploadButton = document.getElementById('upload-button');
|
| 240 |
+
const statusMessage = document.getElementById('status-message');
|
| 241 |
+
const chatMessages = document.getElementById('chat-messages');
|
| 242 |
+
const userInput = document.getElementById('user-input');
|
| 243 |
+
const sendButton = document.getElementById('send-button');
|
| 244 |
+
|
| 245 |
+
let selectedFile = null;
|
| 246 |
+
|
| 247 |
+
// Dropzone functionality
|
| 248 |
+
dropzone.addEventListener('click', () => fileInput.click());
|
| 249 |
+
|
| 250 |
+
dropzone.addEventListener('dragover', (e) => {
|
| 251 |
+
e.preventDefault();
|
| 252 |
+
dropzone.style.borderColor = '#3498db';
|
| 253 |
+
});
|
| 254 |
+
|
| 255 |
+
dropzone.addEventListener('dragleave', () => {
|
| 256 |
+
dropzone.style.borderColor = '#2c3e50';
|
| 257 |
+
});
|
| 258 |
+
|
| 259 |
+
dropzone.addEventListener('drop', (e) => {
|
| 260 |
+
e.preventDefault();
|
| 261 |
+
dropzone.style.borderColor = '#2c3e50';
|
| 262 |
+
|
| 263 |
+
if (e.dataTransfer.files.length) {
|
| 264 |
+
handleFileSelection(e.dataTransfer.files[0]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
}
|
| 266 |
+
});
|
| 267 |
+
|
| 268 |
+
fileInput.addEventListener('change', () => {
|
| 269 |
+
if (fileInput.files.length) {
|
| 270 |
+
handleFileSelection(fileInput.files[0]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
});
|
| 273 |
+
|
| 274 |
+
function handleFileSelection(file) {
|
| 275 |
+
if (file.type !== 'application/pdf') {
|
| 276 |
+
showStatus('Please select a PDF file.', 'error');
|
| 277 |
+
return;
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
selectedFile = file;
|
| 281 |
+
dropzone.innerHTML = `<p>${file.name}</p>`;
|
| 282 |
+
uploadButton.disabled = false;
|
| 283 |
+
showStatus('', '');
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
// PDF Upload functionality
|
| 287 |
+
uploadForm.addEventListener('submit', async (e) => {
|
| 288 |
+
e.preventDefault();
|
| 289 |
+
|
| 290 |
+
if (!selectedFile) return;
|
| 291 |
+
|
| 292 |
+
const formData = new FormData();
|
| 293 |
+
formData.append('pdf', selectedFile);
|
| 294 |
+
|
| 295 |
+
uploadButton.disabled = true;
|
| 296 |
+
showStatus('Uploading and processing...', '');
|
| 297 |
+
|
| 298 |
+
try {
|
| 299 |
+
const response = await fetch('/upload_pdf', {
|
| 300 |
+
method: 'POST',
|
| 301 |
+
body: formData
|
| 302 |
+
});
|
| 303 |
+
|
| 304 |
+
const result = await response.json();
|
| 305 |
+
|
| 306 |
+
if (response.ok) {
|
| 307 |
+
showStatus(result.message, 'success');
|
| 308 |
+
enableChat();
|
| 309 |
+
|
| 310 |
+
// Clear initial message and add bot welcome
|
| 311 |
+
chatMessages.innerHTML = '';
|
| 312 |
+
addBotMessage("Hello! I've analyzed your document. What would you like to know about it?");
|
| 313 |
} else {
|
| 314 |
+
showStatus(result.error, 'error');
|
| 315 |
+
uploadButton.disabled = false;
|
| 316 |
}
|
| 317 |
+
} catch (error) {
|
| 318 |
+
showStatus('Network error. Please try again.', 'error');
|
| 319 |
+
uploadButton.disabled = false;
|
| 320 |
}
|
| 321 |
});
|
| 322 |
+
|
| 323 |
+
function showStatus(message, type) {
|
| 324 |
+
statusMessage.textContent = message;
|
| 325 |
+
statusMessage.className = type;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
}
|
| 327 |
+
|
| 328 |
+
function enableChat() {
|
| 329 |
+
userInput.disabled = false;
|
| 330 |
+
sendButton.disabled = false;
|
| 331 |
+
userInput.focus();
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
// Chat functionality
|
| 335 |
+
sendButton.addEventListener('click', sendMessage);
|
| 336 |
+
|
| 337 |
+
userInput.addEventListener('keypress', (e) => {
|
| 338 |
+
if (e.key === 'Enter' && !e.shiftKey) {
|
| 339 |
+
e.preventDefault();
|
| 340 |
sendMessage();
|
| 341 |
}
|
| 342 |
});
|
| 343 |
+
|
| 344 |
+
async function sendMessage() {
|
| 345 |
+
const message = userInput.value.trim();
|
| 346 |
+
if (!message) return;
|
| 347 |
+
|
| 348 |
+
// Add user message to chat
|
| 349 |
+
addUserMessage(message);
|
| 350 |
+
userInput.value = '';
|
| 351 |
+
|
| 352 |
+
// Disable input while processing
|
| 353 |
+
userInput.disabled = true;
|
| 354 |
+
sendButton.disabled = true;
|
| 355 |
+
|
| 356 |
+
try {
|
| 357 |
+
const response = await fetch('/ask_question', {
|
| 358 |
+
method: 'POST',
|
| 359 |
+
headers: {
|
| 360 |
+
'Content-Type': 'application/json'
|
| 361 |
+
},
|
| 362 |
+
body: JSON.stringify({ message })
|
| 363 |
+
});
|
| 364 |
+
|
| 365 |
+
const result = await response.json();
|
| 366 |
+
|
| 367 |
+
// Add bot response to chat
|
| 368 |
+
addBotMessage(result.response);
|
| 369 |
+
} catch (error) {
|
| 370 |
+
addBotMessage("I'm sorry, I couldn't process your request. Please try again.");
|
| 371 |
+
} finally {
|
| 372 |
+
// Re-enable input
|
| 373 |
+
userInput.disabled = false;
|
| 374 |
+
sendButton.disabled = false;
|
| 375 |
+
userInput.focus();
|
| 376 |
+
}
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
function addUserMessage(text) {
|
| 380 |
+
const messageDiv = document.createElement('div');
|
| 381 |
+
messageDiv.className = 'message user';
|
| 382 |
+
messageDiv.textContent = text;
|
| 383 |
+
chatMessages.appendChild(messageDiv);
|
| 384 |
+
scrollToBottom();
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
function addBotMessage(text) {
|
| 388 |
+
const messageDiv = document.createElement('div');
|
| 389 |
+
messageDiv.className = 'message bot';
|
| 390 |
+
messageDiv.textContent = text;
|
| 391 |
+
chatMessages.appendChild(messageDiv);
|
| 392 |
+
scrollToBottom();
|
| 393 |
+
}
|
| 394 |
+
|
| 395 |
+
function scrollToBottom() {
|
| 396 |
+
chatMessages.scrollTop = chatMessages.scrollHeight;
|
|
|
|
|
|
|
|
|
|
| 397 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 398 |
});
|
| 399 |
</script>
|
| 400 |
</body>
|
| 401 |
+
</html>
|