Spaces:
Running
Running
Update static/appS.js
Browse files- static/appS.js +33 -42
static/appS.js
CHANGED
@@ -153,56 +153,47 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
153 |
}
|
154 |
|
155 |
async function handleSummarize() {
|
156 |
-
|
157 |
-
displayError('Please upload a document first');
|
158 |
-
return;
|
159 |
-
}
|
160 |
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
convo.innerHTML = '';
|
165 |
-
displayFileInfo(selectedFile.name, 'document');
|
166 |
-
|
167 |
-
// Show correct processing message for summarization
|
168 |
-
const thinkingBubble = createMessageBubble(
|
169 |
-
"Analyzing document and generating summary... <div class='loader'></div>",
|
170 |
-
"Aidan"
|
171 |
-
);
|
172 |
|
173 |
-
|
174 |
-
const formData = new FormData();
|
175 |
-
formData.append('file', selectedFile);
|
176 |
-
formData.append('length', length);
|
177 |
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
|
|
182 |
|
183 |
-
|
184 |
-
|
185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
}
|
187 |
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
);
|
198 |
-
|
199 |
-
} catch (error) {
|
200 |
-
thinkingBubble.remove();
|
201 |
-
displayError(error.message || 'Failed to summarize document');
|
202 |
-
} finally {
|
203 |
-
resetFileInputs();
|
204 |
}
|
|
|
|
|
205 |
}
|
|
|
|
|
206 |
|
207 |
|
208 |
async function handleCaption() {
|
|
|
153 |
}
|
154 |
|
155 |
async function handleSummarize() {
|
156 |
+
if (!selectedFile) return;
|
|
|
|
|
|
|
157 |
|
158 |
+
const formData = new FormData();
|
159 |
+
formData.append('file', selectedFile);
|
160 |
+
formData.append('length', 'medium'); // or short/long if you allow user choice
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
|
162 |
+
const bubble = createMessageBubble('Processing document...', 'Assistant');
|
|
|
|
|
|
|
163 |
|
164 |
+
try {
|
165 |
+
const response = await fetch('/summarize/', {
|
166 |
+
method: 'POST',
|
167 |
+
body: formData,
|
168 |
+
});
|
169 |
|
170 |
+
const data = await response.json();
|
171 |
+
if (response.ok) {
|
172 |
+
let summary = data.summary || "No summary generated.";
|
173 |
+
createMessageBubble(summary, "Assistant");
|
174 |
+
|
175 |
+
if (data.audioUrl) {
|
176 |
+
const audio = document.createElement('audio');
|
177 |
+
audio.src = data.audioUrl;
|
178 |
+
audio.controls = true;
|
179 |
+
bubble.appendChild(audio);
|
180 |
}
|
181 |
|
182 |
+
if (data.pdfUrl) {
|
183 |
+
const link = document.createElement('a');
|
184 |
+
link.href = data.pdfUrl;
|
185 |
+
link.textContent = 'Download Summary PDF';
|
186 |
+
link.target = "_blank";
|
187 |
+
bubble.appendChild(link);
|
188 |
+
}
|
189 |
+
} else {
|
190 |
+
createMessageBubble(`Error: ${data.detail || "Failed to summarize"}`, "Assistant");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
}
|
192 |
+
} catch (error) {
|
193 |
+
createMessageBubble(`Error: ${error.message}`, "Assistant");
|
194 |
}
|
195 |
+
}
|
196 |
+
|
197 |
|
198 |
|
199 |
async function handleCaption() {
|