Spaces:
Running
Running
Update templates/index.html
Browse files- templates/index.html +160 -153
templates/index.html
CHANGED
@@ -166,186 +166,193 @@
|
|
166 |
</div>
|
167 |
|
168 |
<script>
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
|
192 |
-
|
193 |
-
startTime = Date.now();
|
194 |
-
timerInterval = setInterval(updateTimestamp, 1000);
|
195 |
-
updateTimestamp();
|
196 |
-
}
|
197 |
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
timerInterval = null;
|
202 |
-
}
|
203 |
-
startTime = null;
|
204 |
-
timestamp.textContent = "";
|
205 |
-
}
|
206 |
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
const reader = new FileReader();
|
216 |
-
reader.onload = function(e) {
|
217 |
-
previewImage.src = e.target.result;
|
218 |
-
imagePreview.classList.remove('hidden');
|
219 |
-
}
|
220 |
-
reader.readAsDataURL(file);
|
221 |
-
} else {
|
222 |
-
previewImage.src = "";
|
223 |
-
imagePreview.classList.add('hidden');
|
224 |
-
}
|
225 |
-
});
|
226 |
|
227 |
-
|
|
|
|
|
228 |
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
}
|
237 |
|
238 |
-
|
239 |
-
dropZone.addEventListener(eventName, highlight, false);
|
240 |
-
});
|
241 |
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
|
246 |
-
|
247 |
-
|
|
|
|
|
|
|
|
|
|
|
248 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
|
250 |
-
|
251 |
-
dropZone.classList.remove('border-blue-400');
|
252 |
-
}
|
253 |
|
254 |
-
|
|
|
|
|
|
|
|
|
255 |
|
256 |
-
|
257 |
-
|
258 |
-
const files = dt.files;
|
259 |
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
imagePreview.classList.remove('hidden');
|
267 |
-
}
|
268 |
-
reader.readAsDataURL(file);
|
269 |
-
}
|
270 |
-
}
|
271 |
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
if (!file) {
|
276 |
-
alert('Veuillez sélectionner une image.');
|
277 |
-
return;
|
278 |
-
}
|
279 |
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
thoughtsBox.classList.add('open');
|
287 |
-
|
288 |
-
const formData = new FormData();
|
289 |
-
formData.append('image', file);
|
290 |
-
|
291 |
-
try {
|
292 |
-
let currentMode = null;
|
293 |
-
const response = await fetch('/solve', {
|
294 |
-
method: 'POST',
|
295 |
-
body: formData
|
296 |
-
});
|
297 |
-
|
298 |
-
const reader = response.body.getReader();
|
299 |
-
const decoder = new TextDecoder();
|
300 |
-
let buffer = '';
|
301 |
-
|
302 |
-
while (true) {
|
303 |
-
const { done, value } = await reader.read();
|
304 |
-
if (done) {
|
305 |
-
stopTimer();
|
306 |
-
break;
|
307 |
-
}
|
308 |
|
309 |
-
|
310 |
-
|
311 |
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
323 |
}
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
answerContent.innerHTML += content;
|
332 |
-
if (window.MathJax) {
|
333 |
-
MathJax.typesetPromise([answerContent]).catch((err) => console.log('MathJax error:', err));
|
334 |
-
}
|
335 |
-
}
|
336 |
}
|
337 |
}
|
338 |
}
|
339 |
}
|
340 |
-
|
341 |
-
} catch (error) {
|
342 |
-
console.error('Erreur:', error);
|
343 |
-
alert('Une erreur est survenue lors du traitement de la requête.');
|
344 |
-
loader.classList.add('hidden');
|
345 |
-
stopTimer();
|
346 |
}
|
347 |
-
}
|
348 |
-
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
349 |
</script>
|
350 |
</body>
|
351 |
</html>
|
|
|
166 |
</div>
|
167 |
|
168 |
<script>
|
169 |
+
|
170 |
+
document.addEventListener('DOMContentLoaded', () => {
|
171 |
+
const form = document.getElementById('problemForm');
|
172 |
+
const imageInput = document.getElementById('imageInput');
|
173 |
+
const loader = document.getElementById('loader');
|
174 |
+
const solutionDiv = document.getElementById('solution');
|
175 |
+
const thoughtsContent = document.getElementById('thoughtsContent');
|
176 |
+
const answerContent = document.getElementById('answerContent');
|
177 |
+
const thoughtsToggle = document.getElementById('thoughtsToggle');
|
178 |
+
const thoughtsBox = document.getElementById('thoughtsBox');
|
179 |
+
const imagePreview = document.getElementById('imagePreview');
|
180 |
+
const previewImage = document.getElementById('previewImage');
|
181 |
+
const timestamp = document.getElementById('timestamp');
|
182 |
+
|
183 |
+
let startTime = null;
|
184 |
+
let timerInterval = null;
|
185 |
+
|
186 |
+
function updateTimestamp() {
|
187 |
+
if (startTime) {
|
188 |
+
const elapsed = Math.floor((Date.now() - startTime) / 1000);
|
189 |
+
timestamp.textContent = elapsed + "s";
|
190 |
+
}
|
191 |
+
}
|
192 |
+
|
193 |
+
function startTimer() {
|
194 |
+
startTime = Date.now();
|
195 |
+
timerInterval = setInterval(updateTimestamp, 1000);
|
196 |
+
updateTimestamp();
|
197 |
+
}
|
198 |
+
|
199 |
+
function stopTimer() {
|
200 |
+
if (timerInterval) {
|
201 |
+
clearInterval(timerInterval);
|
202 |
+
timerInterval = null;
|
203 |
+
}
|
204 |
+
startTime = null;
|
205 |
+
timestamp.textContent = "";
|
206 |
+
}
|
207 |
+
|
208 |
+
thoughtsToggle.addEventListener('click', () => {
|
209 |
+
thoughtsBox.classList.toggle('open');
|
210 |
+
thoughtsToggle.querySelector('svg').classList.toggle('rotate-180');
|
211 |
+
});
|
212 |
+
|
213 |
+
imageInput.addEventListener('change', function(e) {
|
214 |
+
const file = this.files[0];
|
215 |
+
if (file) {
|
216 |
+
const reader = new FileReader();
|
217 |
+
reader.onload = function(e) {
|
218 |
+
previewImage.src = e.target.result;
|
219 |
+
imagePreview.classList.remove('hidden');
|
220 |
}
|
221 |
+
reader.readAsDataURL(file);
|
222 |
+
} else {
|
223 |
+
previewImage.src = "";
|
224 |
+
imagePreview.classList.add('hidden');
|
225 |
+
}
|
226 |
+
});
|
227 |
|
228 |
+
const dropZone = document.querySelector('.uploadArea');
|
|
|
|
|
|
|
|
|
229 |
|
230 |
+
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
|
231 |
+
dropZone.addEventListener(eventName, preventDefaults, false);
|
232 |
+
});
|
|
|
|
|
|
|
|
|
|
|
233 |
|
234 |
+
function preventDefaults(e) {
|
235 |
+
e.preventDefault();
|
236 |
+
e.stopPropagation();
|
237 |
+
}
|
238 |
|
239 |
+
['dragenter', 'dragover'].forEach(eventName => {
|
240 |
+
dropZone.addEventListener(eventName, highlight, false);
|
241 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
|
243 |
+
['dragleave', 'drop'].forEach(eventName => {
|
244 |
+
dropZone.addEventListener(eventName, unhighlight, false);
|
245 |
+
});
|
246 |
|
247 |
+
function highlight(e) {
|
248 |
+
dropZone.classList.add('border-blue-400');
|
249 |
+
}
|
250 |
|
251 |
+
function unhighlight(e) {
|
252 |
+
dropZone.classList.remove('border-blue-400');
|
253 |
+
}
|
|
|
254 |
|
255 |
+
dropZone.addEventListener('drop', handleDrop, false);
|
|
|
|
|
256 |
|
257 |
+
function handleDrop(e) {
|
258 |
+
const dt = e.dataTransfer;
|
259 |
+
const files = dt.files;
|
260 |
|
261 |
+
if (files.length) {
|
262 |
+
imageInput.files = files;
|
263 |
+
const file = files[0];
|
264 |
+
const reader = new FileReader();
|
265 |
+
reader.onload = function(e) {
|
266 |
+
previewImage.src = e.target.result;
|
267 |
+
imagePreview.classList.remove('hidden');
|
268 |
}
|
269 |
+
reader.readAsDataURL(file);
|
270 |
+
}
|
271 |
+
}
|
272 |
+
|
273 |
+
form.addEventListener('submit', async (event) => {
|
274 |
+
event.preventDefault();
|
275 |
+
const file = imageInput.files[0];
|
276 |
+
if (!file) {
|
277 |
+
alert('Veuillez sélectionner une image.');
|
278 |
+
return;
|
279 |
+
}
|
280 |
|
281 |
+
startTimer();
|
|
|
|
|
282 |
|
283 |
+
loader.classList.remove('hidden');
|
284 |
+
solutionDiv.classList.add('hidden');
|
285 |
+
thoughtsContent.innerHTML = '';
|
286 |
+
answerContent.innerHTML = '';
|
287 |
+
thoughtsBox.classList.add('open');
|
288 |
|
289 |
+
const formData = new FormData();
|
290 |
+
formData.append('image', file);
|
|
|
291 |
|
292 |
+
try {
|
293 |
+
let currentMode = null;
|
294 |
+
const response = await fetch('/solve', {
|
295 |
+
method: 'POST',
|
296 |
+
body: formData
|
297 |
+
});
|
|
|
|
|
|
|
|
|
|
|
298 |
|
299 |
+
const reader = response.body.getReader();
|
300 |
+
const decoder = new TextDecoder();
|
301 |
+
let buffer = '';
|
|
|
|
|
|
|
|
|
302 |
|
303 |
+
while (true) {
|
304 |
+
const { done, value } = await reader.read();
|
305 |
+
if (done) {
|
306 |
+
stopTimer();
|
307 |
+
break;
|
308 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
309 |
|
310 |
+
buffer += decoder.decode(value, { stream: true });
|
311 |
+
let eolIndex;
|
312 |
|
313 |
+
while ((eolIndex = buffer.indexOf('\n\n')) >= 0) {
|
314 |
+
const line = buffer.slice(0, eolIndex).trim();
|
315 |
+
buffer = buffer.slice(eolIndex + 2);
|
316 |
|
317 |
+
if (line.startsWith('data:')) {
|
318 |
+
const data = JSON.parse(line.slice(5));
|
319 |
+
|
320 |
+
if (data.mode) {
|
321 |
+
currentMode = data.mode;
|
322 |
+
loader.classList.add('hidden');
|
323 |
+
solutionDiv.classList.remove('hidden');
|
324 |
+
}
|
325 |
+
|
326 |
+
if (data.content) {
|
327 |
+
const content = data.content;
|
328 |
+
if (currentMode === 'thinking') {
|
329 |
+
thoughtsContent.innerHTML += `<p>${content}</p>`;
|
330 |
+
if (window.MathJax) {
|
331 |
+
MathJax.typesetPromise([thoughtsContent]).catch((err) =>
|
332 |
+
console.log('MathJax error:', err)
|
333 |
+
);
|
334 |
}
|
335 |
+
thoughtsContent.scrollTop = thoughtsContent.scrollHeight;
|
336 |
+
} else if (currentMode === 'answering') {
|
337 |
+
answerContent.innerHTML += content;
|
338 |
+
if (window.MathJax) {
|
339 |
+
MathJax.typesetPromise([answerContent]).catch((err) =>
|
340 |
+
console.log('MathJax error:', err)
|
341 |
+
);
|
|
|
|
|
|
|
|
|
|
|
342 |
}
|
343 |
}
|
344 |
}
|
345 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
}
|
347 |
+
}
|
348 |
+
} catch (error) {
|
349 |
+
console.error('Erreur:', error);
|
350 |
+
alert('Une erreur est survenue lors du traitement de la requête.');
|
351 |
+
loader.classList.add('hidden');
|
352 |
+
stopTimer();
|
353 |
+
}
|
354 |
+
});
|
355 |
+
});
|
356 |
</script>
|
357 |
</body>
|
358 |
</html>
|