ikraamkb commited on
Commit
8e4e74f
Β·
verified Β·
1 Parent(s): 5487c8e

Update static/appS.js

Browse files
Files changed (1) hide show
  1. static/appS.js +78 -90
static/appS.js CHANGED
@@ -7,6 +7,8 @@ document.addEventListener('DOMContentLoaded', () => {
7
  const sendButtons = document.querySelectorAll('.sendingQA');
8
  const SummarizeInput = document.querySelector(".SummarizeInput");
9
  const CaptionInput = document.querySelector(".CaptionInput");
 
 
10
 
11
  let selectedFile = null;
12
  let filePreviewBubble = null;
@@ -49,34 +51,16 @@ document.addEventListener('DOMContentLoaded', () => {
49
  }
50
  });
51
 
52
- // Drag and drop
53
- convo.addEventListener('dragover', (e) => {
54
- e.preventDefault();
55
- convo.classList.add('drag-over');
56
- });
57
-
58
- convo.addEventListener('dragleave', () => {
59
- convo.classList.remove('drag-over');
60
- });
61
-
62
- convo.addEventListener('drop', (e) => {
63
- e.preventDefault();
64
- convo.classList.remove('drag-over');
65
- if (e.dataTransfer.files.length) {
66
- const file = e.dataTransfer.files[0];
67
- const dataTransfer = new DataTransfer();
68
- dataTransfer.items.add(file);
69
 
70
- const isSummarizeMode = document.querySelector('input[name="mode"]:checked').value === 'Summarize';
71
- if (isSummarizeMode) {
72
- fileUpload.files = dataTransfer.files;
73
- } else {
74
- imageUpload.files = dataTransfer.files;
75
  }
76
- selectedFile = file;
77
- displayFilePreview(file);
78
- }
79
- });
80
 
81
  // Send button handlers
82
  sendButtons.forEach(button => {
@@ -92,9 +76,11 @@ document.addEventListener('DOMContentLoaded', () => {
92
  );
93
  }
94
 
95
- function createMessageBubble(text, sender = "You", audioSrc = null) {
96
  const bubble = document.createElement('div');
97
  bubble.className = `bubble ${sender === "You" ? "right" : "left"}`;
 
 
98
 
99
  const label = document.createElement('div');
100
  label.className = "label";
@@ -102,40 +88,66 @@ document.addEventListener('DOMContentLoaded', () => {
102
 
103
  const message = document.createElement('div');
104
  message.className = "text";
 
 
 
105
 
106
- if (sender === "You") {
107
- message.textContent = text;
108
- } else {
109
- message.innerHTML = typeof text === 'string' ? text : 'Processing...';
 
 
 
 
 
 
110
 
111
  if (audioSrc) {
112
- const audioContainer = document.createElement('div');
113
- audioContainer.style.display = 'flex';
114
- audioContainer.style.alignItems = 'center';
115
- audioContainer.style.gap = '10px';
116
- audioContainer.style.marginTop = '8px';
117
 
118
  const audio = new Audio(audioSrc);
119
- const audioIcon = document.createElement('i');
120
- audioIcon.className = 'fa-solid fa-volume-high audio-toggle';
121
- audioIcon.style.cursor = 'pointer';
122
-
123
- audioIcon.addEventListener('click', () => {
124
- if (audio.paused) {
125
- audio.play();
126
- audioIcon.classList.replace('fa-volume-xmark', 'fa-volume-high');
127
  audioIcon.title = "Click to mute";
 
128
  } else {
129
- audio.pause();
130
- audioIcon.classList.replace('fa-volume-high', 'fa-volume-xmark');
 
131
  audioIcon.title = "Click to unmute";
132
  }
133
  });
134
 
135
- audioContainer.appendChild(audioIcon);
136
- audioContainer.appendChild(document.createTextNode('Listen'));
137
- message.appendChild(audioContainer);
138
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  }
140
 
141
  bubble.appendChild(label);
@@ -168,42 +180,30 @@ document.addEventListener('DOMContentLoaded', () => {
168
  body: formData
169
  });
170
 
171
- if (!response.ok) {
172
- let errorMessage = 'Request failed';
173
- try {
174
- const error = await response.json();
175
- errorMessage = error.detail || error.error || errorMessage;
176
- } catch (e) {
177
- // Response wasn't valid JSON
178
- }
179
- throw new Error(errorMessage);
180
- }
181
 
182
  const result = await response.json();
183
  thinkingBubble.remove();
184
 
185
  if (isSummarizeMode) {
186
- createMessageBubble(result.summary || "No summary generated.", "Assistant");
187
-
188
- if (result.audioUrl) {
189
- const audio = document.createElement('audio');
190
- audio.src = result.audioUrl;
191
- audio.controls = true;
192
- convo.appendChild(audio);
193
- }
194
-
195
- if (result.pdfUrl) {
196
- const link = document.createElement('a');
197
- link.href = result.pdfUrl;
198
- link.textContent = 'Download Summary PDF';
199
- link.className = 'download-link';
200
- link.target = "_blank";
201
- convo.appendChild(link);
202
- }
203
  } else {
204
  createMessageBubble(
205
- `<strong>Caption:</strong><br><br>${result.answer || result.caption}
206
- ${result.audio ? `<br><audio controls src="${result.audio}"></audio>` : ''}`,
207
  "Aidan",
208
  result.audio
209
  );
@@ -242,18 +242,6 @@ document.addEventListener('DOMContentLoaded', () => {
242
  0% { transform: rotate(0deg); }
243
  100% { transform: rotate(360deg); }
244
  }
245
- .download-link {
246
- display: inline-block;
247
- margin-top: 10px;
248
- padding: 5px 10px;
249
- background: #3b82f6;
250
- color: white;
251
- border-radius: 5px;
252
- text-decoration: none;
253
- }
254
- .download-link:hover {
255
- background: #2563eb;
256
- }
257
  .audio-toggle {
258
  cursor: pointer;
259
  transition: all 0.2s;
 
7
  const sendButtons = document.querySelectorAll('.sendingQA');
8
  const SummarizeInput = document.querySelector(".SummarizeInput");
9
  const CaptionInput = document.querySelector(".CaptionInput");
10
+ const gotItButton = document.getElementById('got-it-btn'); // βœ… Button to hide explain div
11
+ const explainChoixDiv = document.getElementById('explainChoix'); // βœ… Div to hide
12
 
13
  let selectedFile = null;
14
  let filePreviewBubble = null;
 
51
  }
52
  });
53
 
54
+ // βœ… REMOVE Drag & Drop handlers (completely deleted!)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
+ // βœ… "Got it" button to hide explanation div
57
+ if (gotItButton) {
58
+ gotItButton.addEventListener('click', () => {
59
+ if (explainChoixDiv) {
60
+ explainChoixDiv.style.display = "none";
61
  }
62
+ });
63
+ }
 
 
64
 
65
  // Send button handlers
66
  sendButtons.forEach(button => {
 
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%"; // βœ… Max width 50% of screen
83
+ bubble.style.wordWrap = "break-word";
84
 
85
  const label = document.createElement('div');
86
  label.className = "label";
 
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.innerText = text;
97
+ message.appendChild(textSpan);
98
+
99
+ if (sender !== "You") {
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 = "10px";
105
 
106
  if (audioSrc) {
107
+ const audioIcon = document.createElement("i");
108
+ audioIcon.className = "fa-solid fa-volume-high audio-toggle";
109
+ audioIcon.title = "Click to mute";
110
+ audioIcon.style.cursor = "pointer";
111
+ audioIcon.style.fontSize = "18px";
112
 
113
  const audio = new Audio(audioSrc);
114
+ audio.play();
115
+
116
+ audioIcon.addEventListener("click", () => {
117
+ if (audio.muted) {
118
+ audio.currentTime = 0;
119
+ audio.muted = false;
120
+ audioIcon.classList.remove("fa-volume-xmark");
121
+ audioIcon.classList.add("fa-volume-high");
122
  audioIcon.title = "Click to mute";
123
+ audio.play();
124
  } else {
125
+ audio.muted = true;
126
+ audioIcon.classList.remove("fa-volume-high");
127
+ audioIcon.classList.add("fa-volume-xmark");
128
  audioIcon.title = "Click to unmute";
129
  }
130
  });
131
 
132
+ iconContainer.appendChild(audioIcon);
 
 
133
  }
134
+
135
+ if (fileName) {
136
+ const downloadIcon = document.createElement("a");
137
+ downloadIcon.href = fileName;
138
+ downloadIcon.target = "_blank";
139
+ downloadIcon.title = "Download PDF";
140
+
141
+ const icon = document.createElement("i");
142
+ icon.className = "fa-solid fa-file-arrow-down";
143
+ icon.style.fontSize = "18px";
144
+ icon.style.cursor = "pointer";
145
+
146
+ downloadIcon.appendChild(icon);
147
+ iconContainer.appendChild(downloadIcon);
148
+ }
149
+
150
+ message.appendChild(iconContainer);
151
  }
152
 
153
  bubble.appendChild(label);
 
180
  body: formData
181
  });
182
 
183
+ if (!response.ok) {
184
+ let errorMessage = 'Request failed';
185
+ try {
186
+ const error = await response.json();
187
+ errorMessage = error.detail || error.error || errorMessage;
188
+ } catch (e) {
189
+ // response not JSON
190
+ }
191
+ throw new Error(errorMessage);
192
+ }
193
 
194
  const result = await response.json();
195
  thinkingBubble.remove();
196
 
197
  if (isSummarizeMode) {
198
+ createMessageBubble(
199
+ result.summary || "No summary generated.",
200
+ "Assistant",
201
+ result.audioUrl,
202
+ result.pdfUrl
203
+ );
 
 
 
 
 
 
 
 
 
 
 
204
  } else {
205
  createMessageBubble(
206
+ `<strong>Caption:</strong><br><br>${result.answer || result.caption}`,
 
207
  "Aidan",
208
  result.audio
209
  );
 
242
  0% { transform: rotate(0deg); }
243
  100% { transform: rotate(360deg); }
244
  }
 
 
 
 
 
 
 
 
 
 
 
 
245
  .audio-toggle {
246
  cursor: pointer;
247
  transition: all 0.2s;