Spaces:
Running
Running
Update static/appS.js
Browse files- 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
|
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 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
}
|
76 |
-
|
77 |
-
|
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 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
if (audioSrc) {
|
112 |
-
const
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
|
118 |
const audio = new Audio(audioSrc);
|
119 |
-
|
120 |
-
|
121 |
-
audioIcon.
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
audioIcon.classList.
|
127 |
audioIcon.title = "Click to mute";
|
|
|
128 |
} else {
|
129 |
-
audio.
|
130 |
-
audioIcon.classList.
|
|
|
131 |
audioIcon.title = "Click to unmute";
|
132 |
}
|
133 |
});
|
134 |
|
135 |
-
|
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 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
}
|
181 |
|
182 |
const result = await response.json();
|
183 |
thinkingBubble.remove();
|
184 |
|
185 |
if (isSummarizeMode) {
|
186 |
-
createMessageBubble(
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
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;
|