Spaces:
Runtime error
Runtime error
Update static/index.html
Browse files- static/index.html +56 -24
static/index.html
CHANGED
|
@@ -178,6 +178,26 @@
|
|
| 178 |
.chat-input button:hover {
|
| 179 |
color: var(--accent-color);
|
| 180 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
</style>
|
| 182 |
</head>
|
| 183 |
|
|
@@ -195,6 +215,10 @@
|
|
| 195 |
</div>
|
| 196 |
|
| 197 |
<div class="chat-input">
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
<input type="text" id="chatInput" placeholder="Ask me anything...">
|
| 199 |
<button type="button" id="sendButton"><i class='bx bx-send'></i></button>
|
| 200 |
</div>
|
|
@@ -204,6 +228,7 @@
|
|
| 204 |
const chatMessages = document.getElementById('chatMessages');
|
| 205 |
const chatInput = document.getElementById('chatInput');
|
| 206 |
const sendButton = document.getElementById('sendButton');
|
|
|
|
| 207 |
|
| 208 |
// Function to add a message to the chat
|
| 209 |
function addMessage(sender, text) {
|
|
@@ -220,41 +245,46 @@
|
|
| 220 |
// Function to handle user input
|
| 221 |
async function handleUserInput() {
|
| 222 |
const userInput = chatInput.value.trim();
|
| 223 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
|
| 225 |
// Add user message to the chat
|
| 226 |
-
addMessage('user', userInput);
|
| 227 |
-
|
| 228 |
|
| 229 |
-
//
|
| 230 |
-
|
| 231 |
-
|
| 232 |
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
} else if (
|
| 243 |
endpoint = '/visualize';
|
| 244 |
-
|
| 245 |
-
} else if (userInput.startsWith("/translate")) {
|
| 246 |
endpoint = '/translate';
|
| 247 |
-
|
|
|
|
|
|
|
|
|
|
| 248 |
}
|
| 249 |
|
| 250 |
// Send the input to the backend
|
| 251 |
try {
|
| 252 |
const response = await fetch(endpoint, {
|
| 253 |
method: 'POST',
|
| 254 |
-
|
| 255 |
-
'Content-Type': 'application/json',
|
| 256 |
-
},
|
| 257 |
-
body: JSON.stringify(payload),
|
| 258 |
});
|
| 259 |
const data = await response.json();
|
| 260 |
addMessage('bot', JSON.stringify(data));
|
|
@@ -272,4 +302,6 @@
|
|
| 272 |
</script>
|
| 273 |
</body>
|
| 274 |
|
| 275 |
-
</html>
|
|
|
|
|
|
|
|
|
| 178 |
.chat-input button:hover {
|
| 179 |
color: var(--accent-color);
|
| 180 |
}
|
| 181 |
+
|
| 182 |
+
.file-upload {
|
| 183 |
+
display: flex;
|
| 184 |
+
align-items: center;
|
| 185 |
+
gap: 0.5rem;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
.file-upload label {
|
| 189 |
+
cursor: pointer;
|
| 190 |
+
color: var(--text-secondary-color);
|
| 191 |
+
transition: color 0.3s ease;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
.file-upload label:hover {
|
| 195 |
+
color: var(--accent-color);
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
.file-upload input[type="file"] {
|
| 199 |
+
display: none;
|
| 200 |
+
}
|
| 201 |
</style>
|
| 202 |
</head>
|
| 203 |
|
|
|
|
| 215 |
</div>
|
| 216 |
|
| 217 |
<div class="chat-input">
|
| 218 |
+
<div class="file-upload">
|
| 219 |
+
<label for="fileInput" title="Upload File"><i class='bx bx-upload'></i></label>
|
| 220 |
+
<input type="file" id="fileInput" accept=".pdf,.docx,.txt,image/*,.xlsx,.xls">
|
| 221 |
+
</div>
|
| 222 |
<input type="text" id="chatInput" placeholder="Ask me anything...">
|
| 223 |
<button type="button" id="sendButton"><i class='bx bx-send'></i></button>
|
| 224 |
</div>
|
|
|
|
| 228 |
const chatMessages = document.getElementById('chatMessages');
|
| 229 |
const chatInput = document.getElementById('chatInput');
|
| 230 |
const sendButton = document.getElementById('sendButton');
|
| 231 |
+
const fileInput = document.getElementById('fileInput');
|
| 232 |
|
| 233 |
// Function to add a message to the chat
|
| 234 |
function addMessage(sender, text) {
|
|
|
|
| 245 |
// Function to handle user input
|
| 246 |
async function handleUserInput() {
|
| 247 |
const userInput = chatInput.value.trim();
|
| 248 |
+
const file = fileInput.files[0];
|
| 249 |
+
|
| 250 |
+
if (!userInput && !file) {
|
| 251 |
+
alert("Please enter a prompt or upload a file.");
|
| 252 |
+
return;
|
| 253 |
+
}
|
| 254 |
|
| 255 |
// Add user message to the chat
|
| 256 |
+
if (userInput) addMessage('user', userInput);
|
| 257 |
+
if (file) addMessage('user', `Uploaded file: ${file.name}`);
|
| 258 |
|
| 259 |
+
// Clear the input fields
|
| 260 |
+
chatInput.value = '';
|
| 261 |
+
fileInput.value = '';
|
| 262 |
|
| 263 |
+
// Prepare the payload
|
| 264 |
+
const formData = new FormData();
|
| 265 |
+
if (file) formData.append('file', file);
|
| 266 |
+
if (userInput) formData.append('text', userInput);
|
| 267 |
+
|
| 268 |
+
// Determine the endpoint based on the input
|
| 269 |
+
let endpoint = '/summarize'; // Default to summarization
|
| 270 |
+
if (file && file.type.startsWith('image/')) {
|
| 271 |
+
endpoint = userInput ? '/vqa' : '/caption';
|
| 272 |
+
} else if (file && file.name.endsWith('.xlsx') || file.name.endsWith('.xls')) {
|
| 273 |
endpoint = '/visualize';
|
| 274 |
+
formData.append('request', userInput || "Generate a bar chart");
|
| 275 |
+
} else if (userInput && userInput.startsWith("/translate")) {
|
| 276 |
endpoint = '/translate';
|
| 277 |
+
formData.append('target_language', 'fr'); // Default to French
|
| 278 |
+
} else if (userInput && userInput.startsWith("/qa")) {
|
| 279 |
+
endpoint = '/answer';
|
| 280 |
+
formData.append('question', userInput.replace("/qa", "").trim());
|
| 281 |
}
|
| 282 |
|
| 283 |
// Send the input to the backend
|
| 284 |
try {
|
| 285 |
const response = await fetch(endpoint, {
|
| 286 |
method: 'POST',
|
| 287 |
+
body: formData,
|
|
|
|
|
|
|
|
|
|
| 288 |
});
|
| 289 |
const data = await response.json();
|
| 290 |
addMessage('bot', JSON.stringify(data));
|
|
|
|
| 302 |
</script>
|
| 303 |
</body>
|
| 304 |
|
| 305 |
+
</html>
|
| 306 |
+
|
| 307 |
+
|