Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +38 -24
templates/index.html
CHANGED
|
@@ -464,7 +464,7 @@
|
|
| 464 |
}
|
| 465 |
}
|
| 466 |
|
| 467 |
-
|
| 468 |
event.preventDefault();
|
| 469 |
const file = imageInput.files[0];
|
| 470 |
if (!file) {
|
|
@@ -484,45 +484,59 @@
|
|
| 484 |
formData.append('image', file);
|
| 485 |
|
| 486 |
try {
|
|
|
|
| 487 |
const response = await fetch('/solve', {
|
| 488 |
method: 'POST',
|
| 489 |
body: formData
|
| 490 |
});
|
| 491 |
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
if (data.thinking) {
|
| 503 |
-
renderContent(data.thinking, thoughtsContent);
|
| 504 |
}
|
| 505 |
-
|
| 506 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 507 |
}
|
| 508 |
-
} catch (jsonError) {
|
| 509 |
-
// Si ce n'est pas du JSON, essayons de lire comme du texte
|
| 510 |
-
const textData = await response.text();
|
| 511 |
-
loader.classList.add('hidden');
|
| 512 |
-
solutionDiv.classList.remove('hidden');
|
| 513 |
-
renderContent(textData, answerContent);
|
| 514 |
}
|
| 515 |
|
| 516 |
-
stopTimer();
|
| 517 |
-
|
| 518 |
} catch (error) {
|
| 519 |
console.error('Erreur:', error);
|
| 520 |
alert('Une erreur est survenue lors du traitement de la requête.');
|
| 521 |
loader.classList.add('hidden');
|
| 522 |
stopTimer();
|
| 523 |
}
|
| 524 |
-
});
|
| 525 |
-
|
| 526 |
|
| 527 |
});
|
| 528 |
</script>
|
|
|
|
| 464 |
}
|
| 465 |
}
|
| 466 |
|
| 467 |
+
form.addEventListener('submit', async (event) => {
|
| 468 |
event.preventDefault();
|
| 469 |
const file = imageInput.files[0];
|
| 470 |
if (!file) {
|
|
|
|
| 484 |
formData.append('image', file);
|
| 485 |
|
| 486 |
try {
|
| 487 |
+
let currentMode = null;
|
| 488 |
const response = await fetch('/solve', {
|
| 489 |
method: 'POST',
|
| 490 |
body: formData
|
| 491 |
});
|
| 492 |
|
| 493 |
+
const reader = response.body.getReader();
|
| 494 |
+
const decoder = new TextDecoder();
|
| 495 |
+
let buffer = '';
|
| 496 |
|
| 497 |
+
while (true) {
|
| 498 |
+
const { done, value } = await reader.read();
|
| 499 |
+
if (done) {
|
| 500 |
+
stopTimer();
|
| 501 |
+
break;
|
|
|
|
|
|
|
|
|
|
| 502 |
}
|
| 503 |
+
|
| 504 |
+
buffer += decoder.decode(value, { stream: true });
|
| 505 |
+
let eolIndex;
|
| 506 |
+
|
| 507 |
+
while ((eolIndex = buffer.indexOf('\n\n')) >= 0) {
|
| 508 |
+
const line = buffer.slice(0, eolIndex).trim();
|
| 509 |
+
buffer = buffer.slice(eolIndex + 2);
|
| 510 |
+
|
| 511 |
+
if (line.startsWith('data:')) {
|
| 512 |
+
const data = JSON.parse(line.slice(5));
|
| 513 |
+
|
| 514 |
+
if (data.mode) {
|
| 515 |
+
currentMode = data.mode;
|
| 516 |
+
loader.classList.add('hidden');
|
| 517 |
+
solutionDiv.classList.remove('hidden');
|
| 518 |
+
}
|
| 519 |
+
|
| 520 |
+
if (data.content) {
|
| 521 |
+
const content = data.content;
|
| 522 |
+
if (currentMode === 'thinking') {
|
| 523 |
+
renderContent(content, thoughtsContent);
|
| 524 |
+
thoughtsContent.scrollTop = thoughtsContent.scrollHeight;
|
| 525 |
+
} else if (currentMode === 'answering') {
|
| 526 |
+
renderContent(content, answerContent);
|
| 527 |
+
}
|
| 528 |
+
}
|
| 529 |
+
}
|
| 530 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 531 |
}
|
| 532 |
|
|
|
|
|
|
|
| 533 |
} catch (error) {
|
| 534 |
console.error('Erreur:', error);
|
| 535 |
alert('Une erreur est survenue lors du traitement de la requête.');
|
| 536 |
loader.classList.add('hidden');
|
| 537 |
stopTimer();
|
| 538 |
}
|
| 539 |
+
});
|
|
|
|
| 540 |
|
| 541 |
});
|
| 542 |
</script>
|