Spaces:
Running
Running
Update static/application.js
Browse files- static/application.js +51 -59
static/application.js
CHANGED
@@ -300,29 +300,46 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
300 |
|
301 |
filePreviewBubble = document.createElement("div");
|
302 |
filePreviewBubble.className = "file-preview-bubble bubble right";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
303 |
|
304 |
-
|
305 |
-
filePreviewBubble
|
306 |
-
|
307 |
-
// Create an image element for preview
|
308 |
-
const img = document.createElement("img");
|
309 |
-
img.src = URL.createObjectURL(file);
|
310 |
-
img.alt = "Selected Image";
|
311 |
-
img.style.maxWidth = "100%"; // Make the image fill the bubble width
|
312 |
-
img.style.borderRadius = "8px"; // Optional: Rounded corners for images
|
313 |
-
|
314 |
-
// Append the image to the preview bubble
|
315 |
-
filePreviewBubble.appendChild(img);
|
316 |
-
filePreviewBubble.appendChild(document.createTextNode(` Selected: ${file.name}`));
|
317 |
}
|
318 |
-
|
319 |
-
convo.appendChild(filePreviewBubble);
|
320 |
-
convo.scrollTop = convo.scrollHeight;
|
321 |
}
|
322 |
|
323 |
-
function createMessageBubble(text, sender = "You", audioSrc = null, fileName = null) {
|
324 |
const bubble = document.createElement("div");
|
325 |
bubble.className = `bubble ${sender === "You" ? "right" : "left"}`;
|
|
|
326 |
|
327 |
const label = document.createElement("div");
|
328 |
label.className = "label";
|
@@ -332,46 +349,20 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
332 |
message.className = "text";
|
333 |
message.style.whiteSpace = "pre-wrap";
|
334 |
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
} else {
|
339 |
-
message.style.display = "flex";
|
340 |
-
message.style.justifyContent = "space-between";
|
341 |
-
message.style.alignItems = "center";
|
342 |
-
|
343 |
-
const msgSpan = document.createElement("span");
|
344 |
-
msgSpan.innerHTML = text;
|
345 |
-
message.appendChild(msgSpan);
|
346 |
-
|
347 |
-
if (audioSrc) {
|
348 |
-
const icon = document.createElement("i");
|
349 |
-
icon.className = "fa-solid fa-volume-high audio-toggle";
|
350 |
-
icon.title = "Click to mute";
|
351 |
-
icon.style.cursor = "pointer";
|
352 |
-
icon.style.fontSize = "18px";
|
353 |
-
|
354 |
-
const audio = new Audio(audioSrc);
|
355 |
-
audio.play();
|
356 |
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
icon.classList.remove("fa-volume-high");
|
368 |
-
icon.classList.add("fa-volume-xmark");
|
369 |
-
icon.title = "Click to unmute";
|
370 |
-
}
|
371 |
-
});
|
372 |
-
|
373 |
-
message.appendChild(icon);
|
374 |
-
}
|
375 |
}
|
376 |
|
377 |
bubble.appendChild(label);
|
@@ -397,7 +388,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
397 |
}
|
398 |
|
399 |
// Create user's message bubble
|
400 |
-
createMessageBubble(question, "You", null, selectedFile.name);
|
401 |
|
402 |
// Thinking bubble with loader
|
403 |
const thinkingBubble = createMessageBubble("Wait, let me think π€... <div class='loader'></div>", "Aidan");
|
@@ -418,7 +409,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
418 |
|
419 |
// Update the thinking bubble to show the answer text and remove the loader
|
420 |
const message = thinkingBubble.querySelector(".text");
|
421 |
-
message.innerHTML = answerText;
|
422 |
|
423 |
// If audio exists, add audio toggle icon
|
424 |
if (audioSrc) {
|
@@ -488,4 +479,5 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
488 |
}
|
489 |
`;
|
490 |
document.head.appendChild(style);
|
491 |
-
|
|
|
|
300 |
|
301 |
filePreviewBubble = document.createElement("div");
|
302 |
filePreviewBubble.className = "file-preview-bubble bubble right";
|
303 |
+
filePreviewBubble.style.display = "flex";
|
304 |
+
filePreviewBubble.style.flexDirection = "column";
|
305 |
+
filePreviewBubble.style.maxWidth = "50%";
|
306 |
+
|
307 |
+
if (file.type.startsWith('image/')) {
|
308 |
+
const reader = new FileReader();
|
309 |
+
reader.onload = (e) => {
|
310 |
+
const img = document.createElement("img");
|
311 |
+
img.src = e.target.result;
|
312 |
+
img.style.width = "100%";
|
313 |
+
img.style.height = "200px";
|
314 |
+
img.style.objectFit = "cover";
|
315 |
+
img.style.borderRadius = "10px";
|
316 |
+
img.style.marginBottom = "8px";
|
317 |
+
|
318 |
+
const text = document.createElement("span");
|
319 |
+
text.textContent = `π Selected image: ${file.name}`;
|
320 |
+
text.style.fontSize = "13px";
|
321 |
+
|
322 |
+
filePreviewBubble.appendChild(img);
|
323 |
+
filePreviewBubble.appendChild(text);
|
324 |
+
convo.appendChild(filePreviewBubble);
|
325 |
+
convo.scrollTop = convo.scrollHeight;
|
326 |
+
};
|
327 |
+
reader.readAsDataURL(file);
|
328 |
+
} else {
|
329 |
+
const text = document.createElement("span");
|
330 |
+
text.textContent = `π Selected document: ${file.name}`;
|
331 |
+
text.style.fontSize = "13px";
|
332 |
|
333 |
+
filePreviewBubble.appendChild(text);
|
334 |
+
convo.appendChild(filePreviewBubble);
|
335 |
+
convo.scrollTop = convo.scrollHeight;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
336 |
}
|
|
|
|
|
|
|
337 |
}
|
338 |
|
339 |
+
function createMessageBubble(text, sender = "You", audioSrc = null, fileName = null, imageSrc = null) {
|
340 |
const bubble = document.createElement("div");
|
341 |
bubble.className = `bubble ${sender === "You" ? "right" : "left"}`;
|
342 |
+
bubble.style.maxWidth = "50%";
|
343 |
|
344 |
const label = document.createElement("div");
|
345 |
label.className = "label";
|
|
|
349 |
message.className = "text";
|
350 |
message.style.whiteSpace = "pre-wrap";
|
351 |
|
352 |
+
const textSpan = document.createElement("span");
|
353 |
+
textSpan.innerHTML = text;
|
354 |
+
message.appendChild(textSpan);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
355 |
|
356 |
+
// Display image if available
|
357 |
+
if (imageSrc) {
|
358 |
+
const img = document.createElement("img");
|
359 |
+
img.src = imageSrc;
|
360 |
+
img.style.width = "100%";
|
361 |
+
img.style.height = "200px";
|
362 |
+
img.style.objectFit = "cover";
|
363 |
+
img.style.borderRadius = "10px";
|
364 |
+
img.style.marginTop = "8px";
|
365 |
+
message.appendChild(img);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
366 |
}
|
367 |
|
368 |
bubble.appendChild(label);
|
|
|
388 |
}
|
389 |
|
390 |
// Create user's message bubble
|
391 |
+
createMessageBubble(question, "You", null, selectedFile.name, selectedFile.type.startsWith('image/') ? URL.createObjectURL(selectedFile) : null);
|
392 |
|
393 |
// Thinking bubble with loader
|
394 |
const thinkingBubble = createMessageBubble("Wait, let me think π€... <div class='loader'></div>", "Aidan");
|
|
|
409 |
|
410 |
// Update the thinking bubble to show the answer text and remove the loader
|
411 |
const message = thinkingBubble.querySelector(".text");
|
412 |
+
message.innerHTML = answerText;
|
413 |
|
414 |
// If audio exists, add audio toggle icon
|
415 |
if (audioSrc) {
|
|
|
479 |
}
|
480 |
`;
|
481 |
document.head.appendChild(style);
|
482 |
+
|
483 |
+
});
|