Docfile commited on
Commit
f00ee44
·
verified ·
1 Parent(s): ecc651f

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +357 -327
templates/index.html CHANGED
@@ -1,341 +1,371 @@
1
  <!DOCTYPE html>
2
  <html lang="fr">
3
  <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Mariam M-0 | Solution Mathématique</title>
7
- <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
8
-
9
- <!-- Optimized MathJax Configuration -->
10
- <script>
11
- window.MathJax = {
12
- tex: {
13
- inlineMath: [['$', '$']],
14
- displayMath: [['$$', '$$']],
15
- processEscapes: true,
16
- packages: ['base', 'ams']
17
- },
18
- options: {
19
- enableMenu: false,
20
- messageStyle: 'none'
21
- },
22
- startup: {
23
- pageReady: () => {
24
- console.log('MathJax is fully loaded and ready.');
25
- window.mathJaxReady = true; // Signal that MathJax is ready
26
- // On pourrait appeler une fonction ici pour traiter du contenu initial si nécessaire
27
- }
28
- }
29
- };
30
- </script>
31
- <script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js" id="MathJax-script" async></script>
32
- <script src="https://cdn.jsdelivr.net/npm/marked/lib/marked.umd.min.js"></script>
33
-
34
- <style>
35
- @import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;700&display=swap');
36
-
37
- body {
38
- font-family: 'Space Grotesk', sans-serif;
39
- }
40
-
41
- .uploadArea {
42
- background: #f3f4f6;
43
- border: 2px dashed #d1d5db;
44
- transition: border-color 0.2s ease;
45
- }
46
-
47
- .uploadArea:hover {
48
- border-color: #3b82f6;
49
- }
50
-
51
- .blue-button {
52
- background: #3b82f6;
53
- transition: background-color 0.2s ease;
54
  }
55
-
56
- .blue-button:hover {
57
- background: #2563eb;
58
- }
59
-
60
- .loader {
61
- width: 48px;
62
- height: 48px;
63
- border: 3px solid #3b82f6;
64
- border-bottom-color: transparent;
65
- border-radius: 50%;
66
- display: inline-block;
67
- animation: rotation 1s linear infinite;
68
- }
69
-
70
- @keyframes rotation {
71
- 0% { transform: rotate(0deg); }
72
- 100% { transform: rotate(360deg); }
73
- }
74
-
75
- .thought-box {
76
- transition: max-height 0.3s ease-out;
77
- max-height: 0;
78
- overflow: hidden;
79
- }
80
-
81
- .thought-box.open {
82
- max-height: 500px;
83
- }
84
-
85
- #thoughtsContent, #answerContent {
86
- max-height: 500px;
87
- overflow-y: auto;
88
- scroll-behavior: smooth;
89
- white-space: pre-wrap; /* Gérer les espaces et les sauts de ligne */
90
- }
91
-
92
- .preview-image {
93
- max-width: 300px;
94
- max-height: 300px;
95
- object-fit: contain;
96
- }
97
-
98
- .timestamp {
99
- color: #3b82f6;
100
- font-size: 0.9em;
101
- margin-left: 8px;
102
- }
103
- </style>
104
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  </head>
106
  <body class="p-4">
107
- <div class="max-w-4xl mx-auto">
108
- <div class="p-6">
109
- <div class="text-center mb-8">
110
- <h1 class="text-4xl font-bold text-blue-600">Mariam M-0</h1>
111
- <p class="text-gray-600">Solution Mathématique/Physique/Chimie Intelligente</p>
 
 
 
 
 
 
 
 
 
 
 
 
112
  </div>
 
 
 
 
113
 
114
- <form id="problemForm" class="space-y-6">
115
- <div class="uploadArea p-8 text-center relative">
116
- <input type="file" id="imageInput" accept="image/*" class="absolute inset-0 w-full h-full opacity-0 cursor-pointer">
117
- <div class="space-y-3">
118
- <div class="w-16 h-16 mx-auto border-2 border-blue-400 rounded-full flex items-center justify-center">
119
- <svg class="w-8 h-8 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
120
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
121
- </svg>
122
- </div>
123
- <p class="text-gray-700 font-medium">Déposez votre image ici</p>
124
- <p class="text-gray-500 text-sm">ou cliquez pour sélectionner</p>
125
- </div>
126
- </div>
127
-
128
- <div id="imagePreview" class="hidden text-center">
129
- <img id="previewImage" class="preview-image mx-auto" alt="Prévisualisation">
130
- </div>
131
-
132
- <button type="submit" class="blue-button w-full py-3 text-white font-medium rounded-lg">
133
- Résoudre le problème
134
- </button>
135
- </form>
136
-
137
- <div id="loader" class="hidden mt-8 text-center">
138
- <span class="loader"></span>
139
- <p class="mt-4 text-gray-600">Analyse en cours...</p>
140
- </div>
141
 
