Spaces:
Sleeping
Sleeping
Update static/appS.js
Browse files- static/appS.js +74 -75
static/appS.js
CHANGED
@@ -76,87 +76,86 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
76 |
);
|
77 |
}
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
audioIcon.title = "Click to unmute";
|
129 |
-
}
|
130 |
-
});
|
131 |
-
|
132 |
-
iconContainer.appendChild(audioIcon);
|
133 |
-
}
|
134 |
|
135 |
-
|
136 |
-
|
137 |
-
downloadIcon.href = fileName;
|
138 |
-
downloadIcon.target = "_blank";
|
139 |
-
downloadIcon.title = "Download PDF";
|
140 |
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
|
|
|
|
145 |
|
146 |
-
|
147 |
-
|
148 |
-
|
|
|
149 |
|
150 |
-
|
|
|
151 |
}
|
152 |
|
153 |
-
|
154 |
-
bubble.appendChild(message);
|
155 |
-
convo.appendChild(bubble);
|
156 |
-
convo.scrollTop = convo.scrollHeight;
|
157 |
-
return bubble;
|
158 |
}
|
159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
async function handleSubmit() {
|
161 |
if (!selectedFile) {
|
162 |
alert("Please upload a file first");
|
@@ -166,7 +165,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
166 |
const isSummarizeMode = document.querySelector('input[name="mode"]:checked').value === 'Summarize';
|
167 |
const endpoint = isSummarizeMode ? '/summarize/' : '/imagecaption/';
|
168 |
const thinkingText = isSummarizeMode ? 'Processing document...' : "Generating caption... <div class='loader'></div>";
|
169 |
-
const senderName =
|
170 |
|
171 |
const thinkingBubble = createMessageBubble(thinkingText, senderName);
|
172 |
|
@@ -197,7 +196,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
197 |
if (isSummarizeMode) {
|
198 |
createMessageBubble(
|
199 |
result.summary || "No summary generated.",
|
200 |
-
"
|
201 |
result.audioUrl,
|
202 |
result.pdfUrl
|
203 |
);
|
|
|
76 |
);
|
77 |
}
|
78 |
|
79 |
+
function createMessageBubble(text, sender = "You", audioSrc = null, fileName = null) {
|
80 |
+
const bubble = document.createElement('div');
|
81 |
+
bubble.className = `bubble ${sender === "You" ? "right" : "left"}`;
|
82 |
+
bubble.style.maxWidth = "50%";
|
83 |
+
bubble.style.wordWrap = "break-word";
|
84 |
+
|
85 |
+
const label = document.createElement('div');
|
86 |
+
label.className = "label";
|
87 |
+
label.textContent = sender;
|
88 |
+
|
89 |
+
const message = document.createElement('div');
|
90 |
+
message.className = "text";
|
91 |
+
message.style.whiteSpace = "pre-wrap";
|
92 |
+
message.style.display = "flex";
|
93 |
+
message.style.flexDirection = "column";
|
94 |
+
|
95 |
+
const textSpan = document.createElement("span");
|
96 |
+
textSpan.innerHTML = text;
|
97 |
+
message.appendChild(textSpan);
|
98 |
+
|
99 |
+
if (sender !== "You" && (audioSrc || fileName)) {
|
100 |
+
const iconContainer = document.createElement('div');
|
101 |
+
iconContainer.style.marginTop = "10px";
|
102 |
+
iconContainer.style.display = "flex";
|
103 |
+
iconContainer.style.justifyContent = "flex-end";
|
104 |
+
iconContainer.style.gap = "15px";
|
105 |
+
|
106 |
+
// 🎵 Audio Icon
|
107 |
+
if (audioSrc) {
|
108 |
+
const audio = new Audio(audioSrc);
|
109 |
+
const audioIcon = document.createElement("i");
|
110 |
+
audioIcon.className = "fa-solid fa-volume-high audio-toggle";
|
111 |
+
audioIcon.title = "Play Audio";
|
112 |
+
audioIcon.style.cursor = "pointer";
|
113 |
+
audioIcon.style.fontSize = "18px";
|
114 |
+
|
115 |
+
audioIcon.addEventListener("click", () => {
|
116 |
+
if (audio.paused) {
|
117 |
+
audio.play();
|
118 |
+
audioIcon.classList.remove("fa-volume-xmark");
|
119 |
+
audioIcon.classList.add("fa-volume-high");
|
120 |
+
audioIcon.title = "Mute Audio";
|
121 |
+
} else {
|
122 |
+
audio.pause();
|
123 |
+
audioIcon.classList.remove("fa-volume-high");
|
124 |
+
audioIcon.classList.add("fa-volume-xmark");
|
125 |
+
audioIcon.title = "Unmute Audio";
|
126 |
+
}
|
127 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
+
iconContainer.appendChild(audioIcon);
|
130 |
+
}
|
|
|
|
|
|
|
131 |
|
132 |
+
// 📥 Download Icon
|
133 |
+
if (fileName) {
|
134 |
+
const downloadLink = document.createElement('a');
|
135 |
+
downloadLink.href = fileName;
|
136 |
+
downloadLink.target = "_blank";
|
137 |
+
downloadLink.title = "Download PDF";
|
138 |
|
139 |
+
const downloadIcon = document.createElement("i");
|
140 |
+
downloadIcon.className = "fa-solid fa-file-arrow-down";
|
141 |
+
downloadIcon.style.fontSize = "18px";
|
142 |
+
downloadIcon.style.cursor = "pointer";
|
143 |
|
144 |
+
downloadLink.appendChild(downloadIcon);
|
145 |
+
iconContainer.appendChild(downloadLink);
|
146 |
}
|
147 |
|
148 |
+
message.appendChild(iconContainer);
|
|
|
|
|
|
|
|
|
149 |
}
|
150 |
|
151 |
+
bubble.appendChild(label);
|
152 |
+
bubble.appendChild(message);
|
153 |
+
convo.appendChild(bubble);
|
154 |
+
convo.scrollTop = convo.scrollHeight;
|
155 |
+
return bubble;
|
156 |
+
}
|
157 |
+
|
158 |
+
|
159 |
async function handleSubmit() {
|
160 |
if (!selectedFile) {
|
161 |
alert("Please upload a file first");
|
|
|
165 |
const isSummarizeMode = document.querySelector('input[name="mode"]:checked').value === 'Summarize';
|
166 |
const endpoint = isSummarizeMode ? '/summarize/' : '/imagecaption/';
|
167 |
const thinkingText = isSummarizeMode ? 'Processing document...' : "Generating caption... <div class='loader'></div>";
|
168 |
+
const senderName = 'Aidan';
|
169 |
|
170 |
const thinkingBubble = createMessageBubble(thinkingText, senderName);
|
171 |
|
|
|
196 |
if (isSummarizeMode) {
|
197 |
createMessageBubble(
|
198 |
result.summary || "No summary generated.",
|
199 |
+
"Aidan",
|
200 |
result.audioUrl,
|
201 |
result.pdfUrl
|
202 |
);
|