File size: 34,623 Bytes
2a49eb8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
659
660
661
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>PDF Insight - AI-Powered Document Analysis</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">
    <style>
        .dropzone {
            border: 3px dashed #9CA3AF;
            transition: all 0.3s ease;
        }
        .dropzone.active {
            border-color: #3B82F6;
            background-color: #EFF6FF;
        }
        .pdf-container {
            position: relative;
            min-height: 100vh;
        }
        .pdf-viewer {
            width: 70%;
            height: 100vh;
            overflow-y: auto;
            position: relative;
        }
        .annotation-sidebar {
            width: 30%;
            height: 100vh;
            overflow-y: auto;
            border-left: 1px solid #E5E7EB;
            background-color: #F9FAFB;
        }
        .pdf-page {
            margin-bottom: 2rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
            position: relative;
        }
        .highlight {
            background-color: rgba(255, 255, 0, 0.3);
            cursor: pointer;
            transition: all 0.2s ease;
        }
        .highlight:hover {
            background-color: rgba(255, 255, 0, 0.5);
        }
        .annotation-marker {
            position: absolute;
            right: -15px;
            top: 50%;
            transform: translateY(-50%);
            width: 10px;
            height: 10px;
            background-color: #3B82F6;
            border-radius: 50%;
            cursor: pointer;
        }
        .annotation-popup {
            position: absolute;
            right: -320px;
            width: 300px;
            background-color: white;
            border: 1px solid #E5E7EB;
            border-radius: 0.5rem;
            padding: 1rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
            z-index: 10;
        }
        .loading-bar {
            height: 4px;
            background-color: #3B82F6;
            width: 0%;
            transition: width 0.3s ease;
        }
        @keyframes pulse {
            0%, 100% {
                opacity: 1;
            }
            50% {
                opacity: 0.5;
            }
        }
        .pulse {
            animation: pulse 2s infinite;
        }
    </style>