142
- <div id="solution" class="hidden mt-8 space-y-6">
143
- <div class="border-t pt-4">
144
- <button id="thoughtsToggle" class="w-full flex justify-between items-center p-2">
145
- <span class="font-medium text-gray-700">Processus de Réflexion</span>
146
- <span id="timestamp" class="timestamp"></span>
147
- </button>
148
- <div id="thoughtsBox" class="thought-box">
149
- <div id="thoughtsContent" class="p-4 text-gray-600"></div>
150
- </div>
151
- </div>
152
-
153
- <div class="border-t pt-6">
154
- <h3 class="text-xl font-bold text-gray-800 mb-4">Solution</h3>
155
- <div id="answerContent" class="text-gray-700"></div>
156
- </div>
157
- </div>
 
 
 
 
 
158
  </div>
159
- </div>
160
-
161
- <script>
162
- document.addEventListener('DOMContentLoaded', () => {
163
- const form = document.getElementById('problemForm');
164
- const imageInput = document.getElementById('imageInput');
165
- const loader = document.getElementById('loader');
166
- const solution = document.getElementById('solution');
167
- const thoughtsContent = document.getElementById('thoughtsContent');
168
- const answerContent = document.getElementById('answerContent');
169
- const thoughtsToggle = document.getElementById('thoughtsToggle');
170
- const thoughtsBox = document.getElementById('thoughtsBox');
171
- const imagePreview = document.getElementById('imagePreview');
172
- const previewImage = document.getElementById('previewImage');
173
- const timestamp = document.getElementById('timestamp');
174
-
175
- let startTime = null;
176
- let timerInterval = null;
177
- let thoughtsBuffer = '';
178
- let answerBuffer = '';
179
-
180
- const updateTimestamp = () => {
181
- if (startTime) {
182
- timestamp.textContent = `${Math.floor((Date.now() - startTime) / 1000)}s`;
183
- }
184
- };
185
-
186
- const startTimer = () => {
187
- startTime = Date.now();
188
- timerInterval = setInterval(updateTimestamp, 1000);
189
- updateTimestamp();
190
- };
191
-
192
- const stopTimer = () => {
193
- clearInterval(timerInterval);
194
- startTime = null;
195
- timestamp.textContent = '';
196
- };
197
-
198
- const handleFileSelect = file => {
199
- if (!file) return;
200
- const reader = new FileReader();
201
- reader.onload = e => {
202
- previewImage.src = e.target.result;
203
- imagePreview.classList.remove('hidden');
204
- };
205
- reader.readAsDataURL(file);
206
- };
207
-
208
- thoughtsToggle.addEventListener('click', () => {
209
- thoughtsBox.classList.toggle('open');
210
- });
211
-
212
- imageInput.addEventListener('change', e => handleFileSelect(e.target.files[0]));
213
-
214
- const dropZone = document.querySelector('.uploadArea');
215
- dropZone.addEventListener('dragover', e => {
216
- e.preventDefault();
217
- dropZone.classList.add('border-blue-400');
218
- });
219
-
220
- dropZone.addEventListener('dragleave', e => {
221
- e.preventDefault();
222
- dropZone.classList.remove('border-blue-400');
223
- });
224
-
225
- dropZone.addEventListener('drop', e => {
226
- e.preventDefault();
227
- dropZone.classList.remove('border-blue-400');
228
- handleFileSelect(e.dataTransfer.files[0]);
229
- });
230
-
231
- const typesetAnswerIfReady = async () => {
232
- if (window.mathJaxReady) {
233
- MathJax.startup.document.elements = [document.getElementById('answerContent')];
234
- await MathJax.typesetPromise();
235
- answerContent.scrollTop = answerContent.scrollHeight;
236
- } else {
237
- setTimeout(typesetAnswerIfReady, 200);
238
- }
239
- };
240
-
241
- // Configuration de marked pour gérer les sauts de ligne
242
- marked.setOptions({
243
- breaks: true, // Interpréter les sauts de ligne simples comme des <br>
244
- });
245
-
246
- form.addEventListener('submit', async e => {
247
- e.preventDefault();
248
- const file = imageInput.files[0];
249
- if (!file) {
250
- alert('Veuillez sélectionner une image.');
251
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
  }
 
 
253
 
254
- startTimer();
255
- loader.classList.remove('hidden');
256
- solution.classList.add('hidden');
257
- thoughtsContent.innerHTML = '';
258
- answerContent.innerHTML = '';
259
- thoughtsBuffer = '';
260
- answerBuffer = '';
261
- thoughtsBox.classList.add('open');
262
-
263
- const formData = new FormData();
264
- formData.append('image', file);
265
-
266
- try {
267
- let currentMode = null;
268
- const response = await fetch('/solve', {
269
- method: 'POST',
270
- body: formData
271
- });
272
-
273
- const reader = response.body.getReader();
274
- const decoder = new TextDecoder();
275
- let buffer = '';
276
-
277
- const processChunk = async (chunk) => {
278
- buffer += decoder.decode(chunk, { stream: true });
279
- const lines = buffer.split('\n\n');
280
- buffer = lines.pop();
281
-
282
- for (const line of lines) {
283
- if (!line.startsWith('data:')) continue;
284
- const data = JSON.parse(line.slice(5));
285
-
286
- if (data.mode) {
287
- currentMode = data.mode;
288
- loader.classList.add('hidden');
289
- solution.classList.remove('hidden');
290
- }
291
-
292
- if (data.content) {
293
- if (currentMode === 'thinking') {
294
- thoughtsBuffer += data.content;
295
- } else if (currentMode === 'answering') {
296
- answerBuffer += data.content;
297
- }
298
- }
299
- }
300
-
301
- // Mettre à jour le contenu visible à chaque chunk reçu
302
- thoughtsContent.innerHTML = marked.parse(thoughtsBuffer);
303
- answerContent.innerHTML = marked.parse(answerBuffer);
304
- await typesetAnswerIfReady();
305
- };
306
-
307
- while (true) {
308
- const { done, value } = await reader.read();
309
- if (done) {
310
- // Traiter le contenu restant dans le buffer à la fin du stream
311
- if (buffer) {
312
- const data = JSON.parse(buffer.slice(5));
313
- if (data.content) {
314
- if (currentMode === 'thinking') {
315
- thoughtsBuffer += data.content;
316
- } else if (currentMode === 'answering') {
317
- answerBuffer += data.content;
318
- }
319
- }
320
- }
321
-
322
- // Mettre à jour le contenu visible une dernière fois à la fin du stream
323
- thoughtsContent.innerHTML = marked.parse(thoughtsBuffer);
324
- answerContent.innerHTML = marked.parse(answerBuffer);
325
- await typesetAnswerIfReady();
326
- break;
327
- }
328
- await processChunk(value);
329
- }
330
- stopTimer();
331
- } catch (error) {
332
- console.error('Erreur:', error);
333
- alert('Une erreur est survenue.');
334
- loader.classList.add('hidden');
335
- stopTimer();
336
  }
337
- });
338
- });
339
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
340
  </body>
