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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
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>
|