ikraamkb commited on
Commit
82d4697
Β·
verified Β·
1 Parent(s): 7d1820b

Update static/appS.js

Browse files
Files changed (1) hide show
  1. static/appS.js +19 -21
static/appS.js CHANGED
@@ -55,14 +55,10 @@ document.addEventListener('DOMContentLoaded', () => {
55
  }
56
  });
57
 
58
- // "Got it" button to hide explanation div
59
- if (gotItButton) {
60
- gotItButton.addEventListener('click', () => {
61
- if (explainChoixDiv) {
62
- explainChoixDiv.style.display = "none";
63
- }
64
- });
65
- }
66
 
67
  // Send button handlers
68
  sendButtons.forEach(button => {
@@ -71,14 +67,13 @@ document.addEventListener('DOMContentLoaded', () => {
71
 
72
  function displayFilePreview(file) {
73
  if (filePreviewBubble) filePreviewBubble.remove();
74
-
75
  filePreviewBubble = createMessageBubble(
76
  `πŸ“Ž Selected ${file.type.startsWith('image/') ? 'image' : 'document'}: ${file.name}`,
77
  "You"
78
  );
79
  }
80
 
81
- function createMessageBubble(text, sender = "You", audioSrc = null, fileName = null) {
82
  const bubble = document.createElement('div');
83
  bubble.className = `bubble ${sender === "You" ? "right" : "left"}`;
84
  bubble.style.maxWidth = "50%";
@@ -98,7 +93,7 @@ document.addEventListener('DOMContentLoaded', () => {
98
  textSpan.innerHTML = text;
99
  message.appendChild(textSpan);
100
 
101
- if (sender !== "You" && (audioSrc || fileName)) {
102
  const iconContainer = document.createElement('div');
103
  iconContainer.style.marginTop = "10px";
104
  iconContainer.style.display = "flex";
@@ -130,11 +125,11 @@ document.addEventListener('DOMContentLoaded', () => {
130
  iconContainer.appendChild(audioIcon);
131
  }
132
 
133
- if (fileName) {
134
  const downloadLink = document.createElement('a');
135
- downloadLink.href = fileName;
 
136
  downloadLink.target = "_blank";
137
- downloadLink.download = "summary.pdf"; // βœ… Suggest filename to browser
138
 
139
  const downloadIcon = document.createElement("i");
140
  downloadIcon.className = "fa-solid fa-file-arrow-down";
@@ -163,14 +158,19 @@ document.addEventListener('DOMContentLoaded', () => {
163
 
164
  const isSummarizeMode = document.querySelector('input[name="mode"]:checked').value === 'Summarize';
165
  const endpoint = isSummarizeMode ? '/summarize/' : '/imagecaption/';
166
- const thinkingText = isSummarizeMode ? 'Processing document...' : "Generating caption... <div class='loader'></div>";
167
  const senderName = "Aidan";
168
 
169
  const thinkingBubble = createMessageBubble(thinkingText, senderName);
170
 
171
  const formData = new FormData();
172
  formData.append('file', selectedFile);
173
- if (isSummarizeMode) formData.append('length', 'medium');
 
 
 
 
 
174
 
175
  try {
176
  const response = await fetch(endpoint, {
@@ -183,9 +183,7 @@ document.addEventListener('DOMContentLoaded', () => {
183
  try {
184
  const error = await response.json();
185
  errorMessage = error.detail || error.error || errorMessage;
186
- } catch (e) {
187
- // response not JSON
188
- }
189
  throw new Error(errorMessage);
190
  }
191
 
@@ -211,7 +209,7 @@ document.addEventListener('DOMContentLoaded', () => {
211
  thinkingBubble.remove();
212
  createMessageBubble(`⚠️ Error: ${error.message}`, "Aidan");
213
  } finally {
214
- resetFileInputs(); // βœ… Only reset upload inputs, KEEP preview bubble
215
  }
216
  }
217
 
@@ -219,7 +217,7 @@ document.addEventListener('DOMContentLoaded', () => {
219
  selectedFile = null;
220
  fileUpload.value = '';
221
  imageUpload.value = '';
222
- // βœ… DO NOT remove file preview bubble anymore
223
  }
224
 
225
  // Loader CSS
 
55
  }
56
  });
57
 
58
+ // "Got it" button
59
+ gotItButton.addEventListener('click', () => {
60
+ explainChoixDiv.style.display = "none";
61
+ });
 
 
 
 
62
 
63
  // Send button handlers
64
  sendButtons.forEach(button => {
 
67
 
68
  function displayFilePreview(file) {
69
  if (filePreviewBubble) filePreviewBubble.remove();
 
70
  filePreviewBubble = createMessageBubble(
71
  `πŸ“Ž Selected ${file.type.startsWith('image/') ? 'image' : 'document'}: ${file.name}`,
72
  "You"
73
  );
74
  }
75
 
76
+ function createMessageBubble(text, sender = "You", audioSrc = null, fileUrl = null) {
77
  const bubble = document.createElement('div');
78
  bubble.className = `bubble ${sender === "You" ? "right" : "left"}`;
79
  bubble.style.maxWidth = "50%";
 
93
  textSpan.innerHTML = text;
94
  message.appendChild(textSpan);
95
 
96
+ if (sender !== "You" && (audioSrc || fileUrl)) {
97
  const iconContainer = document.createElement('div');
98
  iconContainer.style.marginTop = "10px";
99
  iconContainer.style.display = "flex";
 
125
  iconContainer.appendChild(audioIcon);
126
  }
127
 
128
+ if (fileUrl) {
129
  const downloadLink = document.createElement('a');
130
+ downloadLink.href = fileUrl;
131
+ downloadLink.setAttribute('download', 'summary.pdf');
132
  downloadLink.target = "_blank";
 
133
 
134
  const downloadIcon = document.createElement("i");
135
  downloadIcon.className = "fa-solid fa-file-arrow-down";
 
158
 
159
  const isSummarizeMode = document.querySelector('input[name="mode"]:checked').value === 'Summarize';
160
  const endpoint = isSummarizeMode ? '/summarize/' : '/imagecaption/';
161
+ const thinkingText = isSummarizeMode ? 'Processing document... <div class="loader"></div>' : 'Generating caption... <div class="loader"></div>';
162
  const senderName = "Aidan";
163
 
164
  const thinkingBubble = createMessageBubble(thinkingText, senderName);
165
 
166
  const formData = new FormData();
167
  formData.append('file', selectedFile);
168
+
169
+ if (isSummarizeMode) {
170
+ // Grab length choice if exists (short, medium, long)
171
+ const selectedLength = document.querySelector('input[name="length"]:checked')?.value || 'medium';
172
+ formData.append('length', selectedLength);
173
+ }
174
 
175
  try {
176
  const response = await fetch(endpoint, {
 
183
  try {
184
  const error = await response.json();
185
  errorMessage = error.detail || error.error || errorMessage;
186
+ } catch (e) { }
 
 
187
  throw new Error(errorMessage);
188
  }
189
 
 
209
  thinkingBubble.remove();
210
  createMessageBubble(`⚠️ Error: ${error.message}`, "Aidan");
211
  } finally {
212
+ resetFileInputs();
213
  }
214
  }
215
 
 
217
  selectedFile = null;
218
  fileUpload.value = '';
219
  imageUpload.value = '';
220
+ // πŸ›‘ File preview bubble stays!
221
  }
222
 
223
  // Loader CSS