luanngo commited on
Commit
8b4b81e
·
verified ·
1 Parent(s): 09e1f5b

Add 2 files

Browse files
Files changed (2) hide show
  1. README.md +7 -5
  2. index.html +532 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Chatpdf
3
- emoji:
4
- colorFrom: green
5
- colorTo: indigo
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: chatpdf
3
+ emoji: 🐳
4
+ colorFrom: pink
5
+ colorTo: purple
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,532 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>PDF Editor with AI Assistant</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.11.338/pdf.min.js"></script>
9
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
10
+ <style>
11
+ .pdf-container {
12
+ height: calc(100vh - 180px);
13
+ overflow-y: auto;
14
+ border: 1px solid #e5e7eb;
15
+ }
16
+ .chat-container {
17
+ height: calc(100vh - 180px);
18
+ display: flex;
19
+ flex-direction: column;
20
+ }
21
+ .chat-messages {
22
+ flex-grow: 1;
23
+ overflow-y: auto;
24
+ }
25
+ .pdf-page {
26
+ margin-bottom: 20px;
27
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
28
+ }
29
+ .canvas-container {
30
+ position: relative;
31
+ }
32
+ .annotation-tools {
33
+ position: absolute;
34
+ top: 10px;
35
+ left: 10px;
36
+ background: white;
37
+ padding: 5px;
38
+ border-radius: 5px;
39
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
40
+ display: none;
41
+ }
42
+ .active-tool {
43
+ background-color: #3b82f6;
44
+ color: white;
45
+ }
46
+ .loading-spinner {
47
+ border: 4px solid rgba(0, 0, 0, 0.1);
48
+ border-radius: 50%;
49
+ border-top: 4px solid #3b82f6;
50
+ width: 40px;
51
+ height: 40px;
52
+ animation: spin 1s linear infinite;
53
+ }
54
+ @keyframes spin {
55
+ 0% { transform: rotate(0deg); }
56
+ 100% { transform: rotate(360deg); }
57
+ }
58
+ .drawing-canvas {
59
+ position: absolute;
60
+ top: 0;
61
+ left: 0;
62
+ pointer-events: none;
63
+ }
64
+ </style>
65
+ </head>
66
+ <body class="bg-gray-50">
67
+ <div class="container mx-auto px-4 py-6">
68
+ <header class="mb-8">
69
+ <h1 class="text-3xl font-bold text-blue-600 flex items-center">
70
+ <i class="fas fa-file-pdf mr-3"></i> PDF Editor with AI Assistant
71
+ </h1>
72
+ <p class="text-gray-600 mt-2">Upload, edit, and chat with your PDF documents</p>
73
+ </header>
74
+
75
+ <!-- Upload Section -->
76
+ <div class="bg-white rounded-lg shadow-md p-6 mb-8" id="upload-section">
77
+ <div class="flex flex-col items-center justify-center border-2 border-dashed border-gray-300 rounded-lg p-12 bg-gray-50">
78
+ <i class="fas fa-file-upload text-5xl text-blue-400 mb-4"></i>
79
+ <h3 class="text-xl font-semibold text-gray-700 mb-2">Upload your PDF file</h3>
80
+ <p class="text-gray-500 mb-6">Drag & drop your file here or click to browse</p>
81
+ <input type="file" id="pdf-upload" accept=".pdf" class="hidden">
82
+ <button id="upload-btn" class="bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-6 rounded-lg transition duration-200 flex items-center">
83
+ <i class="fas fa-folder-open mr-2"></i> Select PDF File
84
+ </button>
85
+ <p class="text-sm text-gray-500 mt-4">Supports PDF files up to 50MB</p>
86
+ </div>
87
+ </div>
88
+
89
+ <!-- Editor Section (hidden initially) -->
90
+ <div id="editor-section" class="hidden">
91
+ <div class="flex justify-between items-center mb-4">
92
+ <h2 class="text-xl font-semibold text-gray-800 flex items-center">
93
+ <i class="fas fa-edit mr-2"></i> PDF Editor
94
+ </h2>
95
+ <div class="flex space-x-2">
96
+ <button id="download-btn" class="bg-green-600 hover:bg-green-700 text-white font-medium py-2 px-4 rounded-lg transition duration-200 flex items-center">
97
+ <i class="fas fa-download mr-2"></i> Download
98
+ </button>
99
+ <button id="new-file-btn" class="bg-gray-200 hover:bg-gray-300 text-gray-800 font-medium py-2 px-4 rounded-lg transition duration-200 flex items-center">
100
+ <i class="fas fa-plus mr-2"></i> New File
101
+ </button>
102
+ </div>
103
+ </div>
104
+
105
+ <div class="flex flex-col lg:flex-row gap-6">
106
+ <!-- PDF Editor Column -->
107
+ <div class="w-full lg:w-2/3 bg-white rounded-lg shadow-md p-4">
108
+ <div class="flex items-center justify-between mb-4">
109
+ <div class="flex space-x-2">
110
+ <button id="highlight-btn" class="p-2 rounded-md hover:bg-gray-100" title="Highlight">
111
+ <i class="fas fa-highlighter text-yellow-500"></i>
112
+ </button>
113
+ <button id="underline-btn" class="p-2 rounded-md hover:bg-gray-100" title="Underline">
114
+ <i class="fas fa-underline text-blue-500"></i>
115
+ </button>
116
+ <button id="strike-btn" class="p-2 rounded-md hover:bg-gray-100" title="Strikethrough">
117
+ <i class="fas fa-strikethrough text-red-500"></i>
118
+ </button>
119
+ <button id="draw-btn" class="p-2 rounded-md hover:bg-gray-100" title="Draw">
120
+ <i class="fas fa-pen text-purple-500"></i>
121
+ </button>
122
+ <button id="text-btn" class="p-2 rounded-md hover:bg-gray-100" title="Add Text">
123
+ <i class="fas fa-font text-green-500"></i>
124
+ </button>
125
+ <button id="eraser-btn" class="p-2 rounded-md hover:bg-gray-100" title="Eraser">
126
+ <i class="fas fa-eraser text-gray-500"></i>
127
+ </button>
128
+ </div>
129
+ <div class="flex items-center space-x-2">
130
+ <button id="zoom-in" class="p-2 rounded-md hover:bg-gray-100">
131
+ <i class="fas fa-search-plus"></i>
132
+ </button>
133
+ <span id="zoom-level" class="text-sm font-medium">100%</span>
134
+ <button id="zoom-out" class="p-2 rounded-md hover:bg-gray-100">
135
+ <i class="fas fa-search-minus"></i>
136
+ </button>
137
+ </div>
138
+ </div>
139
+
140
+ <div class="pdf-container" id="pdf-viewer">
141
+ <div class="flex items-center justify-center h-full" id="pdf-loading">
142
+ <div class="text-center">
143
+ <div class="loading-spinner mx-auto mb-4"></div>
144
+ <p class="text-gray-600">Loading PDF document...</p>
145
+ </div>
146
+ </div>
147
+ </div>
148
+ </div>
149
+
150
+ <!-- Chat Assistant Column -->
151
+ <div class="w-full lg:w-1/3 bg-white rounded-lg shadow-md p-4">
152
+ <div class="flex items-center mb-4">
153
+ <div class="w-10 h-10 rounded-full bg-blue-100 flex items-center justify-center mr-3">
154
+ <i class="fas fa-robot text-blue-500"></i>
155
+ </div>
156
+ <h3 class="text-lg font-semibold text-gray-800">PDF Assistant</h3>
157
+ </div>
158
+
159
+ <div class="chat-container">
160
+ <div class="chat-messages" id="chat-messages">
161
+ <div class="bg-blue-50 rounded-lg p-4 mb-4">
162
+ <p class="text-gray-800">Hello! I'm your PDF assistant. Ask me anything about the document or request help with editing.</p>
163
+ </div>
164
+ </div>
165
+
166
+ <div class="mt-4">
167
+ <div class="flex items-center space-x-2 mb-2">
168
+ <button class="bg-gray-100 hover:bg-gray-200 text-gray-800 text-xs py-1 px-2 rounded">
169
+ Summarize
170
+ </button>
171
+ <button class="bg-gray-100 hover:bg-gray-200 text-gray-800 text-xs py-1 px-2 rounded">
172
+ Find key points
173
+ </button>
174
+ <button class="bg-gray-100 hover:bg-gray-200 text-gray-800 text-xs py-1 px-2 rounded">
175
+ Explain section
176
+ </button>
177
+ </div>
178
+ <div class="relative">
179
+ <textarea id="chat-input" rows="2" class="w-full border border-gray-300 rounded-lg p-3 pr-12 focus:ring-blue-500 focus:border-blue-500" placeholder="Ask about the document..."></textarea>
180
+ <button id="send-chat" class="absolute right-3 bottom-3 bg-blue-600 hover:bg-blue-700 text-white p-2 rounded-lg">
181
+ <i class="fas fa-paper-plane"></i>
182
+ </button>
183
+ </div>
184
+ </div>
185
+ </div>
186
+ </div>
187
+ </div>
188
+ </div>
189
+ </div>
190
+
191
+ <script>
192
+ // Set PDF.js worker path
193
+ pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.11.338/pdf.worker.min.js';
194
+
195
+ // DOM elements
196
+ const uploadSection = document.getElementById('upload-section');
197
+ const editorSection = document.getElementById('editor-section');
198
+ const pdfUpload = document.getElementById('pdf-upload');
199
+ const uploadBtn = document.getElementById('upload-btn');
200
+ const pdfViewer = document.getElementById('pdf-viewer');
201
+ const pdfLoading = document.getElementById('pdf-loading');
202
+ const zoomInBtn = document.getElementById('zoom-in');
203
+ const zoomOutBtn = document.getElementById('zoom-out');
204
+ const zoomLevel = document.getElementById('zoom-level');
205
+ const downloadBtn = document.getElementById('download-btn');
206
+ const newFileBtn = document.getElementById('new-file-btn');
207
+ const chatMessages = document.getElementById('chat-messages');
208
+ const chatInput = document.getElementById('chat-input');
209
+ const sendChatBtn = document.getElementById('send-chat');
210
+ const highlightBtn = document.getElementById('highlight-btn');
211
+ const underlineBtn = document.getElementById('underline-btn');
212
+ const strikeBtn = document.getElementById('strike-btn');
213
+ const drawBtn = document.getElementById('draw-btn');
214
+ const textBtn = document.getElementById('text-btn');
215
+ const eraserBtn = document.getElementById('eraser-btn');
216
+
217
+ // Variables
218
+ let pdfDoc = null;
219
+ let currentPage = 1;
220
+ let pageRendering = false;
221
+ let pageNumPending = null;
222
+ let scale = 1.0;
223
+ let canvas, ctx;
224
+ let isDrawing = false;
225
+ let activeTool = null;
226
+ let lastX = 0;
227
+ let lastY = 0;
228
+ let drawingCanvases = [];
229
+
230
+ // Event listeners
231
+ uploadBtn.addEventListener('click', () => pdfUpload.click());
232
+ pdfUpload.addEventListener('change', handleFileUpload);
233
+ zoomInBtn.addEventListener('click', zoomIn);
234
+ zoomOutBtn.addEventListener('click', zoomOut);
235
+ downloadBtn.addEventListener('click', downloadPDF);
236
+ newFileBtn.addEventListener('click', resetApp);
237
+ sendChatBtn.addEventListener('click', sendChatMessage);
238
+ chatInput.addEventListener('keypress', (e) => {
239
+ if (e.key === 'Enter' && !e.shiftKey) {
240
+ e.preventDefault();
241
+ sendChatMessage();
242
+ }
243
+ });
244
+
245
+ // Tool buttons
246
+ highlightBtn.addEventListener('click', () => setActiveTool('highlight'));
247
+ underlineBtn.addEventListener('click', () => setActiveTool('underline'));
248
+ strikeBtn.addEventListener('click', () => setActiveTool('strike'));
249
+ drawBtn.addEventListener('click', () => setActiveTool('draw'));
250
+ textBtn.addEventListener('click', () => setActiveTool('text'));
251
+ eraserBtn.addEventListener('click', () => setActiveTool('eraser'));
252
+
253
+ // Handle file upload
254
+ function handleFileUpload(e) {
255
+ const file = e.target.files[0];
256
+ if (file.type !== 'application/pdf') {
257
+ alert('Please select a PDF file.');
258
+ return;
259
+ }
260
+
261
+ uploadSection.classList.add('hidden');
262
+ editorSection.classList.remove('hidden');
263
+
264
+ const fileReader = new FileReader();
265
+ fileReader.onload = function() {
266
+ const typedarray = new Uint8Array(this.result);
267
+ loadPDF(typedarray);
268
+ };
269
+ fileReader.readAsArrayBuffer(file);
270
+ }
271
+
272
+ // Load PDF document
273
+ function loadPDF(data) {
274
+ pdfLoading.style.display = 'flex';
275
+ pdfViewer.innerHTML = '';
276
+ pdfViewer.appendChild(pdfLoading);
277
+
278
+ pdfjsLib.getDocument(data).promise.then(function(pdf) {
279
+ pdfDoc = pdf;
280
+ renderPDF();
281
+ }).catch(function(error) {
282
+ console.error('Error loading PDF:', error);
283
+ pdfLoading.querySelector('p').textContent = 'Error loading PDF. Please try another file.';
284
+ });
285
+ }
286
+
287
+ // Render PDF pages
288
+ function renderPDF() {
289
+ pdfLoading.style.display = 'none';
290
+
291
+ for (let i = 1; i <= pdfDoc.numPages; i++) {
292
+ const pageContainer = document.createElement('div');
293
+ pageContainer.className = 'pdf-page';
294
+ pageContainer.id = `page-${i}`;
295
+
296
+ const canvasContainer = document.createElement('div');
297
+ canvasContainer.className = 'canvas-container relative';
298
+
299
+ const annotationTools = document.createElement('div');
300
+ annotationTools.className = 'annotation-tools';
301
+ annotationTools.id = `tools-${i}`;
302
+ annotationTools.innerHTML = `
303
+ <button class="p-1 hover:bg-gray-100 rounded" data-tool="highlight"><i class="fas fa-highlighter text-yellow-500"></i></button>
304
+ <button class="p-1 hover:bg-gray-100 rounded" data-tool="underline"><i class="fas fa-underline text-blue-500"></i></button>
305
+ <button class="p-1 hover:bg-gray-100 rounded" data-tool="strike"><i class="fas fa-strikethrough text-red-500"></i></button>
306
+ `;
307
+
308
+ canvas = document.createElement('canvas');
309
+ canvas.className = 'pdf-canvas border border-gray-200';
310
+ canvas.id = `canvas-${i}`;
311
+
312
+ const drawingCanvas = document.createElement('canvas');
313
+ drawingCanvas.className = 'drawing-canvas';
314
+ drawingCanvas.id = `drawing-${i}`;
315
+ drawingCanvases.push(drawingCanvas);
316
+
317
+ canvasContainer.appendChild(canvas);
318
+ canvasContainer.appendChild(drawingCanvas);
319
+ canvasContainer.appendChild(annotationTools);
320
+ pageContainer.appendChild(canvasContainer);
321
+ pdfViewer.appendChild(pageContainer);
322
+
323
+ renderPage(i);
324
+ }
325
+
326
+ // Set up drawing canvases
327
+ setupDrawingCanvases();
328
+ }
329
+
330
+ // Render a specific page
331
+ function renderPage(num) {
332
+ pageRendering = true;
333
+ pdfDoc.getPage(num).then(function(page) {
334
+ const viewport = page.getViewport({ scale: scale });
335
+ const canvas = document.getElementById(`canvas-${num}`);
336
+ const context = canvas.getContext('2d');
337
+
338
+ canvas.height = viewport.height;
339
+ canvas.width = viewport.width;
340
+
341
+ // Adjust drawing canvas size
342
+ const drawingCanvas = document.getElementById(`drawing-${num}`);
343
+ drawingCanvas.height = viewport.height;
344
+ drawingCanvas.width = viewport.width;
345
+
346
+ const renderContext = {
347
+ canvasContext: context,
348
+ viewport: viewport
349
+ };
350
+
351
+ const renderTask = page.render(renderContext);
352
+
353
+ renderTask.promise.then(function() {
354
+ pageRendering = false;
355
+ if (pageNumPending !== null) {
356
+ renderPage(pageNumPending);
357
+ pageNumPending = null;
358
+ }
359
+ });
360
+ });
361
+
362
+ currentPage = num;
363
+ }
364
+
365
+ // Zoom functions
366
+ function zoomIn() {
367
+ if (scale >= 3.0) return;
368
+ scale += 0.25;
369
+ zoomLevel.textContent = `${Math.round(scale * 100)}%`;
370
+ rerenderPDF();
371
+ }
372
+
373
+ function zoomOut() {
374
+ if (scale <= 0.5) return;
375
+ scale -= 0.25;
376
+ zoomLevel.textContent = `${Math.round(scale * 100)}%`;
377
+ rerenderPDF();
378
+ }
379
+
380
+ function rerenderPDF() {
381
+ if (pageRendering) {
382
+ pageNumPending = currentPage;
383
+ } else {
384
+ for (let i = 1; i <= pdfDoc.numPages; i++) {
385
+ renderPage(i);
386
+ }
387
+ }
388
+ }
389
+
390
+ // Set up drawing canvases
391
+ function setupDrawingCanvases() {
392
+ drawingCanvases.forEach(drawingCanvas => {
393
+ const ctx = drawingCanvas.getContext('2d');
394
+
395
+ drawingCanvas.addEventListener('mousedown', startDrawing);
396
+ drawingCanvas.addEventListener('mousemove', draw);
397
+ drawingCanvas.addEventListener('mouseup', stopDrawing);
398
+ drawingCanvas.addEventListener('mouseout', stopDrawing);
399
+
400
+ function startDrawing(e) {
401
+ if (activeTool !== 'draw') return;
402
+
403
+ isDrawing = true;
404
+ const rect = drawingCanvas.getBoundingClientRect();
405
+ lastX = e.clientX - rect.left;
406
+ lastY = e.clientY - rect.top;
407
+
408
+ ctx.beginPath();
409
+ ctx.moveTo(lastX, lastY);
410
+ ctx.strokeStyle = '#3b82f6';
411
+ ctx.lineWidth = 2;
412
+ ctx.lineCap = 'round';
413
+ }
414
+
415
+ function draw(e) {
416
+ if (!isDrawing || activeTool !== 'draw') return;
417
+
418
+ const rect = drawingCanvas.getBoundingClientRect();
419
+ const currentX = e.clientX - rect.left;
420
+ const currentY = e.clientY - rect.top;
421
+
422
+ ctx.lineTo(currentX, currentY);
423
+ ctx.stroke();
424
+
425
+ lastX = currentX;
426
+ lastY = currentY;
427
+ }
428
+
429
+ function stopDrawing() {
430
+ isDrawing = false;
431
+ }
432
+ });
433
+ }
434
+
435
+ // Set active tool
436
+ function setActiveTool(tool) {
437
+ activeTool = tool;
438
+
439
+ // Reset all tool buttons
440
+ [highlightBtn, underlineBtn, strikeBtn, drawBtn, textBtn, eraserBtn].forEach(btn => {
441
+ btn.classList.remove('active-tool');
442
+ });
443
+
444
+ // Highlight active tool
445
+ switch(tool) {
446
+ case 'highlight':
447
+ highlightBtn.classList.add('active-tool');
448
+ break;
449
+ case 'underline':
450
+ underlineBtn.classList.add('active-tool');
451
+ break;
452
+ case 'strike':
453
+ strikeBtn.classList.add('active-tool');
454
+ break;
455
+ case 'draw':
456
+ drawBtn.classList.add('active-tool');
457
+ break;
458
+ case 'text':
459
+ textBtn.classList.add('active-tool');
460
+ break;
461
+ case 'eraser':
462
+ eraserBtn.classList.add('active-tool');
463
+ break;
464
+ }
465
+ }
466
+
467
+ // Chat functions
468
+ function sendChatMessage() {
469
+ const message = chatInput.value.trim();
470
+ if (!message) return;
471
+
472
+ // Add user message to chat
473
+ addChatMessage(message, 'user');
474
+
475
+ // Simulate AI response (in a real app, this would call an API)
476
+ setTimeout(() => {
477
+ const responses = [
478
+ "Based on the document, the key points are...",
479
+ "The summary of section 3 is...",
480
+ "This document primarily discusses...",
481
+ "I've analyzed the content and found that...",
482
+ "The author's main argument appears to be..."
483
+ ];
484
+ const randomResponse = responses[Math.floor(Math.random() * responses.length)];
485
+ addChatMessage(randomResponse, 'ai');
486
+ }, 1000);
487
+
488
+ chatInput.value = '';
489
+ }
490
+
491
+ function addChatMessage(message, sender) {
492
+ const messageDiv = document.createElement('div');
493
+ messageDiv.className = `mb-4 ${sender === 'user' ? 'text-right' : 'text-left'}`;
494
+
495
+ const bubble = document.createElement('div');
496
+ bubble.className = `inline-block rounded-lg p-3 max-w-xs lg:max-w-md ${sender === 'user' ? 'bg-blue-600 text-white' : 'bg-gray-100 text-gray-800'}`;
497
+ bubble.textContent = message;
498
+
499
+ messageDiv.appendChild(bubble);
500
+ chatMessages.appendChild(messageDiv);
501
+
502
+ // Scroll to bottom
503
+ chatMessages.scrollTop = chatMessages.scrollHeight;
504
+ }
505
+
506
+ // Download PDF (simplified - in a real app, you'd need to merge annotations)
507
+ function downloadPDF() {
508
+ alert('In a real application, this would download the edited PDF with all annotations.');
509
+ }
510
+
511
+ // Reset app to initial state
512
+ function resetApp() {
513
+ pdfUpload.value = '';
514
+ pdfViewer.innerHTML = '';
515
+ pdfViewer.appendChild(pdfLoading);
516
+ pdfLoading.style.display = 'flex';
517
+ pdfLoading.querySelector('p').textContent = 'Loading PDF document...';
518
+ chatMessages.innerHTML = `
519
+ <div class="bg-blue-50 rounded-lg p-4 mb-4">
520
+ <p class="text-gray-800">Hello! I'm your PDF assistant. Ask me anything about the document or request help with editing.</p>
521
+ </div>
522
+ `;
523
+ editorSection.classList.add('hidden');
524
+ uploadSection.classList.remove('hidden');
525
+ scale = 1.0;
526
+ zoomLevel.textContent = '100%';
527
+ activeTool = null;
528
+ drawingCanvases = [];
529
+ }
530
+ </script>
531
+ <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=luanngo/chatpdf" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
532
+ </html>