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
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>PDF Chat Assistant | Interactive RAG</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#4F46E5',
                        secondary: '#818CF8',
                        dark: '#1F2937',
                        light: '#F9FAFB'
                    }
                }
            }
        }
    </script>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
        body {
            font-family: 'Inter', sans-serif;
        }
        .card-shadow {
            box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1);
        }
        .drag-over {
            border: 2px dashed #4F46E5;
            background-color: #818cf820;
        }
        .message-bubble {
            max-width: 85%;
            border-radius: 18px;
            padding: 14px 18px;
        }
        .user-message {
            background-color: #4F46E5;
            color: white;
            border-bottom-right-radius: 5px;
        }
        .bot-message {
            background-color: #E5E7EB;
            color: #1F2937;
            border-bottom-left-radius: 5px;
        }
        .chat-container {
            height: calc(100vh - 220px);
        }
        .pdf-preview {
            height: calc(100vh - 270px);
        }
        @media (max-width: 1024px) {
            .pdf-preview {
                height: 500px;
            }
            .chat-container {
                height: 500px;
            }
        }
        .chat-input:focus {
            outline: none;
            box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.5);
        }
    </style>
</head>
<body class="bg-light">
    <!-- Header -->
    <header class="bg-white py-4 card-shadow">
        <div class="container mx-auto px-4">
            <div class="flex justify-between items-center">
                <div class="flex items-center">
                    <div class="w-10 h-10 bg-primary rounded-full flex items-center justify-center">
                        <i class="fas fa-file-pdf text-white text-xl"></i>
                    </div>
                    <h1 class="text-2xl font-bold text-dark ml-3">PDF Chat Assistant</h1>
                </div>
                <div class="flex items-center space-x-4">
                    <button class="bg-primary text-white px-4 py-2 rounded-lg hover:bg-secondary transition">
                        <i class="fas fa-user mr-2"></i>My Account
                    </button>
                </div>
            </div>
        </div>
    </header>

    <main class="container mx-auto px-4 py-8">
        <div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
            <!-- Left Side: PDF Upload & Preview -->
            <div class="bg-white rounded-xl card-shadow p-6">
                <h2 class="text-xl font-bold text-dark mb-4 flex items-center">
                    <i class="fas fa-cloud-upload-alt text-secondary mr-2"></i> Upload Document
                </h2>
                
                <!-- File Upload Box -->
                <div id="upload-area" class="border-2 border-dashed border-gray-300 rounded-xl p-8 text-center mb-6 cursor-pointer hover:bg-gray-50 transition">
                    <div class="mb-4">
                        <i class="fas fa-file-upload text-4xl text-secondary mb-3"></i>
                        <p class="font-semibold">Drag & Drop your PDF file</p>
                        <p class="text-gray-500 text-sm mt-1">or click to browse</p>
                    </div>
                    <input type="file" id="file-input" accept=".pdf" class="hidden">
                    <button id="browse-btn" class="bg-primary text-white px-4 py-2 rounded-lg hover:bg-secondary transition">
                        Browse Files
                    </button>
                </div>
                
                <!-- File Preview -->
                <div id="file-preview" class="hidden">
                    <div class="flex justify-between items-center mb-4">
                        <h3 class="text-lg font-semibold">Document Preview</h3>
                        <button id="remove-file" class="text-red-500 hover:text-red-700">
                            <i class="fas fa-trash-alt mr-1"></i> Remove
                        </button>
                    </div>
                    
                    <div class="bg-gray-100 rounded-lg overflow-hidden pdf-preview">
                        <div class="flex items-center justify-center h-full">
                            <div class="text-center p-8">
                                <i class="fas fa-file-pdf text-6xl text-red-500 mb-4"></i>
                                <p class="font-semibold" id="file-name">document.pdf</p>
                                <p class="text-gray-600 mt-2">PDF preview would appear here</p>
                                <div class="mt-6 flex justify-center">
                                    <div class="w-24 h-32 bg-white border flex items-center justify-center mx-1">
                                        <p class="text-xs">Page 1</p>
                                    </div>
                                    <div class="w-24 h-32 bg-white border flex items-center justify-center mx-1">
                                        <p class="text-xs">Page 2</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="mt-4 flex justify-between">
                        <div class="text-sm text-gray-600">
                            <span>Processing:</span>
                            <span id="processing-text">Extracting content...</span>
                        </div>
                        <div class="flex">
                            <div class="w-8 h-8 rounded-full bg-green-500 flex items-center justify-center">
                                <i class="fas fa-check text-white text-sm"></i>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- Sample Documents -->
                <div class="mt-8">
                    <h3 class="font-medium text-gray-700 mb-3 flex items-center">
                        <i class="fas fa-lightbulb text-yellow-400 mr-2"></i> Sample Documents
                    </h3>
                    <div class="grid grid-cols-2 gap-4">
                        <button class="bg-gray-100 hover:bg-gray-200 p-4 rounded-lg flex items-center">
                            <i class="fas fa-file-alt text-blue-500 mr-2"></i>
                            <span class="truncate">Annual_Report.pdf</span>
                        </button>
                        <button class="bg-gray-100 hover:bg-gray-200 p-4 rounded-lg flex items-center">
                            <i class="fas fa-file-alt text-green-500 mr-2"></i>
                            <span class="truncate">Research_Paper.pdf</span>
                        </button>
                    </div>
                </div>
            </div>
            
            <!-- Right Side: Chat Interface -->
            <div class="bg-white rounded-xl card-shadow overflow-hidden flex flex-col">
                <div class="p-6 border-b">
                    <h2 class="text-xl font-bold text-dark flex items-center">
                        <i class="fas fa-comments text-secondary mr-2"></i> Document Chat
                    </h2>
                    <div class="text-sm text-gray-600 mt-1">Ask questions about your uploaded document</div>
                </div>
                
                <!-- Chat Messages Container -->
                <div id="chat-container" class="chat-container overflow-y-auto p-6 bg-gray-50 flex-grow">
                    <!-- Welcome message -->
                    <div class="flex mb-6">
                        <div class="flex-shrink-0">
                            <div class="w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center">
                                <i class="fas fa-robot text-secondary"></i>
                            </div>
                        </div>
                        <div class="ml-4">
                            <div class="bot-message message-bubble">
                                <p class="font-bold text-secondary mb-1">PDF Assistant</p>
                                <p>Hello! I'm your document assistant. Upload a PDF file to get started.</p>
                                <p class="mt-2">You can ask me questions like:</p>
                                <ul class="list-disc pl-5 mt-2 space-y-1">
                                    <li>Summarize this document</li>
                                    <li>What's the main point on page 5?</li>
                                    <li>Find key statistics in section 3</li>
                                </ul>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Chat messages will appear here dynamically -->
                </div>
                
                <!-- Chat Input -->
                <div class="p-6 bg-white border-t">
                    <div id="upload-required" class="bg-blue-50 text-blue-800 rounded-lg p-3 mb-4 flex items-center">
                        <i class="fas fa-info-circle mr-2"></i>
                        <span>Upload a PDF document to start chatting</span>
                    </div>
                    <div id="chat-input-area" class="hidden">
                        <div class="flex items-center">
                            <input 
                                id="chat-input" 
                                type="text" 
                                placeholder="Ask a question about your document..."
                                class="flex-grow border border-gray-300 rounded-l-lg p-3 chat-input focus:border-primary"
                            >
                            <button id="send-btn" class="bg-primary text-white px-5 py-3 rounded-r-lg hover:bg-secondary transition">
                                <i class="fas fa-paper-plane"></i>
                            </button>
                        </div>
                        <div class="flex justify-between mt-3">
                            <div class="flex space-x-4">
                                <button class="text-sm text-gray-600 hover:text-primary">
                                    <i class="fas fa-sync-alt mr-1"></i> Reindex document
                                </button>
                                <button class="text-sm text-gray-600 hover:text-primary">
                                    <i class="fas fa-file-download mr-1"></i> Export chat
                                </button>
                            </div>
                            <button id="suggest-btn" class="text-sm text-primary">
                                <i class="fas fa-wand-magic-sparkles mr-1"></i> Suggest questions
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </main>

    <!-- Footer -->
    <footer class="bg-white py-8 mt-12 border-t">
        <div class="container mx-auto px-4">
            <div class="text-center">
                <div class="flex justify-center space-x-6 mb-4">
                    <a href="#" class="text-gray-600 hover:text-primary">
                        <i class="fab fa-twitter"></i>
                    </a>
                    <a href="#" class="text-gray-600 hover:text-primary">
                        <i class="fab fa-github"></i>
                    </a>
                    <a href="#" class="text-gray-600 hover:text-primary">
                        <i class="fab fa-linkedin"></i>
                    </a>
                </div>
                <p class="text-gray-600">© 2023 PDF Chat Assistant. All rights reserved.</p>
                <p class="text-gray-500 text-sm mt-2">Built with Retrieval Augmented Generation technology</p>
            </div>
        </div>
    </footer>

    <!-- JavaScript for interactivity -->
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // Elements
            const uploadArea = document.getElementById('upload-area');
            const fileInput = document.getElementById('file-input');
            const browseBtn = document.getElementById('browse-btn');
            const filePreview = document.getElementById('file-preview');
            const removeFile = document.getElementById('remove-file');
            const fileName = document.getElementById('file-name');
            const chatInputArea = document.getElementById('chat-input-area');
            const uploadRequired = document.getElementById('upload-required');
            const chatInput = document.getElementById('chat-input');
            const sendBtn = document.getElementById('send-btn');
            const chatContainer = document.getElementById('chat-container');
            const suggestBtn = document.getElementById('suggest-btn');
            
            // Browse button click event
            browseBtn.addEventListener('click', () => fileInput.click());
            
            // File input change event
            fileInput.addEventListener('change', function() {
                if (this.files && this.files[0]) {
                    handleFileUpload(this.files[0]);
                }
            });
            
            // Drag and drop events
            ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
                uploadArea.addEventListener(eventName, preventDefaults, false);
            });
            
            function preventDefaults(e) {
                e.preventDefault();
                e.stopPropagation();
            }
            
            ['dragenter', 'dragover'].forEach(eventName => {
                uploadArea.addEventListener(eventName, () => uploadArea.classList.add('drag-over'));
            });
            
            ['dragleave', 'drop'].forEach(eventName => {
                uploadArea.addEventListener(eventName, () => uploadArea.classList.remove('drag-over'));
            });
            
            uploadArea.addEventListener('drop', (e) => {
                const dt = e.dataTransfer;
                const file = dt.files[0];
                handleFileUpload(file);
            });
            
            // File upload handler
            function handleFileUpload(file) {
                if (file && file.type === 'application/pdf') {
                    fileName.textContent = file.name;
                    filePreview.classList.remove('hidden');
                    uploadRequired.classList.add('hidden');
                    chatInputArea.classList.remove('hidden');
                    
                    // Simulate processing delay
                    const processingText = document.getElementById('processing-text');
                    processingText.textContent = 'Extracting content...';
                    
                    setTimeout(() => {
                        processingText.textContent = 'Document ready for questions';
                        addBotMessage(`Your document "${file.name}" has been processed successfully. How can I help you with this PDF?`);
                    }, 3000);
                } else {
                    alert('Please select a valid PDF file.');
                }
            }
            
            // Remove file handler
            removeFile.addEventListener('click', () => {
                filePreview.classList.add('hidden');
                uploadRequired.classList.remove('hidden');
                chatInputArea.classList.add('hidden');
                fileInput.value = '';
            });
            
            // Send button click event
            sendBtn.addEventListener('click', sendMessage);
            
            // Enter key in chat input
            chatInput.addEventListener('keypress', (e) => {
                if (e.key === 'Enter') {
                    sendMessage();
                }
            });
            
            // Send message function
            function sendMessage() {
                const message = chatInput.value.trim();
                if (!message) return;
                
                addUserMessage(message);
                chatInput.value = '';
                
                // Simulate bot typing
                setTimeout(() => {
                    simulateBotReply(message);
                }, 1000);
            }
            
            // Add user message to chat
            function addUserMessage(message) {
                const messageElement = `
                    <div class="flex justify-end mb-6">
                        <div class="flex flex-col items-end">
                            <div class="user-message message-bubble">
                                ${message}
                            </div>
                        </div>
                        <div class="flex-shrink-0 ml-4">
                            <div class="w-10 h-10 bg-primary rounded-full flex items-center justify-center">
                                <i class="fas fa-user text-white"></i>
                            </div>
                        </div>
                    </div>
                `;
                chatContainer.insertAdjacentHTML('beforeend', messageElement);
                chatContainer.scrollTop = chatContainer.scrollHeight;
            }
            
            // Add bot message to chat
            function addBotMessage(message) {
                const messageElement = `
                    <div class="flex mb-6">
                        <div class="flex-shrink-0">
                            <div class="w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center">
                                <i class="fas fa-robot text-secondary"></i>
                            </div>
                        </div>
                        <div class="ml-4">
                            <div class="bot-message message-bubble">
                                <p class="font-bold text-secondary mb-1">PDF Assistant</p>
                                <p>${message}</p>
                            </div>
                        </div>
                    </div>
                `;
                chatContainer.insertAdjacentHTML('beforeend', messageElement);
                chatContainer.scrollTop = chatContainer.scrollHeight;
            }
            
            // Function to simulate bot responses
            function simulateBotReply(userMessage) {
                // Simple response logic for demo
                let response;
                const lowerMessage = userMessage.toLowerCase();
                
                if (lowerMessage.includes('hello') || lowerMessage.includes('hi')) {
                    response = "Hello! How can I assist you with your document?";
                } else if (lowerMessage.includes('summary') || lowerMessage.includes('summarize')) {
                    response = "Based on the document, the main points are: <br><br>1. The report highlights significant growth in the technology sector this year.<br>2. Cybersecurity investments have increased by 32% year-over-year.<br>3. Cloud migration remains a top priority for 75% of enterprises.";
                } else if (lowerMessage.includes('page') || lowerMessage.includes('section')) {
                    const pageNum = userMessage.match(/\d+/);
                    response = pageNum 
                        ? `On page ${pageNum[0]}, the document discusses key trends in AI adoption across industries. According to the text, over 60% of companies have implemented at least one AI solution, with healthcare leading adoption at 78%.`
                        : `The section discusses evolving consumer preferences in digital services, highlighting increased demand for personalization and seamless cross-device experiences.`;
                } else if (lowerMessage.includes('statistic') || lowerMessage.includes('data')) {
                    response = "The document contains several key statistics:<br><br>• Revenue growth projection for 2024 is 14.5%<br>• Customer satisfaction improved to 92%<br>• Employee retention rates increased by 17 percentage points";
                } else {
                    response = "Based on the document you uploaded, I can provide the following insights:<br><br>• The main theme appears to be digital transformation strategies<br>• There's a strong focus on cloud migration benefits<br>• Chapter 3 contains detailed case studies with measurable results<br><br>Can I help you explore a specific section more deeply?";
                }
                
                addBotMessage(response);
            }
            
            // Suggest questions button
            suggestBtn.addEventListener('click', () => {
                const suggestions = `
                    <div class="flex mb-6">
                        <div class="flex-shrink-0">
                            <div class="w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center">
                                <i class="fas fa-robot text-secondary"></i>
                            </div>
                        </div>
                        <div class="ml-4">
                            <div class="bot-message message-bubble">
                                <p class="font-bold text-secondary mb-1">PDF Assistant</p>
                                <p>Here are some questions you might ask about your document:</p>
                                <div class="grid grid-cols-1 gap-2 mt-3">
                                    <button class="suggestion-btn bg-white hover:bg-gray-100 border border-gray-300 rounded-lg p-2 text-left text-sm text-gray-700">
                                        <i class="fas fa-question-circle text-secondary mr-2"></i>Summarize the key findings
                                    </button>
                                    <button class="suggestion-btn bg-white hover:bg-gray-100 border border-gray-300 rounded-lg p-2 text-left text-sm text-gray-700">
                                        <i class="fas fa-question-circle text-secondary mr-2"></i>What methodology was used in the research?
                                    </button>
                                    <button class="suggestion-btn bg-white hover:bg-gray-100 border border-gray-300 rounded-lg p-2 text-left text-sm text-gray-700">
                                        <i class="fas fa-question-circle text-secondary mr-2"></i>List the recommendations from conclusion
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                `;
                
                chatContainer.insertAdjacentHTML('beforeend', suggestions);
                chatContainer.scrollTop = chatContainer.scrollHeight;
                
                // Add event listeners to suggestion buttons
                document.querySelectorAll('.suggestion-btn').forEach(button => {
                    button.addEventListener('click', (e) => {
                        const text = e.target.textContent || e.target.innerText;
                        chatInput.value = text.split(' ').slice(1).join(' ');
                        chatInput.focus();
                    });
                });
            });
        });
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=raktimhugging/rag-v1" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>