Spaces:
Running
Running
undefined - Initial Deployment
Browse files- README.md +7 -5
- index.html +475 -19
README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
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: rag-v1
|
3 |
+
emoji: 🐳
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: blue
|
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,475 @@
|
|
1 |
-
<!
|
2 |
-
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 Chat Assistant | Interactive RAG</title>
|
7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
9 |
+
<script>
|
10 |
+
tailwind.config = {
|
11 |
+
theme: {
|
12 |
+
extend: {
|
13 |
+
colors: {
|
14 |
+
primary: '#4F46E5',
|
15 |
+
secondary: '#818CF8',
|
16 |
+
dark: '#1F2937',
|
17 |
+
light: '#F9FAFB'
|
18 |
+
}
|
19 |
+
}
|
20 |
+
}
|
21 |
+
}
|
22 |
+
</script>
|
23 |
+
<style>
|
24 |
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
|
25 |
+
body {
|
26 |
+
font-family: 'Inter', sans-serif;
|
27 |
+
}
|
28 |
+
.card-shadow {
|
29 |
+
box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1);
|
30 |
+
}
|
31 |
+
.drag-over {
|
32 |
+
border: 2px dashed #4F46E5;
|
33 |
+
background-color: #818cf820;
|
34 |
+
}
|
35 |
+
.message-bubble {
|
36 |
+
max-width: 85%;
|
37 |
+
border-radius: 18px;
|
38 |
+
padding: 14px 18px;
|
39 |
+
}
|
40 |
+
.user-message {
|
41 |
+
background-color: #4F46E5;
|
42 |
+
color: white;
|
43 |
+
border-bottom-right-radius: 5px;
|
44 |
+
}
|
45 |
+
.bot-message {
|
46 |
+
background-color: #E5E7EB;
|
47 |
+
color: #1F2937;
|
48 |
+
border-bottom-left-radius: 5px;
|
49 |
+
}
|
50 |
+
.chat-container {
|
51 |
+
height: calc(100vh - 220px);
|
52 |
+
}
|
53 |
+
.pdf-preview {
|
54 |
+
height: calc(100vh - 270px);
|
55 |
+
}
|
56 |
+
@media (max-width: 1024px) {
|
57 |
+
.pdf-preview {
|
58 |
+
height: 500px;
|
59 |
+
}
|
60 |
+
.chat-container {
|
61 |
+
height: 500px;
|
62 |
+
}
|
63 |
+
}
|
64 |
+
.chat-input:focus {
|
65 |
+
outline: none;
|
66 |
+
box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.5);
|
67 |
+
}
|
68 |
+
</style>
|
69 |
+
</head>
|
70 |
+
<body class="bg-light">
|
71 |
+
<!-- Header -->
|
72 |
+
<header class="bg-white py-4 card-shadow">
|
73 |
+
<div class="container mx-auto px-4">
|
74 |
+
<div class="flex justify-between items-center">
|
75 |
+
<div class="flex items-center">
|
76 |
+
<div class="w-10 h-10 bg-primary rounded-full flex items-center justify-center">
|
77 |
+
<i class="fas fa-file-pdf text-white text-xl"></i>
|
78 |
+
</div>
|
79 |
+
<h1 class="text-2xl font-bold text-dark ml-3">PDF Chat Assistant</h1>
|
80 |
+
</div>
|
81 |
+
<div class="flex items-center space-x-4">
|
82 |
+
<button class="bg-primary text-white px-4 py-2 rounded-lg hover:bg-secondary transition">
|
83 |
+
<i class="fas fa-user mr-2"></i>My Account
|
84 |
+
</button>
|
85 |
+
</div>
|
86 |
+
</div>
|
87 |
+
</div>
|
88 |
+
</header>
|
89 |
+
|
90 |
+
<main class="container mx-auto px-4 py-8">
|
91 |
+
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
|
92 |
+
<!-- Left Side: PDF Upload & Preview -->
|
93 |
+
<div class="bg-white rounded-xl card-shadow p-6">
|
94 |
+
<h2 class="text-xl font-bold text-dark mb-4 flex items-center">
|
95 |
+
<i class="fas fa-cloud-upload-alt text-secondary mr-2"></i> Upload Document
|
96 |
+
</h2>
|
97 |
+
|
98 |
+
<!-- File Upload Box -->
|
99 |
+
<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">
|
100 |
+
<div class="mb-4">
|
101 |
+
<i class="fas fa-file-upload text-4xl text-secondary mb-3"></i>
|
102 |
+
<p class="font-semibold">Drag & Drop your PDF file</p>
|
103 |
+
<p class="text-gray-500 text-sm mt-1">or click to browse</p>
|
104 |
+
</div>
|
105 |
+
<input type="file" id="file-input" accept=".pdf" class="hidden">
|
106 |
+
<button id="browse-btn" class="bg-primary text-white px-4 py-2 rounded-lg hover:bg-secondary transition">
|
107 |
+
Browse Files
|
108 |
+
</button>
|
109 |
+
</div>
|
110 |
+
|
111 |
+
<!-- File Preview -->
|
112 |
+
<div id="file-preview" class="hidden">
|
113 |
+
<div class="flex justify-between items-center mb-4">
|
114 |
+
<h3 class="text-lg font-semibold">Document Preview</h3>
|
115 |
+
<button id="remove-file" class="text-red-500 hover:text-red-700">
|
116 |
+
<i class="fas fa-trash-alt mr-1"></i> Remove
|
117 |
+
</button>
|
118 |
+
</div>
|
119 |
+
|
120 |
+
<div class="bg-gray-100 rounded-lg overflow-hidden pdf-preview">
|
121 |
+
<div class="flex items-center justify-center h-full">
|
122 |
+
<div class="text-center p-8">
|
123 |
+
<i class="fas fa-file-pdf text-6xl text-red-500 mb-4"></i>
|
124 |
+
<p class="font-semibold" id="file-name">document.pdf</p>
|
125 |
+
<p class="text-gray-600 mt-2">PDF preview would appear here</p>
|
126 |
+
<div class="mt-6 flex justify-center">
|
127 |
+
<div class="w-24 h-32 bg-white border flex items-center justify-center mx-1">
|
128 |
+
<p class="text-xs">Page 1</p>
|
129 |
+
</div>
|
130 |
+
<div class="w-24 h-32 bg-white border flex items-center justify-center mx-1">
|
131 |
+
<p class="text-xs">Page 2</p>
|
132 |
+
</div>
|
133 |
+
</div>
|
134 |
+
</div>
|
135 |
+
</div>
|
136 |
+
</div>
|
137 |
+
|
138 |
+
<div class="mt-4 flex justify-between">
|
139 |
+
<div class="text-sm text-gray-600">
|
140 |
+
<span>Processing:</span>
|
141 |
+
<span id="processing-text">Extracting content...</span>
|
142 |
+
</div>
|
143 |
+
<div class="flex">
|
144 |
+
<div class="w-8 h-8 rounded-full bg-green-500 flex items-center justify-center">
|
145 |
+
<i class="fas fa-check text-white text-sm"></i>
|
146 |
+
</div>
|
147 |
+
</div>
|
148 |
+
</div>
|
149 |
+
</div>
|
150 |
+
|
151 |
+
<!-- Sample Documents -->
|
152 |
+
<div class="mt-8">
|
153 |
+
<h3 class="font-medium text-gray-700 mb-3 flex items-center">
|
154 |
+
<i class="fas fa-lightbulb text-yellow-400 mr-2"></i> Sample Documents
|
155 |
+
</h3>
|
156 |
+
<div class="grid grid-cols-2 gap-4">
|
157 |
+
<button class="bg-gray-100 hover:bg-gray-200 p-4 rounded-lg flex items-center">
|
158 |
+
<i class="fas fa-file-alt text-blue-500 mr-2"></i>
|
159 |
+
<span class="truncate">Annual_Report.pdf</span>
|
160 |
+
</button>
|
161 |
+
<button class="bg-gray-100 hover:bg-gray-200 p-4 rounded-lg flex items-center">
|
162 |
+
<i class="fas fa-file-alt text-green-500 mr-2"></i>
|
163 |
+
<span class="truncate">Research_Paper.pdf</span>
|
164 |
+
</button>
|
165 |
+
</div>
|
166 |
+
</div>
|
167 |
+
</div>
|
168 |
+
|
169 |
+
<!-- Right Side: Chat Interface -->
|
170 |
+
<div class="bg-white rounded-xl card-shadow overflow-hidden flex flex-col">
|
171 |
+
<div class="p-6 border-b">
|
172 |
+
<h2 class="text-xl font-bold text-dark flex items-center">
|
173 |
+
<i class="fas fa-comments text-secondary mr-2"></i> Document Chat
|
174 |
+
</h2>
|
175 |
+
<div class="text-sm text-gray-600 mt-1">Ask questions about your uploaded document</div>
|
176 |
+
</div>
|
177 |
+
|
178 |
+
<!-- Chat Messages Container -->
|
179 |
+
<div id="chat-container" class="chat-container overflow-y-auto p-6 bg-gray-50 flex-grow">
|
180 |
+
<!-- Welcome message -->
|
181 |
+
<div class="flex mb-6">
|
182 |
+
<div class="flex-shrink-0">
|
183 |
+
<div class="w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center">
|
184 |
+
<i class="fas fa-robot text-secondary"></i>
|
185 |
+
</div>
|
186 |
+
</div>
|
187 |
+
<div class="ml-4">
|
188 |
+
<div class="bot-message message-bubble">
|
189 |
+
<p class="font-bold text-secondary mb-1">PDF Assistant</p>
|
190 |
+
<p>Hello! I'm your document assistant. Upload a PDF file to get started.</p>
|
191 |
+
<p class="mt-2">You can ask me questions like:</p>
|
192 |
+
<ul class="list-disc pl-5 mt-2 space-y-1">
|
193 |
+
<li>Summarize this document</li>
|
194 |
+
<li>What's the main point on page 5?</li>
|
195 |
+
<li>Find key statistics in section 3</li>
|
196 |
+
</ul>
|
197 |
+
</div>
|
198 |
+
</div>
|
199 |
+
</div>
|
200 |
+
|
201 |
+
<!-- Chat messages will appear here dynamically -->
|
202 |
+
</div>
|
203 |
+
|
204 |
+
<!-- Chat Input -->
|
205 |
+
<div class="p-6 bg-white border-t">
|
206 |
+
<div id="upload-required" class="bg-blue-50 text-blue-800 rounded-lg p-3 mb-4 flex items-center">
|
207 |
+
<i class="fas fa-info-circle mr-2"></i>
|
208 |
+
<span>Upload a PDF document to start chatting</span>
|
209 |
+
</div>
|
210 |
+
<div id="chat-input-area" class="hidden">
|
211 |
+
<div class="flex items-center">
|
212 |
+
<input
|
213 |
+
id="chat-input"
|
214 |
+
type="text"
|
215 |
+
placeholder="Ask a question about your document..."
|
216 |
+
class="flex-grow border border-gray-300 rounded-l-lg p-3 chat-input focus:border-primary"
|
217 |
+
>
|
218 |
+
<button id="send-btn" class="bg-primary text-white px-5 py-3 rounded-r-lg hover:bg-secondary transition">
|
219 |
+
<i class="fas fa-paper-plane"></i>
|
220 |
+
</button>
|
221 |
+
</div>
|
222 |
+
<div class="flex justify-between mt-3">
|
223 |
+
<div class="flex space-x-4">
|
224 |
+
<button class="text-sm text-gray-600 hover:text-primary">
|
225 |
+
<i class="fas fa-sync-alt mr-1"></i> Reindex document
|
226 |
+
</button>
|
227 |
+
<button class="text-sm text-gray-600 hover:text-primary">
|
228 |
+
<i class="fas fa-file-download mr-1"></i> Export chat
|
229 |
+
</button>
|
230 |
+
</div>
|
231 |
+
<button id="suggest-btn" class="text-sm text-primary">
|
232 |
+
<i class="fas fa-wand-magic-sparkles mr-1"></i> Suggest questions
|
233 |
+
</button>
|
234 |
+
</div>
|
235 |
+
</div>
|
236 |
+
</div>
|
237 |
+
</div>
|
238 |
+
</div>
|
239 |
+
</main>
|
240 |
+
|
241 |
+
<!-- Footer -->
|
242 |
+
<footer class="bg-white py-8 mt-12 border-t">
|
243 |
+
<div class="container mx-auto px-4">
|
244 |
+
<div class="text-center">
|
245 |
+
<div class="flex justify-center space-x-6 mb-4">
|
246 |
+
<a href="#" class="text-gray-600 hover:text-primary">
|
247 |
+
<i class="fab fa-twitter"></i>
|
248 |
+
</a>
|
249 |
+
<a href="#" class="text-gray-600 hover:text-primary">
|
250 |
+
<i class="fab fa-github"></i>
|
251 |
+
</a>
|
252 |
+
<a href="#" class="text-gray-600 hover:text-primary">
|
253 |
+
<i class="fab fa-linkedin"></i>
|
254 |
+
</a>
|
255 |
+
</div>
|
256 |
+
<p class="text-gray-600">© 2023 PDF Chat Assistant. All rights reserved.</p>
|
257 |
+
<p class="text-gray-500 text-sm mt-2">Built with Retrieval Augmented Generation technology</p>
|
258 |
+
</div>
|
259 |
+
</div>
|
260 |
+
</footer>
|
261 |
+
|
262 |
+
<!-- JavaScript for interactivity -->
|
263 |
+
<script>
|
264 |
+
document.addEventListener('DOMContentLoaded', function() {
|
265 |
+
// Elements
|
266 |
+
const uploadArea = document.getElementById('upload-area');
|
267 |
+
const fileInput = document.getElementById('file-input');
|
268 |
+
const browseBtn = document.getElementById('browse-btn');
|
269 |
+
const filePreview = document.getElementById('file-preview');
|
270 |
+
const removeFile = document.getElementById('remove-file');
|
271 |
+
const fileName = document.getElementById('file-name');
|
272 |
+
const chatInputArea = document.getElementById('chat-input-area');
|
273 |
+
const uploadRequired = document.getElementById('upload-required');
|
274 |
+
const chatInput = document.getElementById('chat-input');
|
275 |
+
const sendBtn = document.getElementById('send-btn');
|
276 |
+
const chatContainer = document.getElementById('chat-container');
|
277 |
+
const suggestBtn = document.getElementById('suggest-btn');
|
278 |
+
|
279 |
+
// Browse button click event
|
280 |
+
browseBtn.addEventListener('click', () => fileInput.click());
|
281 |
+
|
282 |
+
// File input change event
|
283 |
+
fileInput.addEventListener('change', function() {
|
284 |
+
if (this.files && this.files[0]) {
|
285 |
+
handleFileUpload(this.files[0]);
|
286 |
+
}
|
287 |
+
});
|
288 |
+
|
289 |
+
// Drag and drop events
|
290 |
+
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
|
291 |
+
uploadArea.addEventListener(eventName, preventDefaults, false);
|
292 |
+
});
|
293 |
+
|
294 |
+
function preventDefaults(e) {
|
295 |
+
e.preventDefault();
|
296 |
+
e.stopPropagation();
|
297 |
+
}
|
298 |
+
|
299 |
+
['dragenter', 'dragover'].forEach(eventName => {
|
300 |
+
uploadArea.addEventListener(eventName, () => uploadArea.classList.add('drag-over'));
|
301 |
+
});
|
302 |
+
|
303 |
+
['dragleave', 'drop'].forEach(eventName => {
|
304 |
+
uploadArea.addEventListener(eventName, () => uploadArea.classList.remove('drag-over'));
|
305 |
+
});
|
306 |
+
|
307 |
+
uploadArea.addEventListener('drop', (e) => {
|
308 |
+
const dt = e.dataTransfer;
|
309 |
+
const file = dt.files[0];
|
310 |
+
handleFileUpload(file);
|
311 |
+
});
|
312 |
+
|
313 |
+
// File upload handler
|
314 |
+
function handleFileUpload(file) {
|
315 |
+
if (file && file.type === 'application/pdf') {
|
316 |
+
fileName.textContent = file.name;
|
317 |
+
filePreview.classList.remove('hidden');
|
318 |
+
uploadRequired.classList.add('hidden');
|
319 |
+
chatInputArea.classList.remove('hidden');
|
320 |
+
|
321 |
+
// Simulate processing delay
|
322 |
+
const processingText = document.getElementById('processing-text');
|
323 |
+
processingText.textContent = 'Extracting content...';
|
324 |
+
|
325 |
+
setTimeout(() => {
|
326 |
+
processingText.textContent = 'Document ready for questions';
|
327 |
+
addBotMessage(`Your document "${file.name}" has been processed successfully. How can I help you with this PDF?`);
|
328 |
+
}, 3000);
|
329 |
+
} else {
|
330 |
+
alert('Please select a valid PDF file.');
|
331 |
+
}
|
332 |
+
}
|
333 |
+
|
334 |
+
// Remove file handler
|
335 |
+
removeFile.addEventListener('click', () => {
|
336 |
+
filePreview.classList.add('hidden');
|
337 |
+
uploadRequired.classList.remove('hidden');
|
338 |
+
chatInputArea.classList.add('hidden');
|
339 |
+
fileInput.value = '';
|
340 |
+
});
|
341 |
+
|
342 |
+
// Send button click event
|
343 |
+
sendBtn.addEventListener('click', sendMessage);
|
344 |
+
|
345 |
+
// Enter key in chat input
|
346 |
+
chatInput.addEventListener('keypress', (e) => {
|
347 |
+
if (e.key === 'Enter') {
|
348 |
+
sendMessage();
|
349 |
+
}
|
350 |
+
});
|
351 |
+
|
352 |
+
// Send message function
|
353 |
+
function sendMessage() {
|
354 |
+
const message = chatInput.value.trim();
|
355 |
+
if (!message) return;
|
356 |
+
|
357 |
+
addUserMessage(message);
|
358 |
+
chatInput.value = '';
|
359 |
+
|
360 |
+
// Simulate bot typing
|
361 |
+
setTimeout(() => {
|
362 |
+
simulateBotReply(message);
|
363 |
+
}, 1000);
|
364 |
+
}
|
365 |
+
|
366 |
+
// Add user message to chat
|
367 |
+
function addUserMessage(message) {
|
368 |
+
const messageElement = `
|
369 |
+
<div class="flex justify-end mb-6">
|
370 |
+
<div class="flex flex-col items-end">
|
371 |
+
<div class="user-message message-bubble">
|
372 |
+
${message}
|
373 |
+
</div>
|
374 |
+
</div>
|
375 |
+
<div class="flex-shrink-0 ml-4">
|
376 |
+
<div class="w-10 h-10 bg-primary rounded-full flex items-center justify-center">
|
377 |
+
<i class="fas fa-user text-white"></i>
|
378 |
+
</div>
|
379 |
+
</div>
|
380 |
+
</div>
|
381 |
+
`;
|
382 |
+
chatContainer.insertAdjacentHTML('beforeend', messageElement);
|
383 |
+
chatContainer.scrollTop = chatContainer.scrollHeight;
|
384 |
+
}
|
385 |
+
|
386 |
+
// Add bot message to chat
|
387 |
+
function addBotMessage(message) {
|
388 |
+
const messageElement = `
|
389 |
+
<div class="flex mb-6">
|
390 |
+
<div class="flex-shrink-0">
|
391 |
+
<div class="w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center">
|
392 |
+
<i class="fas fa-robot text-secondary"></i>
|
393 |
+
</div>
|
394 |
+
</div>
|
395 |
+
<div class="ml-4">
|
396 |
+
<div class="bot-message message-bubble">
|
397 |
+
<p class="font-bold text-secondary mb-1">PDF Assistant</p>
|
398 |
+
<p>${message}</p>
|
399 |
+
</div>
|
400 |
+
</div>
|
401 |
+
</div>
|
402 |
+
`;
|
403 |
+
chatContainer.insertAdjacentHTML('beforeend', messageElement);
|
404 |
+
chatContainer.scrollTop = chatContainer.scrollHeight;
|
405 |
+
}
|
406 |
+
|
407 |
+
// Function to simulate bot responses
|
408 |
+
function simulateBotReply(userMessage) {
|
409 |
+
// Simple response logic for demo
|
410 |
+
let response;
|
411 |
+
const lowerMessage = userMessage.toLowerCase();
|
412 |
+
|
413 |
+
if (lowerMessage.includes('hello') || lowerMessage.includes('hi')) {
|
414 |
+
response = "Hello! How can I assist you with your document?";
|
415 |
+
} else if (lowerMessage.includes('summary') || lowerMessage.includes('summarize')) {
|
416 |
+
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.";
|
417 |
+
} else if (lowerMessage.includes('page') || lowerMessage.includes('section')) {
|
418 |
+
const pageNum = userMessage.match(/\d+/);
|
419 |
+
response = pageNum
|
420 |
+
? `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%.`
|
421 |
+
: `The section discusses evolving consumer preferences in digital services, highlighting increased demand for personalization and seamless cross-device experiences.`;
|
422 |
+
} else if (lowerMessage.includes('statistic') || lowerMessage.includes('data')) {
|
423 |
+
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";
|
424 |
+
} else {
|
425 |
+
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?";
|
426 |
+
}
|
427 |
+
|
428 |
+
addBotMessage(response);
|
429 |
+
}
|
430 |
+
|
431 |
+
// Suggest questions button
|
432 |
+
suggestBtn.addEventListener('click', () => {
|
433 |
+
const suggestions = `
|
434 |
+
<div class="flex mb-6">
|
435 |
+
<div class="flex-shrink-0">
|
436 |
+
<div class="w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center">
|
437 |
+
<i class="fas fa-robot text-secondary"></i>
|
438 |
+
</div>
|
439 |
+
</div>
|
440 |
+
<div class="ml-4">
|
441 |
+
<div class="bot-message message-bubble">
|
442 |
+
<p class="font-bold text-secondary mb-1">PDF Assistant</p>
|
443 |
+
<p>Here are some questions you might ask about your document:</p>
|
444 |
+
<div class="grid grid-cols-1 gap-2 mt-3">
|
445 |
+
<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">
|
446 |
+
<i class="fas fa-question-circle text-secondary mr-2"></i>Summarize the key findings
|
447 |
+
</button>
|
448 |
+
<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">
|
449 |
+
<i class="fas fa-question-circle text-secondary mr-2"></i>What methodology was used in the research?
|
450 |
+
</button>
|
451 |
+
<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">
|
452 |
+
<i class="fas fa-question-circle text-secondary mr-2"></i>List the recommendations from conclusion
|
453 |
+
</button>
|
454 |
+
</div>
|
455 |
+
</div>
|
456 |
+
</div>
|
457 |
+
</div>
|
458 |
+
`;
|
459 |
+
|
460 |
+
chatContainer.insertAdjacentHTML('beforeend', suggestions);
|
461 |
+
chatContainer.scrollTop = chatContainer.scrollHeight;
|
462 |
+
|
463 |
+
// Add event listeners to suggestion buttons
|
464 |
+
document.querySelectorAll('.suggestion-btn').forEach(button => {
|
465 |
+
button.addEventListener('click', (e) => {
|
466 |
+
const text = e.target.textContent || e.target.innerText;
|
467 |
+
chatInput.value = text.split(' ').slice(1).join(' ');
|
468 |
+
chatInput.focus();
|
469 |
+
});
|
470 |
+
});
|
471 |
+
});
|
472 |
+
});
|
473 |
+
</script>
|
474 |
+
<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>
|
475 |
+
</html>
|