341
- </html>
 
1
  <!DOCTYPE html>
2
  <html lang="fr">
3
  <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Mariam M-0 | Solution Mathématique</title>
7
+ <!-- Tailwind CSS (version 2.2.19 utilisée ici, à mettre à jour si besoin) -->
8
+ <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
9
+
10
+ <!-- Configuration optimisée de MathJax avec support étendu LaTeX -->
11
+ <script>
12
+ window.MathJax = {
13
+ tex: {
14
+ inlineMath: [['$', '$']],
15
+ displayMath: [['$$', '$$']],
16
+ processEscapes: true,
17
+ // Chargement automatique de commandes supplémentaires (ex. environnements de tableaux)
18
+ packages: {'[+]': ['autoload','ams']}
19
+ },
20
+ options: {
21
+ enableMenu: false,
22
+ messageStyle: 'none'
23
+ },
24
+ startup: {
25
+ pageReady: () => {
26
+ console.log('MathJax est complètement chargé.');
27
+ window.mathJaxReady = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  }
29
+ }
30
+ };
31
+ </script>
32
+ <script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js" id="MathJax-script" async></script>
33
+ <script src="https://cdn.jsdelivr.net/npm/marked/lib/marked.umd.min.js"></script>
34
+
35
+ <style>
36
+ @import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;700&display=swap');
37
+
38
+ body {
39
+ font-family: 'Space Grotesk', sans-serif;
40
+ }
41
+
42
+ .uploadArea {
43
+ background: #f3f4f6;
44
+ border: 2px dashed #d1d5db;
45
+ transition: border-color 0.2s ease;
46
+ }
47
+ .uploadArea:hover {
48
+ border-color: #3b82f6;
49
+ }
50
+
51
+ .blue-button {
52
+ background: #3b82f6;
53
+ transition: background-color 0.2s ease;
54
+ }
55
+ .blue-button:hover {
56
+ background: #2563eb;
57
+ }
58
+
59
+ .loader {
60
+ width: 48px;
61
+ height: 48px;
62
+ border: 3px solid #3b82f6;
63
+ border-bottom-color: transparent;
64
+ border-radius: 50%;
65
+ display: inline-block;
66
+ animation: rotation 1s linear infinite;
67
+ }
68
+ @keyframes rotation {
69
+ 0% { transform: rotate(0deg); }
70
+ 100% { transform: rotate(360deg); }
71
+ }
72
+
73
+ .thought-box {
74
+ transition: max-height 0.3s ease-out;
75
+ max-height: 0;
76
+ overflow: hidden;
77
+ }
78
+ .thought-box.open {
79
+ max-height: 500px;
80
+ }
81
+
82
+ #thoughtsContent, #answerContent {
83
+ max-height: 500px;
84
+ overflow-y: auto;
85
+ scroll-behavior: smooth;
86
+ white-space: pre-wrap;
87
+ }
88
+
89
+ .preview-image {
90
+ max-width: 300px;
91
+ max-height: 300px;
92
+ object-fit: contain;
93
+ }
94
+
95
+ .timestamp {
96
+ color: #3b82f6;
97
+ font-size: 0.9em;
98
+ margin-left: 8px;
99
+ }
100
+
101
+ /* Styles supplémentaires pour une meilleure présentation des tableaux */
102
+ table {
103
+ border-collapse: collapse;
104
+ width: 100%;
105
+ margin-bottom: 1rem;
106
+ }
107
+ th, td {
108
+ border: 1px solid #d1d5db;
109
+ padding: 0.5rem;
110
+ text-align: left;
111
+ }
112
+ th {
113
+ background-color: #f3f4f6;
114
+ font-weight: 600;
115
+ }
116
+ /* Pour un rendu responsive, ajouter éventuellement : */
117
+ .table-responsive {
118
+ overflow-x: auto;
119
+ }
120
+ </style>
121
  </head>
