Docfile commited on
Commit
72870fd
·
verified ·
1 Parent(s): f698087

Create m.html

Browse files
Files changed (1) hide show
  1. templates/m.html +417 -0
templates/m.html ADDED
@@ -0,0 +1,417 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 -->
8
+ <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
9
+
10
+ <!-- Bibliothèque html2pdf -->
11
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script>
12
+
13
+ <!-- Configuration MathJax -->
14
+ <script>
15
+ window.MathJax = {
16
+ tex: {
17
+ inlineMath: [['$', '$']],
18
+ displayMath: [['$$', '$$']],
19
+ processEscapes: true,
20
+ packages: {'[+]': ['autoload','ams']}
21
+ },
22
+ options: {
23
+ enableMenu: false,
24
+ messageStyle: 'none'
25
+ },
26
+ startup: {
27
+ pageReady: () => {
28
+ console.log('MathJax est complètement chargé.');
29
+ window.mathJaxReady = true;
30
+ }
31
+ }
32
+ };
33
+ </script>
34
+ <script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js" id="MathJax-script" async></script>
35
+ <script src="https://cdn.jsdelivr.net/npm/marked/lib/marked.umd.min.js"></script>
36
+
37
+ <style>
38
+ @import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;700&display=swap');
39
+
40
+ body {
41
+ font-family: 'Space Grotesk', sans-serif;
42
+ }
43
+
44
+ .uploadArea {
45
+ background: #f3f4f6;
46
+ border: 2px dashed #d1d5db;
47
+ transition: border-color 0.2s ease;
48
+ }
49
+ .uploadArea:hover {
50
+ border-color: #3b82f6;
51
+ }
52
+
53
+ .blue-button {
54
+ background: #3b82f6;
55
+ transition: background-color 0.2s ease;
56
+ }
57
+ .blue-button:hover {
58
+ background: #2563eb;
59
+ }
60
+
61
+ .download-button {
62
+ background: #10b981;
63
+ color: white;
64
+ transition: background-color 0.2s ease;
65
+ padding: 0.5rem 1rem;
66
+ border-radius: 0.5rem;
67
+ display: inline-flex;
68
+ align-items: center;
69
+ gap: 0.5rem;
70
+ font-weight: 500;
71
+ }
72
+ .download-button:hover {
73
+ background: #059669;
74
+ }
75
+
76
+ .loader {
77
+ width: 48px;
78
+ height: 48px;
79
+ border: 3px solid #3b82f6;
80
+ border-bottom-color: transparent;
81
+ border-radius: 50%;
82
+ display: inline-block;
83
+ animation: rotation 1s linear infinite;
84
+ }
85
+ @keyframes rotation {
86
+ 0% { transform: rotate(0deg); }
87
+ 100% { transform: rotate(360deg); }
88
+ }
89
+
90
+ .thought-box {
91
+ transition: max-height 0.3s ease-out;
92
+ max-height: 0;
93
+ overflow: hidden;
94
+ }
95
+ .thought-box.open {
96
+ max-height: 500px;
97
+ }
98
+
99
+ #thoughtsContent, #answerContent {
100
+ max-height: 500px;
101
+ overflow-y: auto;
102
+ scroll-behavior: smooth;
103
+ white-space: pre-wrap;
104
+ }
105
+
106
+ .preview-image {
107
+ max-width: 300px;
108
+ max-height: 300px;
109
+ object-fit: contain;
110
+ }
111
+
112
+ .timestamp {
113
+ color: #3b82f6;
114
+ font-size: 0.9em;
115
+ margin-left: 8px;
116
+ }
117
+
118
+ table {
119
+ border-collapse: collapse;
120
+ width: 100%;
121
+ margin-bottom: 1rem;
122
+ }
123
+ th, td {
124
+ border: 1px solid #d1d5db;
125
+ padding: 0.5rem;
126
+ text-align: left;
127
+ }
128
+ th {
129
+ background-color: #f3f4f6;
130
+ font-weight: 600;
131
+ }
132
+ .table-responsive {
133
+ overflow-x: auto;
134
+ }
135
+
136
+ @media print {
137
+ .no-print {
138
+ display: none;
139
+ }
140
+ }
141
+ </style>
142
+ </head>
143
+ <body class="p-4">
144
+ <div class="max-w-4xl mx-auto">
145
+ <header class="p-6 text-center mb-8">
146
+ <h1 class="text-4xl font-bold text-blue-600">Mariam M-0</h1>
147
+ <p class="text-gray-600">Solution Mathématique/Physique/Chimie Intelligente</p>
148
+ </header>
149
+
150
+ <main>
151
+ <form id="problemForm" class="space-y-6" novalidate>
152
+ <div class="uploadArea p-8 text-center relative" aria-label="Zone de dépôt d'image">
153
+ <input type="file" id="imageInput" accept="image/*" class="absolute inset-0 w-full h-full opacity-0 cursor-pointer" aria-label="Choisir une image">
154
+ <div class="space-y-3">
155
+ <div class="w-16 h-16 mx-auto border-2 border-blue-400 rounded-full flex items-center justify-center">
156
+ <svg class="w-8 h-8 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
157
+ <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" />
158
+ </svg>
159
+ </div>
160
+ <p class="text-gray-700 font-medium">Déposez votre image ici</p>
161
+ <p class="text-gray-500 text-sm">ou cliquez pour sélectionner</p>
162
+ </div>
163
+ </div>
164
+
165
+ <div id="imagePreview" class="hidden text-center">
166
+ <img id="previewImage" class="preview-image mx-auto" alt="Prévisualisation de l'image sélectionnée">
167
+ </div>
168
+
169
+ <button type="submit" class="blue-button w-full py-3 text-white font-medium rounded-lg">
170
+ Résoudre le problème
171
+ </button>
172
+ </form>
173
+
174
+ <div id="loader" class="hidden mt-8 text-center">
175
+ <span class="loader"></span>
176
+ <p class="mt-4 text-gray-600">Analyse en cours...</p>
177
+ </div>
178
+
179
+ <section id="solution" class="hidden mt-8 space-y-6">
180
+ <div class="border-t pt-4">
181
+ <button id="thoughtsToggle" type="button" class="w-full flex justify-between items-center p-2">
182
+ <span class="font-medium text-gray-700">Processus de Réflexion</span>
183
+ <span id="timestamp" class="timestamp"></span>
184
+ </button>
185
+ <div id="thoughtsBox" class="thought-box">
186
+ <div id="thoughtsContent" class="p-4 text-gray-600"></div>
187
+ </div>
188
+ </div>
189
+ <div class="border-t pt-6">
190
+ <div class="flex justify-between items-center mb-4">
191
+ <h3 class="text-xl font-bold text-gray-800">Solution</h3>
192
+ <button id="downloadPdf" class="download-button no-print">
193
+ <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
194
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4" />
195
+ </svg>
196
+ Télécharger PDF
197
+ </button>
198
+ </div>
199
+ <div id="answerContent" class="text-gray-700 table-responsive"></div>
200
+ </div>
201
+ </section>
202
+ </main>
203
+ </div>
204
+
205
+ <script>
206
+ document.addEventListener('DOMContentLoaded', () => {
207
+ const form = document.getElementById('problemForm');
208
+ const imageInput = document.getElementById('imageInput');
209
+ const loader = document.getElementById('loader');
210
+ const solutionSection = document.getElementById('solution');
211
+ const thoughtsContent = document.getElementById('thoughtsContent');
212
+ const answerContent = document.getElementById('answerContent');
213
+ const thoughtsToggle = document.getElementById('thoughtsToggle');
214
+ const thoughtsBox = document.getElementById('thoughtsBox');
215
+ const imagePreview = document.getElementById('imagePreview');
216
+ const previewImage = document.getElementById('previewImage');
217
+ const timestamp = document.getElementById('timestamp');
218
+
219
+ let startTime = null;
220
+ let timerInterval = null;
221
+ let thoughtsBuffer = '';
222
+ let answerBuffer = '';
223
+ let currentMode = null;
224
+ let updateTimeout = null;
225
+
226
+ const generatePDF = async () => {
227
+ const element = document.getElementById('answerContent');
228
+
229
+ const opt = {
230
+ margin: [10, 10],
231
+ filename: 'solution-mathematique.pdf',
232
+ image: { type: 'jpeg', quality: 0.98 },
233
+ html2canvas: {
234
+ scale: 2,
235
+ useCORS: true,
236
+ logging: false
237
+ },
238
+ jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }
239
+ };
240
+
241
+ if (window.MathJax) {
242
+ await MathJax.typesetPromise([element]);
243
+ }
244
+
245
+ try {
246
+ await html2pdf().set(opt).from(element).save();
247
+ } catch (error) {
248
+ console.error('Erreur lors de la génération du PDF:', error);
249
+ alert('Une erreur est survenue lors de la génération du PDF.');
250
+ }
251
+ };
252
+
253
+ document.getElementById('downloadPdf').addEventListener('click', generatePDF);
254
+
255
+ const updateTimestamp = () => {
256
+ if (startTime) {
257
+ const seconds = Math.floor((Date.now() - startTime) / 1000);
258
+ timestamp.textContent = `${seconds}s`;
259
+ }
260
+ };
261
+
262
+ const startTimer = () => {
263
+ startTime = Date.now();
264
+ timerInterval = setInterval(updateTimestamp, 1000);
265
+ updateTimestamp();
266
+ };
267
+
268
+ const stopTimer = () => {
269
+ clearInterval(timerInterval);
270
+ startTime = null;
271
+ timestamp.textContent = '';
272
+ };
273
+
274
+ const handleFileSelect = file => {
275
+ if (!file) return;
276
+ const reader = new FileReader();
277
+ reader.onload = e => {
278
+ previewImage.src = e.target.result;
279
+ imagePreview.classList.remove('hidden');
280
+ };
281
+ reader.readAsDataURL(file);
282
+ };
283
+
284
+ thoughtsToggle.addEventListener('click', () => {
285
+ thoughtsBox.classList.toggle('open');
286
+ });
287
+
288
+ imageInput.addEventListener('change', e => handleFileSelect(e.target.files[0]));
289
+
290
+ const dropZone = document.querySelector('.uploadArea');
291
+ dropZone.addEventListener('dragover', e => {
292
+ e.preventDefault();
293
+ dropZone.classList.add('border-blue-400');
294
+ });
295
+ dropZone.addEventListener('dragleave', e => {
296
+ e.preventDefault();
297
+ dropZone.classList.remove('border-blue-400');
298
+ });
299
+ dropZone.addEventListener('drop', e => {
300
+ e.preventDefault();
301
+ dropZone.classList.remove('border-blue-400');
302
+ handleFileSelect(e.dataTransfer.files[0]);
303
+ });
304
+
305
+ const typesetAnswerIfReady = async () => {
306
+ if (window.mathJaxReady) {
307
+ MathJax.startup.document.elements = [document.getElementById('answerContent')];
308
+ await MathJax.typesetPromise();
309
+ answerContent.scrollTop = answerContent.scrollHeight;
310
+ } else {
311
+ setTimeout(typesetAnswerIfReady, 200);
312
+ }
313
+ };
314
+
315
+ const updateDisplay = async () => {
316
+ thoughtsContent.innerHTML = marked.parse(thoughtsBuffer);
317
+ answerContent.innerHTML = marked.parse(answerBuffer);
318
+ await typesetAnswerIfReady();
319
+ updateTimeout = null;
320
+ };
321
+
322
+ const scheduleUpdate = () => {
323
+ if (updateTimeout) return;
324
+ updateTimeout = setTimeout(updateDisplay, 200);
325
+ };
326
+
327
+ marked.setOptions({
328
+ gfm: true,
329
+ breaks: true
330
+ });
331
+
332
+ form.addEventListener('submit', async e => {
333
+ e.preventDefault();
334
+ const file = imageInput.files[0];
335
+ if (!file) {
336
+ alert('Veuillez sélectionner une image.');
337
+ return;
338
+ }
339
+
340
+ startTimer();
341
+ loader.classList.remove('hidden');
342
+ solutionSection.classList.add('hidden');
343
+ thoughtsContent.innerHTML = '';
344
+ answerContent.innerHTML = '';
345
+ thoughtsBuffer = '';
346
+ answerBuffer = '';
347
+ currentMode = null;
348
+ thoughtsBox.classList.add('open');
349
+
350
+ const formData = new FormData();
351
+ formData.append('image', file);
352
+
353
+ try {
354
+ const response = await fetch('/solve', {
355
+ method: 'POST',
356
+ body: formData
357
+ });
358
+
359
+ const reader = response.body.getReader();
360
+ const decoder = new TextDecoder();
361
+ let buffer = '';
362
+
363
+ const processChunk = async chunk => {
364
+ buffer += decoder.decode(chunk, { stream: true });
365
+ const lines = buffer.split('\n\n');
366
+ buffer = lines.pop();
367
+
368
+ for (const line of lines) {
369
+ if (!line.startsWith('data:')) continue;
370
+ const data = JSON.parse(line.slice(5));
371
+
372
+ if (data.mode) {
373
+ currentMode = data.mode;
374
+ loader.classList.add('hidden');
375
+ solutionSection.classList.remove('hidden');
376
+ }
377
+ if (data.content) {
378
+ if (currentMode === 'thinking') {
379
+ thoughtsBuffer += data.content;
380
+ } else if (currentMode === 'answering') {
381
+ answerBuffer += data.content;
382
+ }
383
+ }
384
+ }
385
+ scheduleUpdate();
386
+ };
387
+
388
+ while (true) {
389
+ const { done, value } = await reader.read();
390
+ if (done) {
391
+ if (buffer) {
392
+ const data = JSON.parse(buffer.slice(5));
393
+ if (data.content) {
394
+ if (currentMode === 'thinking') {
395
+ thoughtsBuffer += data.content;
396
+ } else if (currentMode === 'answering') {
397
+ answerBuffer += data.content;
398
+ }
399
+ }
400
+ }
401
+ scheduleUpdate();
402
+ break;
403
+ }
404
+ await processChunk(value);
405
+ }
406
+ stopTimer();
407
+ } catch (error) {
408
+ console.error('Erreur:', error);
409
+ alert('Une erreur est survenue.');
410
+ loader.classList.add('hidden');
411
+ stopTimer();
412
+ }
413
+ });
414
+ });
415
+ </script>
416
+ </body>
417
+ </html>