Docfile commited on
Commit
3258c39
·
verified ·
1 Parent(s): 8566348

Update templates/maj.html

Browse files
Files changed (1) hide show
  1. templates/maj.html +197 -28
templates/maj.html CHANGED
@@ -5,6 +5,7 @@
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Math Solver - Version Gratuite</title>
7
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" rel="stylesheet">
 
8
  <style>
9
  :root {
10
  --primary-color: #4a6fa5;
@@ -13,6 +14,8 @@
13
  --background-color: #f8f9fa;
14
  --text-color: #333;
15
  --box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
 
 
16
  }
17
 
18
  body {
@@ -116,6 +119,110 @@
116
  font-size: 0.9rem;
117
  }
118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  @media (max-width: 768px) {
120
  .container {
121
  padding: 15px;
@@ -170,10 +277,11 @@
170
 
171
  <div id="solutionOutput" style="margin-top: 30px; text-align: left; display: none;">
172
  <h3>Solution :</h3>
173
- <div id="loadingIndicator" style="display: none; text-align: center;">
174
- <p><i class="fas fa-spinner fa-spin"></i> Analyse et résolution en cours...</p>
 
175
  </div>
176
- <div id="solution" style="background: #f9f9f9; padding: 20px; border-radius: 8px; white-space: pre-wrap;"></div>
177
  </div>
178
 
179
  <div class="upgrade-section">
@@ -188,6 +296,8 @@
188
  </footer>
189
  </div>
190
 
 
 
191
  <script>
192
  document.getElementById('imageInput').addEventListener('change', function(event) {
193
  const file = event.target.files[0];
@@ -210,7 +320,7 @@
210
  const solution = document.getElementById('solution');
211
 
212
  solutionOutput.style.display = 'block';
213
- loadingIndicator.style.display = 'block';
214
  solution.innerHTML = '';
215
 
216
  fetch('/solved', {
@@ -220,15 +330,31 @@
220
  .then(response => {
221
  const reader = response.body.getReader();
222
  const decoder = new TextDecoder();
 
223
 
224
  function processStream({ done, value }) {
225
  if (done) {
226
  loadingIndicator.style.display = 'none';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  return;
228
  }
229
 
230
- const chunk = decoder.decode(value, { stream: true });
231
- const lines = chunk.split('\n\n');
 
232
 
233
  for (const line of lines) {
234
  if (line.startsWith('data: ')) {
@@ -236,53 +362,96 @@
236
  const data = JSON.parse(line.substr(6));
237
 
238
  if (data.mode === 'thinking') {
239
- loadingIndicator.innerHTML = '<p><i class="fas fa-brain"></i> Je réfléchis au problème...</p>';
 
240
  } else if (data.mode === 'answering') {
241
- loadingIndicator.innerHTML = '<p><i class="fas fa-pencil-alt"></i> Rédaction de la solution...</p>';
 
242
  } else if (data.mode === 'executing_code') {
243
- loadingIndicator.innerHTML = '<p><i class="fas fa-code"></i> Exécution de code pour la résolution...</p>';
 
 
 
 
244
  }
245
 
246
  if (data.content) {
247
- solution.innerHTML += data.content;
248
- MathJax.typeset([solution]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
  }
250
 
251
  if (data.error) {
252
- solution.innerHTML += `<div style="color: red;">Erreur: ${data.error}</div>`;
253
  loadingIndicator.style.display = 'none';
254
  }
255
  } catch (e) {
256
- console.error('Error parsing JSON:', e);
257
  }
258
  }
259
  }
260
 
 
 
 
261
  return reader.read().then(processStream);
262
  }
263
 
264
  return reader.read().then(processStream);
265
  })
266
  .catch(error => {
267
- solution.innerHTML += `<div style="color: red;">Erreur de connexion: ${error}</div>`;
268
  loadingIndicator.style.display = 'none';
269
  });
270
  });
271
  </script>
272
 
273
- <!-- MathJax pour le rendu LaTeX -->
274
- <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.0/es5/tex-mml-chtml.js"></script>
275
- <script>
276
- window.MathJax = {
277
- tex: {
278
- inlineMath: [['$', '$'], ['\\(', '\\)']],
279
- displayMath: [['$$', '$$'], ['\\[', '\\]']],
280
- processEscapes: true
281
- },
282
- options: {
283
- skipHtmlTags: ['script', 'noscript', 'style', 'textarea', 'pre']
284
- }
285
- };
286
- </script>
287
  </body>
288
  </html>
 
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Math Solver - Version Gratuite</title>
7
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" rel="stylesheet">
8
+ <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/atom-one-dark.min.css" rel="stylesheet">
9
  <style>
10
  :root {
11
  --primary-color: #4a6fa5;
 
14
  --background-color: #f8f9fa;
15
  --text-color: #333;
16
  --box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
17
+ --code-bg: #2c323c;
18
+ --output-bg: #f1f8f9;
19
  }
20
 
21
  body {
 
119
  font-size: 0.9rem;
120
  }
121
 
122
+ #solution {
123
+ background: #fff;
124
+ padding: 20px;
125
+ border-radius: 8px;
126
+ text-align: left;
127
+ line-height: 1.8;
128
+ font-size: 16px;
129
+ }
130
+
131
+ .code-section {
132
+ margin: 20px 0;
133
+ border-radius: 8px;
134
+ overflow: hidden;
135
+ box-shadow: 0 2px 5px rgba(0,0,0,0.1);
136
+ }
137
+
138
+ .code-header {
139
+ background-color: #343a40;
140
+ color: white;
141
+ padding: 8px 15px;
142
+ font-size: 14px;
143
+ font-family: 'Courier New', monospace;
144
+ display: flex;
145
+ justify-content: space-between;
146
+ align-items: center;
147
+ }
148
+
149
+ .code-content {
150
+ margin: 0;
151
+ padding: 15px;
152
+ background-color: var(--code-bg);
153
+ color: #e6e6e6;
154
+ overflow-x: auto;
155
+ font-family: 'Courier New', monospace;
156
+ font-size: 14px;
157
+ line-height: 1.5;
158
+ }
159
+
160
+ .output-section {
161
+ background-color: var(--output-bg);
162
+ padding: 15px;
163
+ border-radius: 0 0 8px 8px;
164
+ border-top: 1px solid #ddd;
165
+ color: #333;
166
+ font-family: 'Courier New', monospace;
167
+ font-size: 14px;
168
+ white-space: pre-wrap;
169
+ overflow-x: auto;
170
+ }
171
+
172
+ .step-section {
173
+ margin: 25px 0;
174
+ padding: 15px;
175
+ background-color: #f9f9f9;
176
+ border-left: 4px solid var(--primary-color);
177
+ border-radius: 0 8px 8px 0;
178
+ }
179
+
180
+ .math-display {
181
+ overflow-x: auto;
182
+ padding: 10px 0;
183
+ text-align: center;
184
+ }
185
+
186
+ .thinking-indicator, .executing-indicator, .answering-indicator {
187
+ display: flex;
188
+ align-items: center;
189
+ padding: 10px;
190
+ margin: 10px 0;
191
+ border-radius: 8px;
192
+ font-size: 0.9rem;
193
+ }
194
+
195
+ .thinking-indicator {
196
+ background-color: #e3f2fd;
197
+ color: #1565c0;
198
+ }
199
+
200
+ .executing-indicator {
201
+ background-color: #ede7f6;
202
+ color: #5e35b1;
203
+ }
204
+
205
+ .answering-indicator {
206
+ background-color: #e8f5e9;
207
+ color: #2e7d32;
208
+ }
209
+
210
+ .indicator-icon {
211
+ margin-right: 10px;
212
+ animation: pulse 1.5s infinite ease-in-out;
213
+ }
214
+
215
+ @keyframes pulse {
216
+ 0% { opacity: 0.6; }
217
+ 50% { opacity: 1; }
218
+ 100% { opacity: 0.6; }
219
+ }
220
+
221
+ .katex-display {
222
+ overflow-x: auto;
223
+ padding: 8px 0;
224
+ }
225
+
226
  @media (max-width: 768px) {
227
  .container {
228
  padding: 15px;
 
277
 
278
  <div id="solutionOutput" style="margin-top: 30px; text-align: left; display: none;">
279
  <h3>Solution :</h3>
280
+ <div id="loadingIndicator" class="thinking-indicator" style="display: none;">
281
+ <i class="fas fa-brain indicator-icon"></i>
282
+ <span>Je réfléchis au problème...</span>
283
  </div>
284
+ <div id="solution" style="background: #fff; padding: 20px; border-radius: 8px;"></div>
285
  </div>
286
 
287
  <div class="upgrade-section">
 
296
  </footer>
297
  </div>
298
 
299
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
300
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/languages/python.min.js"></script>
301
  <script>
302
  document.getElementById('imageInput').addEventListener('change', function(event) {
303
  const file = event.target.files[0];
 
320
  const solution = document.getElementById('solution');
321
 
322
  solutionOutput.style.display = 'block';
323
+ loadingIndicator.style.display = 'flex';
324
  solution.innerHTML = '';
325
 
326
  fetch('/solved', {
 
330
  .then(response => {
331
  const reader = response.body.getReader();
332
  const decoder = new TextDecoder();
333
+ let buffer = '';
334
 
335
  function processStream({ done, value }) {
336
  if (done) {
337
  loadingIndicator.style.display = 'none';
338
+ // Render any remaining LaTeX once stream is complete
339
+ try {
340
+ renderMathInElement(solution, {
341
+ delimiters: [
342
+ {left: '$$', right: '$$', display: true},
343
+ {left: '$', right: '$', display: false},
344
+ {left: '\\(', right: '\\)', display: false},
345
+ {left: '\\[', right: '\\]', display: true}
346
+ ],
347
+ throwOnError: false
348
+ });
349
+ } catch (e) {
350
+ console.error('Error rendering LaTeX:', e);
351
+ }
352
  return;
353
  }
354
 
355
+ buffer += decoder.decode(value, { stream: true });
356
+ const lines = buffer.split('\n\n');
357
+ buffer = lines.pop(); // Keep the incomplete chunk for next time
358
 
359
  for (const line of lines) {
360
  if (line.startsWith('data: ')) {
 
362
  const data = JSON.parse(line.substr(6));
363
 
364
  if (data.mode === 'thinking') {
365
+ loadingIndicator.className = 'thinking-indicator';
366
+ loadingIndicator.innerHTML = '<i class="fas fa-brain indicator-icon"></i><span>Je réfléchis au problème...</span>';
367
  } else if (data.mode === 'answering') {
368
+ loadingIndicator.className = 'answering-indicator';
369
+ loadingIndicator.innerHTML = '<i class="fas fa-pencil-alt indicator-icon"></i><span>Rédaction de la solution...</span>';
370
  } else if (data.mode === 'executing_code') {
371
+ loadingIndicator.className = 'executing-indicator';
372
+ loadingIndicator.innerHTML = '<i class="fas fa-code indicator-icon"></i><span>Exécution de code pour la résolution...</span>';
373
+ } else if (data.mode === 'code_result') {
374
+ loadingIndicator.className = 'executing-indicator';
375
+ loadingIndicator.innerHTML = '<i class="fas fa-terminal indicator-icon"></i><span>Traitement des résultats...</span>';
376
  }
377
 
378
  if (data.content) {
379
+ const content = data.content;
380
+
381
+ // Detect if this is code or output and format appropriately
382
+ if (content.includes('```python')) {
383
+ // This is code
384
+ const code = content.replace(/```python\n([\s\S]*?)\n```/g, function(match, p1) {
385
+ return `<div class="code-section">
386
+ <div class="code-header">
387
+ <span>Code Python</span>
388
+ </div>
389
+ <pre><code class="language-python">${p1}</code></pre>
390
+ </div>`;
391
+ });
392
+ solution.innerHTML += code;
393
+
394
+ // Apply syntax highlighting
395
+ document.querySelectorAll('pre code').forEach((block) => {
396
+ hljs.highlightElement(block);
397
+ });
398
+ }
399
+ else if (content.includes('Résultat d\'exécution:')) {
400
+ // This is code output
401
+ const output = content.replace(/Résultat d'exécution:\n```\n([\s\S]*?)\n```/g, function(match, p1) {
402
+ return `<div class="output-section">${p1}</div>`;
403
+ });
404
+ solution.innerHTML += output;
405
+ }
406
+ else {
407
+ // Regular text, might contain LaTeX
408
+ solution.innerHTML += `<div class="step-section">${content}</div>`;
409
+
410
+ // Render LaTeX incrementally
411
+ try {
412
+ renderMathInElement(solution, {
413
+ delimiters: [
414
+ {left: '$$', right: '$$', display: true},
415
+ {left: '$', right: '$', display: false},
416
+ {left: '\\(', right: '\\)', display: false},
417
+ {left: '\\[', right: '\\]', display: true}
418
+ ],
419
+ throwOnError: false
420
+ });
421
+ } catch (e) {
422
+ console.error('Error rendering LaTeX:', e);
423
+ }
424
+ }
425
  }
426
 
427
  if (data.error) {
428
+ solution.innerHTML += `<div style="color: red; margin: 15px 0; padding: 10px; background: #ffeeee; border-radius: 5px;">Erreur: ${data.error}</div>`;
429
  loadingIndicator.style.display = 'none';
430
  }
431
  } catch (e) {
432
+ console.error('Error parsing JSON:', e, line);
433
  }
434
  }
435
  }
436
 
437
+ // Scroll to bottom automatically
438
+ window.scrollTo(0, document.body.scrollHeight);
439
+
440
  return reader.read().then(processStream);
441
  }
442
 
443
  return reader.read().then(processStream);
444
  })
445
  .catch(error => {
446
+ solution.innerHTML += `<div style="color: red; margin: 15px 0; padding: 10px; background: #ffeeee; border-radius: 5px;">Erreur de connexion: ${error}</div>`;
447
  loadingIndicator.style.display = 'none';
448
  });
449
  });
450
  </script>
451
 
452
+ <!-- KaTeX pour le rendu LaTeX (plus rapide et plus léger que MathJax) -->
453
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.8/katex.min.css">
454
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.8/katex.min.js"></script>
455
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.8/contrib/auto-render.min.js"></script>
 
 
 
 
 
 
 
 
 
 
456
  </body>
457
  </html>