122
  <body class="p-4">
123
+ <div class="max-w-4xl mx-auto">
124
+ <header class="p-6 text-center mb-8">
125
+ <h1 class="text-4xl font-bold text-blue-600">Mariam M-0</h1>
126
+ <p class="text-gray-600">Solution Mathématique/Physique/Chimie Intelligente</p>
127
+ </header>
128
+
129
+ <main>
130
+ <form id="problemForm" class="space-y-6" novalidate>
131
+ <!-- Zone de dépôt et sélection d'image -->
132
+ <div class="uploadArea p-8 text-center relative" aria-label="Zone de dépôt d'image">
133
+ <input type="file" id="imageInput" accept="image/*" class="absolute inset-0 w-full h-full opacity-0 cursor-pointer" aria-label="Choisir une image">
134
+ <div class="space-y-3">
135
+ <div class="w-16 h-16 mx-auto border-2 border-blue-400 rounded-full flex items-center justify-center">
136
+ <svg class="w-8 h-8 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
137
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
138
+ d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
139
+ </svg>
140
  </div>
141
+ <p class="text-gray-700 font-medium">Déposez votre image ici</p>
142
+ <p class="text-gray-500 text-sm">ou cliquez pour sélectionner</p>
143
+ </div>
144
+ </div>
145
 
