ikraamkb commited on
Commit
69003ff
·
verified ·
1 Parent(s): 1b06a03

Update static/appS.js

Browse files
Files changed (1) hide show
  1. static/appS.js +33 -42
static/appS.js CHANGED
@@ -153,56 +153,47 @@ document.addEventListener('DOMContentLoaded', () => {
153
  }
154
 
155
  async function handleSummarize() {
156
- if (!selectedFile) {
157
- displayError('Please upload a document first');
158
- return;
159
- }
160
 
161
- const length = document.querySelector('input[name="optionS"]:checked')?.value || "medium";
162
-
163
- // Clear conversation and show file preview
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
- try {
174
- const formData = new FormData();
175
- formData.append('file', selectedFile);
176
- formData.append('length', length);
177
 
178
- const response = await fetch('/summarize/', {
179
- method: 'POST',
180
- body: formData
181
- });
 
182
 
183
- if (!response.ok) {
184
- const error = await response.json();
185
- throw new Error(error.detail || 'Summarization failed');
 
 
 
 
 
 
 
186
  }
187
 
188
- const result = await response.json();
189
-
190
- // Remove thinking message and show results
191
- thinkingBubble.remove();
192
- displaySummaryResult(
193
- selectedFile.name,
194
- result.summary,
195
- result.audio_url || result.audioUrl,
196
- result.pdf_url || result.pdfUrl
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() {