</head>
<body class="bg-gray-50">
    <div class="loading-bar"></div>
    
    <div id="app" class="min-h-screen">
        <!-- Header -->
        <header class="bg-white shadow-sm">
            <div class="max-w-7xl mx-auto px-4 py-4 sm:px-6 lg:px-8 flex justify-between items-center">
                <div class="flex items-center">
                    <i class="fas fa-brain text-blue-500 text-2xl mr-3"></i>
                    <h1 class="text-xl font-bold text-gray-800">PDF Insight</h1>
                </div>
                <div class="flex items-center space-x-4">
                    <button id="uploadBtn" class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-md flex items-center">
                        <i class="fas fa-upload mr-2"></i> Upload PDF
                    </button>
                    <input type="file" id="fileInput" class="hidden" accept=".pdf">
                    <button id="analyzeBtn" class="bg-green-500 hover:bg-green-600 text-white px-4 py-2 rounded-md flex items-center hidden">
                        <i class="fas fa-robot mr-2"></i> Analyze Document
                    </button>
                </div>
            </div>
        </header>

        <!-- Main Content -->
        <main class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
            <!-- Dropzone Section (shown when no PDF is loaded) -->
            <div id="dropzoneSection" class="flex flex-col items-center justify-center py-20">
                <div class="dropzone w-full max-w-3xl rounded-xl p-12 text-center cursor-pointer" id="dropzone">
                    <div class="flex flex-col items-center justify-center">
                        <i class="fas fa-file-pdf text-5xl text-gray-400 mb-4"></i>
                        <h2 class="text-2xl font-semibold text-gray-700 mb-2">Drag & Drop your PDF here</h2>
                        <p class="text-gray-500 mb-6">or click to browse files</p>
                        <div class="bg-blue-50 text-blue-700 px-4 py-2 rounded-md inline-flex items-center">
                            <i class="fas fa-info-circle mr-2"></i>
                            <span>Supported: PDF files up to 50MB</span>
                        </div>
                    </div>
                </div>
                <div class="mt-8 text-center max-w-2xl">
                    <h3 class="text-lg font-medium text-gray-700 mb-3">How it works</h3>
                    <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                        <div class="bg-white p-4 rounded-lg shadow-sm">
                            <div class="bg-blue-100 text-blue-600 w-12 h-12 rounded-full flex items-center justify-center mb-3 mx-auto">
                                <i class="fas fa-upload"></i>
                            </div>
                            <h4 class="font-medium mb-1">Upload PDF</h4>
                            <p class="text-sm text-gray-500">Drag & drop or select your document</p>
                        </div>
                        <div class="bg-white p-4 rounded-lg shadow-sm">
                            <div class="bg-blue-100 text-blue-600 w-12 h-12 rounded-full flex items-center justify-center mb-3 mx-auto">
                                <i class="fas fa-microchip"></i>
                            </div>
                            <h4 class="font-medium mb-1">AI Processing</h4>
                            <p class="text-sm text-gray-500">We analyze text with OCR and AI</p>
                        </div>
                        <div class="bg-white p-4 rounded-lg shadow-sm">
                            <div class="bg-blue-100 text-blue-600 w-12 h-12 rounded-full flex items-center justify-center mb-3 mx-auto">
                                <i class="fas fa-comment-dots"></i>
                            </div>
                            <h4 class="font-medium mb-1">Get Insights</h4>
                            <p class="text-sm text-gray-500">View AI annotations in the margins</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- PDF Viewer Section (shown after PDF is loaded) -->
            <div id="pdfViewerSection" class="hidden">
                <div class="flex justify-between items-center mb-6">
                    <div>
                        <h2 id="pdfTitle" class="text-xl font-semibold text-gray-800 truncate max-w-md"></h2>
                        <p id="pdfInfo" class="text-sm text-gray-500"></p>
                    </div>
                    <div class="flex space-x-3">
                        <button id="downloadBtn" class="bg-gray-100 hover:bg-gray-200 text-gray-700 px-4 py-2 rounded-md flex items-center">
                            <i class="fas fa-download mr-2"></i> Download
                        </button>
                        <button id="newDocumentBtn" class="bg-gray-100 hover:bg-gray-200 text-gray-700 px-4 py-2 rounded-md flex items-center">
                            <i class="fas fa-file mr-2"></i> New Document
                        </button>
                    </div>
                </div>

                <div class="pdf-container flex">
                    <div class="pdf-viewer bg-white p-6" id="pdfViewer">
                        <!-- PDF pages will be rendered here -->
                        <div class="flex items-center justify-center h-full">
                            <div class="text-center">
                                <div class="pulse">
                                    <i class="fas fa-spinner fa-spin text-4xl text-blue-500 mb-4"></i>
                                </div>
                                <h3 class="text-lg font-medium text-gray-700">Processing PDF...</h3>
                                <p class="text-gray-500 mt-2">This may take a few moments</p>
                            </div>
                        </div>
                    </div>
                    <div class="annotation-sidebar p-6" id="annotationSidebar">
                        <div class="flex items-center justify-between mb-6">
                            <h3 class="text-lg font-semibold text-gray-800">AI Annotations</h3>
                            <div class="flex items-center space-x-2">
                                <div class="relative">
                                    <button id="filterBtn" class="bg-gray-100 hover:bg-gray-200 text-gray-700 px-3 py-1 rounded-md flex items-center text-sm">
                                        <i class="fas fa-filter mr-2"></i> Filter
                                    </button>
                                    <div id="filterDropdown" class="absolute right-0 mt-2 w-48 bg-white rounded-md shadow-lg z-10 hidden">
                                        <div class="py-1">
                                            <label class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 cursor-pointer">
                                                <input type="checkbox" class="mr-2" checked> Key Terms
                                            </label>
                                            <label class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 cursor-pointer">
                                                <input type="checkbox" class="mr-2" checked> Definitions
                                            </label>
                                            <label class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 cursor-pointer">
                                                <input type="checkbox" class="mr-2" checked> References
                                            </label>
                                        </div>
                                    </div>
                                </div>
                                <button id="exportAnnotationsBtn" class="bg-gray-100 hover:bg-gray-200 text-gray-700 px-3 py-1 rounded-md flex items-center text-sm">
                                    <i class="fas fa-file-export mr-2"></i> Export
                                </button>
                            </div>
                        </div>
                        
                        <div id="annotationsList">
                            <div class="bg-blue-50 border-l-4 border-blue-500 p-4 mb-4 rounded">
                                <div class="flex justify-between items-start">
                                    <div>
                                        <h4 class="font-medium text-blue-800">Document Summary</h4>
                                        <p class="text-sm text-gray-600 mt-1">Upload a PDF to see AI-generated annotations appear here.</p>
                                    </div>
                                    <span class="bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded-full">Summary</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
    </div>

    <!-- Processing Modal -->
    <div id="processingModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
        <div class="bg-white rounded-lg p-6 max-w-md w-full">
            <div class="text-center">
                <div class="pulse mb-4">
                    <i class="fas fa-robot text-5xl text-blue-500"></i>
                </div>
                <h3 class="text-xl font-medium text-gray-800 mb-2">Analyzing Document</h3>
                <p class="text-gray-600 mb-4">Our AI is reading your document and generating insights. This may take a moment...</p>
                <div class="w-full bg-gray-200 rounded-full h-2.5 mb-4">
                    <div id="progressBar" class="bg-blue-600 h-2.5 rounded-full" style="width: 0%"></div>
                </div>
                <p id="processingStatus" class="text-sm text-gray-500">Initializing OCR processing...</p>
            </div>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // DOM Elements
            const dropzone = document.getElementById('dropzone');
            const fileInput = document.getElementById('fileInput');
            const uploadBtn = document.getElementById('uploadBtn');
            const analyzeBtn = document.getElementById('analyzeBtn');
            const dropzoneSection = document.getElementById('dropzoneSection');
            const pdfViewerSection = document.getElementById('pdfViewerSection');
            const pdfViewer = document.getElementById('pdfViewer');
            const pdfTitle = document.getElementById('pdfTitle');
            const pdfInfo = document.getElementById('pdfInfo');
            const annotationsList = document.getElementById('annotationsList');
            const newDocumentBtn = document.getElementById('newDocumentBtn');
            const processingModal = document.getElementById('processingModal');
            const progressBar = document.getElementById('progressBar');
            const processingStatus = document.getElementById('processingStatus');
            const loadingBar = document.querySelector('.loading-bar');
            const filterBtn = document.getElementById('filterBtn');
            const filterDropdown = document.getElementById('filterDropdown');

            // Event Listeners
            uploadBtn.addEventListener('click', () => fileInput.click());
            fileInput.addEventListener('change', handleFileSelect);
            dropzone.addEventListener('dragover', handleDragOver);
            dropzone.addEventListener('dragleave', handleDragLeave);
            dropzone.addEventListener('drop', handleDrop);
            analyzeBtn.addEventListener('click', analyzeDocument);
            newDocumentBtn.addEventListener('click', resetDocument);
            filterBtn.addEventListener('click', toggleFilterDropdown);

            // Close filter dropdown when clicking outside
            document.addEventListener('click', (e) => {
                if (!filterBtn.contains(e.target) && !filterDropdown.contains(e.target)) {
                    filterDropdown.classList.add('hidden');
                }
            });

            // Functions
            function handleDragOver(e) {
                e.preventDefault();
                e.stopPropagation();
                dropzone.classList.add('active');
            }

            function handleDragLeave(e) {
                e.preventDefault();
                e.stopPropagation();
                dropzone.classList.remove('active');
            }

            function handleDrop(e) {
                e.preventDefault();
                e.stopPropagation();
                dropzone.classList.remove('active');
                
                const files = e.dataTransfer.files;
                if (files.length) {
                    handleFile(files[0]);
                }
            }

            function handleFileSelect(e) {
                if (e.target.files.length) {
                    handleFile(e.target.files[0]);
                }
            }

            function handleFile(file) {
                if (file.type !== 'application/pdf') {
                    showToast('Please upload a PDF file', 'error');
                    return;
                }

                if (file.size > 50 * 1024 * 1024) { // 50MB limit
                    showToast('File size exceeds 50MB limit', 'error');
                    return;
                }

                // Show loading state
                loadingBar.style.width = '30%';
                
                // Simulate file processing
                setTimeout(() => {
                    loadingBar.style.width = '100%';
                    
                    // Display PDF info
                    pdfTitle.textContent = file.name;
                    pdfInfo.textContent = `${(file.size / 1024 / 1024).toFixed(2)} MB • Uploaded ${new Date().toLocaleDateString()}`;
                    
                    // Show the PDF viewer section
                    dropzoneSection.classList.add('hidden');
                    pdfViewerSection.classList.remove('hidden');
                    analyzeBtn.classList.remove('hidden');
                    
                    // Simulate PDF rendering
                    setTimeout(() => {
                        renderSamplePDF();
                        loadingBar.style.width = '0%';
                    }, 500);
                }, 1000);
            }

            function renderSamplePDF() {
                // In a real app, you would use PDF.js or similar to render the actual PDF
                // Here we're just creating a sample representation
                pdfViewer.innerHTML = '';
                
                // Create 3 sample pages
                for (let i = 1; i <= 3; i++) {
                    const page = document.createElement('div');
                    page.className = 'pdf-page bg-white p-8 relative';
                    
                    // Page header
                    const pageHeader = document.createElement('div');
                    pageHeader.className = 'flex justify-between items-center mb-6 pb-2 border-b border-gray-200';
                    pageHeader.innerHTML = `
                        <span class="text-sm font-medium text-gray-500">Page ${i}</span>
                        <span class="text-xs bg-gray-100 text-gray-600 px-2 py-1 rounded">${i}/3</span>
                    `;
                    page.appendChild(pageHeader);
                    
                    // Page content
                    const pageContent = document.createElement('div');
                    pageContent.className = 'text-gray-800 leading-relaxed';
                    
                    // Add sample text with highlights
                    const paragraphs = [
                        "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam in dui mauris. Vivamus hendrerit arcu sed erat molestie vehicula. Sed auctor neque eu tellus rhoncus ut eleifend nibh porttitor.",
                        "The concept of artificial intelligence (AI) refers to the simulation of human intelligence in machines. These systems are designed to think like humans and mimic their actions.",
                        "Machine learning is a subset of AI that focuses on building systems that learn—or improve performance—based on the data they consume. Deep learning is a further subset that uses neural networks with many layers."
                    ];
                    
                    paragraphs.forEach((text, idx) => {
                        const p = document.createElement('p');
                        p.className = 'mb-4';
                        
                        // Add highlights to some words
                        if (i === 1 && idx === 1) {
                            p.innerHTML = text.replace('artificial intelligence (AI)', '<span class="highlight" data-term="AI" data-page="1">artificial intelligence (AI)</span>');
                            
                            // Add annotation marker
                            const marker = document.createElement('div');
                            marker.className = 'annotation-marker';
                            marker.setAttribute('data-term', 'AI');
                            marker.addEventListener('click', () => showAnnotationPopup(marker, 'AI'));
                            p.appendChild(marker);
                        } 
                        else if (i === 2 && idx === 2) {
                            p.innerHTML = text.replace('Machine learning', '<span class="highlight" data-term="Machine Learning" data-page="2">Machine learning</span>')
                                            .replace('Deep learning', '<span class="highlight" data-term="Deep Learning" data-page="2">Deep learning</span>');
                            
                            // Add annotation markers
                            const mlMarker = document.createElement('div');
                            mlMarker.className = 'annotation-marker';
                            mlMarker.setAttribute('data-term', 'Machine Learning');
                            mlMarker.addEventListener('click', () => showAnnotationPopup(mlMarker, 'Machine Learning'));
                            p.appendChild(mlMarker);
                            
                            const dlMarker = document.createElement('div');
                            dlMarker.className = 'annotation-marker';
                            dlMarker.style.top = '70%';
                            dlMarker.setAttribute('data-term', 'Deep Learning');
                            dlMarker.addEventListener('click', () => showAnnotationPopup(dlMarker, 'Deep Learning'));
                            p.appendChild(dlMarker);
                        }
                        else {
                            p.textContent = text;
                        }
                        
                        pageContent.appendChild(p);
                    });
                    
                    page.appendChild(pageContent);
                    pdfViewer.appendChild(page);
                }
                
                // Add click handlers for highlights
                document.querySelectorAll('.highlight').forEach(highlight => {
                    highlight.addEventListener('click', function() {
                        const term = this.getAttribute('data-term');
                        showAnnotationPopup(this, term);
                    });
                });
            }

            function analyzeDocument() {
                // Show processing modal
                processingModal.classList.remove('hidden');
                
                // Simulate processing steps
                const steps = [
                    "Extracting text with OCR...",
                    "Identifying key terms and concepts...",
                    "Analyzing document structure...",
                    "Generating AI insights...",
                    "Finalizing annotations..."
                ];
                
                let currentStep = 0;
                const interval = setInterval(() => {
                    if (currentStep < steps.length) {
                        const progress = ((currentStep + 1) / steps.length) * 100;
                        progressBar.style.width = `${progress}%`;
                        processingStatus.textContent = steps[currentStep];
                        currentStep++;
                    } else {
                        clearInterval(interval);
                        
                        // Simulate completion
                        setTimeout(() => {
                            processingModal.classList.add('hidden');
                            showToast('Analysis complete!', 'success');
                            populateAnnotations();
                        }, 1000);
                    }
                }, 1500);
            }

            function populateAnnotations() {
                // In a real app, this would come from the AI analysis
                const annotations = [
                    {
                        id: 1,
                        term: "AI",
                        page: 1,
                        type: "definition",
                        content: "Artificial Intelligence (AI) refers to machines designed to perform tasks that typically require human intelligence, such as visual perception, speech recognition, and decision-making.",
                        confidence: 0.92
                    },
                    {
                        id: 2,
                        term: "Machine Learning",
                        page: 2,
                        type: "definition",
                        content: "Machine Learning is a subset of AI that enables systems to automatically learn and improve from experience without being explicitly programmed.",
                        confidence: 0.95
                    },
                    {
                        id: 3,
                        term: "Deep Learning",
                        page: 2,
                        type: "definition",
                        content: "Deep Learning uses artificial neural networks with multiple layers to progressively extract higher-level features from raw input, mimicking how the human brain processes information.",
                        confidence: 0.89
                    },
                    {
                        id: 4,
                        term: "Document Summary",
                        page: "all",
                        type: "summary",
                        content: "This document discusses fundamental concepts in artificial intelligence, including machine learning and deep learning. It provides definitions and explains the relationships between these technologies.",
                        confidence: 0.87
                    }
                ];
                
                // Clear existing annotations
                annotationsList.innerHTML = '';
                
                // Add new annotations
                annotations.forEach(annotation => {
                    const annotationEl = document.createElement('div');
                    annotationEl.className = `bg-white border border-gray-200 p-4 mb-4 rounded-lg shadow-sm hover:shadow-md transition-shadow cursor-pointer`;
                    annotationEl.innerHTML = `
                        <div class="flex justify-between items-start mb-2">
                            <div>
                                <h4 class="font-medium text-gray-800">${annotation.term}</h4>
                                <span class="text-xs text-gray-500">Page ${annotation.page}</span>
                            </div>
                            <span class="text-xs px-2 py-1 rounded-full ${
                                annotation.type === 'definition' ? 'bg-blue-100 text-blue-800' : 
                                annotation.type === 'summary' ? 'bg-green-100 text-green-800' : 
                                'bg-purple-100 text-purple-800'
                            }">
                                ${annotation.type.charAt(0).toUpperCase() + annotation.type.slice(1)}
                            </span>
                        </div>
                        <p class="text-gray-600 text-sm mb-2">${annotation.content}</p>
                        <div class="flex justify-between items-center">
                            <span class="text-xs text-gray-400">AI Confidence: ${Math.round(annotation.confidence * 100)}%</span>
                            <button class="text-xs text-blue-500 hover:text-blue-700" data-term="${annotation.term}">
                                <i class="fas fa-location-arrow mr-1"></i> Locate in document
                            </button>
                        </div>
                    `;
                    
                    // Add click handler to locate term in document
                    annotationEl.querySelector('button').addEventListener('click', function(e) {
                        e.stopPropagation();
                        const term = this.getAttribute('data-term');
                        scrollToTerm(term);
                    });
                    
                    annotationsList.appendChild(annotationEl);
                });
            }

            function showAnnotationPopup(element, term) {
                // Remove any existing popups
                document.querySelectorAll('.annotation-popup').forEach(el => el.remove());
                
                // In a real app, this would fetch the actual annotation data
                const annotationData = {
                    "AI": {
                        content: "Artificial Intelligence (AI) refers to machines designed to perform tasks that typically require human intelligence.",
                        type: "definition",
                        confidence: 0.92
                    },
                    "Machine Learning": {
                        content: "Machine Learning is a subset of AI that enables systems to automatically learn and improve from experience.",
                        type: "definition",
                        confidence: 0.95
                    },
                    "Deep Learning": {
                        content: "Deep Learning uses artificial neural networks with multiple layers to extract higher-level features from raw input.",
                        type: "definition",
                        confidence: 0.89
                    }
                };
                
                if (!annotationData[term]) return;
                
                const popup = document.createElement('div');
                popup.className = 'annotation-popup';
                popup.innerHTML = `
                    <div class="flex justify-between items-start mb-2">
                        <h4 class="font-medium text-gray-800">${term}</h4>
                        <span class="text-xs px-2 py-1 rounded-full ${
                            annotationData[term].type === 'definition' ? 'bg-blue-100 text-blue-800' : 'bg-purple-100 text-purple-800'
                        }">
                            ${annotationData[term].type.charAt(0).toUpperCase() + annotationData[term].type.slice(1)}
                        </span>
                    </div>
                    <p class="text-gray-600 text-sm mb-3">${annotationData[term].content}</p>
                    <div class="flex justify-between items-center text-xs">
                        <span class="text-gray-400">AI Confidence: ${Math.round(annotationData[term].confidence * 100)}%</span>
                        <button class="text-blue-500 hover:text-blue-700">
                            <i class="fas fa-bookmark mr-1"></i> Save
                        </button>
                    </div>
                `;
                
                // Position the popup next to the element
                const rect = element.getBoundingClientRect();
                popup.style.top = `${rect.top + window.scrollY}px`;
                
                // Add to document
                document.body.appendChild(popup);
                
                // Close popup when clicking outside
                setTimeout(() => {
                    const clickHandler = (e) => {
                        if (!popup.contains(e.target) && !element.contains(e.target)) {
                            popup.remove();
                            document.removeEventListener('click', clickHandler);
                        }
                    };
                    document.addEventListener('click', clickHandler);
                }, 10);
            }

            function scrollToTerm(term) {
                // Find the first highlight with this term and scroll to it
                const highlight = document.querySelector(`.highlight[data-term="${term}"]`);
                if (highlight) {
                    highlight.scrollIntoView({ behavior: 'smooth', block: 'center' });
                    
                    // Add temporary highlight effect
                    highlight.style.backgroundColor = 'rgba(255, 255, 0, 0.7)';
                    setTimeout(() => {
                        highlight.style.backgroundColor = 'rgba(255, 255, 0, 0.3)';
                    }, 2000);
                }
            }

            function resetDocument() {
                // Reset the UI
                fileInput.value = '';
                dropzoneSection.classList.remove('hidden');
                pdfViewerSection.classList.add('hidden');
                analyzeBtn.classList.add('hidden');
                annotationsList.innerHTML = `
                    <div class="bg-blue-50 border-l-4 border-blue-500 p-4 mb-4 rounded">
                        <div class="flex justify-between items-start">
                            <div>
                                <h4 class="font-medium text-blue-800">Document Summary</h4>
                                <p class="text-sm text-gray-600 mt-1">Upload a PDF to see AI-generated annotations appear here.</p>
                            </div>
                            <span class="bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded-full">Summary</span>
                        </div>
                    </div>
                `;
            }

            function toggleFilterDropdown() {
                filterDropdown.classList.toggle('hidden');
            }

            function showToast(message, type) {
                const toast = document.createElement('div');
                toast.className = `fixed bottom-4 right-4 px-6 py-3 rounded-md shadow-md text-white ${
                    type === 'error' ? 'bg-red-500' : 'bg-green-500'
                }`;
                toast.textContent = message;
                document.body.appendChild(toast);
                
                setTimeout(() => {
                    toast.classList.add('opacity-0', 'transition-opacity', 'duration-300');
                    setTimeout(() => toast.remove(), 300);
                }, 3000);
            }
        });
    </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=Godsmiler-69/pdf" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>