Spaces:
Sleeping
Sleeping
Update static/appS.js
Browse files- static/appS.js +52 -52
static/appS.js
CHANGED
|
@@ -276,63 +276,63 @@ function injectAudioPlayer(bubble, audioUrl) {
|
|
| 276 |
audioContainer.appendChild(audioIcon);
|
| 277 |
messageDiv.appendChild(audioContainer);
|
| 278 |
} */
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
}
|
| 284 |
|
| 285 |
-
const
|
| 286 |
-
|
| 287 |
-
const thinkingText = isSummarizeMode ? 'Processing document 📄... <div class="loader"></div>' : "Generating caption 🖼️ ... <div class='loader'></div>";
|
| 288 |
-
const senderName = "Aidan";
|
| 289 |
-
|
| 290 |
-
const thinkingBubble = createMessageBubble(thinkingText, senderName);
|
| 291 |
-
|
| 292 |
-
const formData = new FormData();
|
| 293 |
-
formData.append('file', selectedFile);
|
| 294 |
-
if (isSummarizeMode) formData.append('length', 'medium');
|
| 295 |
-
|
| 296 |
-
try {
|
| 297 |
-
const response = await fetch(endpoint, {
|
| 298 |
-
method: 'POST',
|
| 299 |
-
body: formData
|
| 300 |
-
});
|
| 301 |
-
|
| 302 |
-
if (!response.ok) {
|
| 303 |
-
let errorMessage = 'Request failed';
|
| 304 |
-
try {
|
| 305 |
-
const error = await response.json();
|
| 306 |
-
errorMessage = error.detail || error.error || errorMessage;
|
| 307 |
-
} catch (e) {}
|
| 308 |
-
throw new Error(errorMessage);
|
| 309 |
-
}
|
| 310 |
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
result.audio,
|
| 326 |
-
null
|
| 327 |
-
);
|
| 328 |
-
}
|
| 329 |
-
} catch (error) {
|
| 330 |
-
thinkingBubble.remove();
|
| 331 |
-
createMessageBubble(`⚠️ Error: ${error.message}`, "Aidan");
|
| 332 |
-
} finally {
|
| 333 |
-
selectedFile = null; // ✅ Reset selected file AFTER send
|
| 334 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
}
|
|
|
|
| 336 |
|
| 337 |
const style = document.createElement('style');
|
| 338 |
style.textContent = `
|
|
|
|
| 276 |
audioContainer.appendChild(audioIcon);
|
| 277 |
messageDiv.appendChild(audioContainer);
|
| 278 |
} */
|
| 279 |
+
async function handleSubmit() {
|
| 280 |
+
if (!selectedFile) {
|
| 281 |
+
alert("Please upload a file first");
|
| 282 |
+
return;
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
const isSummarizeMode = document.querySelector('input[name="mode"]:checked').value === 'Summarize';
|
| 286 |
+
const endpoint = isSummarizeMode ? '/Summarization/summarize/' : '/Summarization/imagecaption/';
|
| 287 |
+
const thinkingText = isSummarizeMode ? 'Processing document 📄... <div class="loader"></div>' : "Generating caption 🖼️ ... <div class='loader'></div>";
|
| 288 |
+
const senderName = "Aidan";
|
| 289 |
+
|
| 290 |
+
const thinkingBubble = createMessageBubble(thinkingText, senderName);
|
| 291 |
+
|
| 292 |
+
const formData = new FormData();
|
| 293 |
+
formData.append('file', selectedFile);
|
| 294 |
+
if (isSummarizeMode) formData.append('length', 'medium');
|
| 295 |
+
|
| 296 |
+
try {
|
| 297 |
+
const response = await fetch(endpoint, {
|
| 298 |
+
method: 'POST',
|
| 299 |
+
body: formData
|
| 300 |
+
});
|
| 301 |
+
|
| 302 |
+
if (!response.ok) {
|
| 303 |
+
let errorMessage = 'Request failed';
|
| 304 |
+
try {
|
| 305 |
+
const error = await response.json();
|
| 306 |
+
errorMessage = error.detail || error.error || errorMessage;
|
| 307 |
+
} catch (e) {}
|
| 308 |
+
throw new Error(errorMessage);
|
| 309 |
}
|
| 310 |
|
| 311 |
+
const result = await response.json();
|
| 312 |
+
thinkingBubble.remove();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
|
| 314 |
+
if (isSummarizeMode) {
|
| 315 |
+
createMessageBubble(
|
| 316 |
+
result.summary || "No summary generated.",
|
| 317 |
+
"Aidan",
|
| 318 |
+
null, // Removed audioUrl
|
| 319 |
+
result.pdfUrl
|
| 320 |
+
);
|
| 321 |
+
} else {
|
| 322 |
+
createMessageBubble(
|
| 323 |
+
result.caption || result.answer || "No caption generated.",
|
| 324 |
+
"Aidan",
|
| 325 |
+
null, // Removed audio
|
| 326 |
+
null
|
| 327 |
+
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
}
|
| 329 |
+
} catch (error) {
|
| 330 |
+
thinkingBubble.remove();
|
| 331 |
+
createMessageBubble(`⚠️ Error: ${error.message}`, "Aidan");
|
| 332 |
+
} finally {
|
| 333 |
+
selectedFile = null;
|
| 334 |
}
|
| 335 |
+
}
|
| 336 |
|
| 337 |
const style = document.createElement('style');
|
| 338 |
style.textContent = `
|