Spaces:
Sleeping
Sleeping
Update static/appS.js
Browse files- static/appS.js +41 -1
static/appS.js
CHANGED
|
@@ -176,7 +176,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 176 |
return bubble;
|
| 177 |
}
|
| 178 |
|
| 179 |
-
|
| 180 |
if (!selectedFile) {
|
| 181 |
alert("Please upload a file first");
|
| 182 |
return;
|
|
@@ -241,6 +241,46 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 241 |
} finally {
|
| 242 |
selectedFile = null;
|
| 243 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
}
|
| 245 |
|
| 246 |
const style = document.createElement('style');
|
|
|
|
| 176 |
return bubble;
|
| 177 |
}
|
| 178 |
|
| 179 |
+
/* async function handleSubmit() {
|
| 180 |
if (!selectedFile) {
|
| 181 |
alert("Please upload a file first");
|
| 182 |
return;
|
|
|
|
| 241 |
} finally {
|
| 242 |
selectedFile = null;
|
| 243 |
}
|
| 244 |
+
} */
|
| 245 |
+
async function handleSubmit() {
|
| 246 |
+
if (!selectedFile) {
|
| 247 |
+
alert("Please upload a file first");
|
| 248 |
+
return;
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
const isSummarizeMode = document.querySelector('input[name="mode"]:checked').value === 'Summarize';
|
| 252 |
+
|
| 253 |
+
// ✅ Dynamic path handling for Hugging Face Spaces
|
| 254 |
+
const BASE_PATH = window.location.pathname.split('/').slice(0, 3).join('/');
|
| 255 |
+
const endpoint = isSummarizeMode
|
| 256 |
+
? `${BASE_PATH}/summarization/summarize/`
|
| 257 |
+
: `${BASE_PATH}/summarization/imagecaption/`;
|
| 258 |
+
|
| 259 |
+
const thinkingText = isSummarizeMode
|
| 260 |
+
? 'Processing document 📄... <div class="loader"></div>'
|
| 261 |
+
: "Generating caption 🖼️... <div class='loader'></div>";
|
| 262 |
+
|
| 263 |
+
const thinkingBubble = createMessageBubble(thinkingText, "Aidan");
|
| 264 |
+
|
| 265 |
+
try {
|
| 266 |
+
const response = await fetch(endpoint, {
|
| 267 |
+
method: 'POST',
|
| 268 |
+
body: formData
|
| 269 |
+
});
|
| 270 |
+
|
| 271 |
+
if (!response.ok) {
|
| 272 |
+
const error = await response.json().catch(() => null);
|
| 273 |
+
throw new Error(error?.detail || error?.error || "Request failed");
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
const result = await response.json();
|
| 277 |
+
// ... (rest of your success handling)
|
| 278 |
+
} catch (error) {
|
| 279 |
+
console.error("API Error:", error);
|
| 280 |
+
createMessageBubble(`⚠️ Error: ${error.message}`, "Aidan");
|
| 281 |
+
} finally {
|
| 282 |
+
thinkingBubble.remove();
|
| 283 |
+
}
|
| 284 |
}
|
| 285 |
|
| 286 |
const style = document.createElement('style');
|