146
+ <!-- Aperçu de l'image -->
147
+ <div id="imagePreview" class="hidden text-center">
148
+ <img id="previewImage" class="preview-image mx-auto" alt="Prévisualisation de l'image sélectionnée">
149
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
+ <button type="submit" class="blue-button w-full py-3 text-white font-medium rounded-lg">
152
+ Résoudre le problème
153
+ </button>
154
+ </form>
155
+
156
+ <!-- Loader d'analyse -->
157
+ <div id="loader" class="hidden mt-8 text-center">
158
+ <span class="loader"></span>
159
+ <p class="mt-4 text-gray-600">Analyse en cours...</p>
160
+ </div>
161
+
162
+ <!-- Affichage de la solution -->
163
+ <section id="solution" class="hidden mt-8 space-y-6">
164
+ <div class="border-t pt-4">
165
+ <button id="thoughtsToggle" type="button" class="w-full flex justify-between items-center p-2">
166
+ <span class="font-medium text-gray-700">Processus de Réflexion</span>
167
+ <span id="timestamp" class="timestamp"></span>
168
+ </button>
169
+ <div id="thoughtsBox" class="thought-box">
170
+ <div id="thoughtsContent" class="p-4 text-gray-600"></div>
171
+ </div>
172
  </div>
173
+ <div class="border-t pt-6">
174
+ <h3 class="text-xl font-bold text-gray-800 mb-4">Solution</h3>
175
+ <!-- Enveloppement d'éventuels tableaux dans une div responsive -->
176
+ <div id="answerContent" class="text-gray-700 table-responsive"></div>
177
+ </div>
178
+ </section>
179
+ </main>
180
+ </div>
181
+
182
+ <script>
183
+ document.addEventListener('DOMContentLoaded', () => {
184
+ // Récupération des éléments DOM
185
+ const form = document.getElementById('problemForm');
186
+ const imageInput = document.getElementById('imageInput');
187
+ const loader = document.getElementById('loader');
188
+ const solutionSection = document.getElementById('solution');
189
+ const thoughtsContent = document.getElementById('thoughtsContent');
190
+ const answerContent = document.getElementById('answerContent');
191
+ const thoughtsToggle = document.getElementById('thoughtsToggle');
192
+ const thoughtsBox = document.getElementById('thoughtsBox');
193
+ const imagePreview = document.getElementById('imagePreview');
194
+ const previewImage = document.getElementById('previewImage');
195
+ const timestamp = document.getElementById('timestamp');
196
+
197
+ let startTime = null;
198
+ let timerInterval = null;
199
+ let thoughtsBuffer = '';
200
+ let answerBuffer = '';
201
+ let currentMode = null;
202
+
203
+ // Mise à jour de l'affichage du temps écoulé
204
+ const updateTimestamp = () => {
205
+ if (startTime) {
206
+ const seconds = Math.floor((Date.now() - startTime) / 1000);
207
+ timestamp.textContent = `${seconds}s`;
208
+ }
209
+ };
210
+
211
+ const startTimer = () => {
212
+ startTime = Date.now();
213
+ timerInterval = setInterval(updateTimestamp, 1000);
214
+ updateTimestamp();
215
+ };
216
+
217
+ const stopTimer = () => {
218
+ clearInterval(timerInterval);
219
+ startTime = null;
220
+ timestamp.textContent = '';
221
+ };
222
+
223
+ // Gestion de la sélection ou du dépôt de l'image
224
+ const handleFileSelect = file => {
225
+ if (!file) return;
226
+ const reader = new FileReader();
227
+ reader.onload = e => {
228
+ previewImage.src = e.target.result;
229
+ imagePreview.classList.remove('hidden');
230
+ };
231
+ reader.readAsDataURL(file);
232
+ };
233
+
234
+ // Toggle pour afficher/cacher le processus de réflexion
235
+ thoughtsToggle.addEventListener('click', () => {
236
+ thoughtsBox.classList.toggle('open');
237
+ });
238
+
239
+ imageInput.addEventListener('change', e => handleFileSelect(e.target.files[0]));
240
+
241
+ // Gestion des événements de glisser-déposer
242
+ const dropZone = document.querySelector('.uploadArea');
243
+ dropZone.addEventListener('dragover', e => {
244
+ e.preventDefault();
245
+ dropZone.classList.add('border-blue-400');
246
+ });
247
+ dropZone.addEventListener('dragleave', e => {
248
+ e.preventDefault();
249
+ dropZone.classList.remove('border-blue-400');
250
+ });
251
+ dropZone.addEventListener('drop', e => {
252
+ e.preventDefault();
253
+ dropZone.classList.remove('border-blue-400');
254
+ handleFileSelect(e.dataTransfer.files[0]);
255
+ });
256
+
257
+ // Fonction pour relancer le rendu MathJax dès que le contenu de la réponse est mis à jour
258
+ const typesetAnswerIfReady = async () => {
259
+ if (window.mathJaxReady) {
260
+ MathJax.startup.document.elements = [document.getElementById('answerContent')];
261
+ await MathJax.typesetPromise();
262
+ answerContent.scrollTop = answerContent.scrollHeight;
263
+ } else {
264
+ setTimeout(typesetAnswerIfReady, 200);
265
+ }
266
+ };
267
+
268
+ // Configuration de marked avec support du mode GFM (pour les tableaux) et interprétation des sauts de ligne
269
+ marked.setOptions({
270
+ gfm: true,
271
+ breaks: true
272
+ });
273
+
274
+ // Soumission du formulaire
275
+ form.addEventListener('submit', async e => {
276
+ e.preventDefault();
277
+ const file = imageInput.files[0];
278
+ if (!file) {
279
+ alert('Veuillez sélectionner une image.');
280
+ return;
281
+ }
282
+
283
+ // Initialisation de l'affichage et des variables
284
+ startTimer();
285
+ loader.classList.remove('hidden');
286
+ solutionSection.classList.add('hidden');
287
+ thoughtsContent.innerHTML = '';
288
+ answerContent.innerHTML = '';
289
+ thoughtsBuffer = '';
290
+ answerBuffer = '';
291
+ currentMode = null;
292
+ thoughtsBox.classList.add('open');
293
+
294
+ const formData = new FormData();
295
+ formData.append('image', file);
296
+
297
+ try {
298
+ // Envoi de la requête au serveur
299
+ const response = await fetch('/solve', {
300
+ method: 'POST',
301
+ body: formData
302
+ });
303
+
304
+ const reader = response.body.getReader();
305
+ const decoder = new TextDecoder();
306
+ let buffer = '';
307
+
308
+ // Traitement d'un chunk de données
309
+ const processChunk = async chunk => {
310
+ buffer += decoder.decode(chunk, { stream: true });
311
+ const lines = buffer.split('\n\n');
312
+ buffer = lines.pop(); // Conserver la dernière ligne incomplète
313
+
314
+ for (const line of lines) {
315
+ if (!line.startsWith('data:')) continue;
316
+ const data = JSON.parse(line.slice(5));
317
+
318
+ if (data.mode) {
319
+ currentMode = data.mode;
320
+ loader.classList.add('hidden');
321
+ solutionSection.classList.remove('hidden');
322
+ }
323
+ if (data.content) {
324
+ if (currentMode === 'thinking') {
325
+ thoughtsBuffer += data.content;
326
+ } else if (currentMode === 'answering') {
327
+ answerBuffer += data.content;
328
  }
329
+ }
330
+ }
331
 
332
+ // Mise à jour de l'affichage en temps réel
333
+ thoughtsContent.innerHTML = marked.parse(thoughtsBuffer);
334
+ answerContent.innerHTML = marked.parse(answerBuffer);
335
+ await typesetAnswerIfReady();
336
+ };
337
+
338
+ // Lecture du flux de réponse
339
+ while (true) {
340
+ const { done, value } = await reader.read();
341
+ if (done) {
342
+ // Traitement du contenu restant dans le buffer
343
+ if (buffer) {
344
+ const data = JSON.parse(buffer.slice(5));
345
+ if (data.content) {
346
+ if (currentMode === 'thinking') {
347
+ thoughtsBuffer += data.content;
348
+ } else if (currentMode === 'answering') {
349
+ answerBuffer += data.content;
350
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
351
  }
352
+ }
353
+ thoughtsContent.innerHTML = marked.parse(thoughtsBuffer);
354
+ answerContent.innerHTML = marked.parse(answerBuffer);
355
+ await typesetAnswerIfReady();
356
+ break;
357
+ }
358
+ await processChunk(value);
359
+ }
360
+ stopTimer();
361
+ } catch (error) {
362
+ console.error('Erreur:', error);
363
+ alert('Une erreur est survenue.');
364
+ loader.classList.add('hidden');
365
+ stopTimer();
366
+ }
367
+ });
368
+ });
369
+ </script>
370
  </body>
371
+ </html>