Docfile commited on
Commit
58fc92d
·
verified ·
1 Parent(s): 37c7d16

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +86 -162
templates/index.html CHANGED
@@ -11,94 +11,10 @@
11
  <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
12
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
13
  <style>
14
- @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
15
-
16
- body {
17
- font-family: 'Poppins', sans-serif;
18
- }
19
-
20
- .loader {
21
- width: 48px;
22
- height: 48px;
23
- border: 5px solid #FFF;
24
- border-bottom-color: #3B82F6;
25
- border-radius: 50%;
26
- display: inline-block;
27
- box-sizing: border-box;
28
- animation: rotation 1s linear infinite;
29
- }
30
-
31
- @keyframes rotation {
32
- 0% {
33
- transform: rotate(0deg);
34
- }
35
-
36
- 100% {
37
- transform: rotate(360deg);
38
- }
39
- }
40
-
41
- .math-content {
42
- font-size: 1.1em;
43
- line-height: 1.6;
44
- overflow-x: auto;
45
- }
46
-
47
- .math-content p {
48
- margin-bottom: 1rem;
49
- }
50
-
51
- .math-content .MathJax {
52
- overflow-x: auto;
53
- overflow-y: hidden;
54
- padding: 0.5rem 0;
55
- }
56
-
57
- @media (max-width: 640px) {
58
- .math-content .MathJax {
59
- font-size: 0.9em;
60
- }
61
- }
62
-
63
- .math-hidden {
64
- visibility: hidden;
65
- }
66
  </style>
67
  <script>
68
- // Configuration de marked
69
- marked.setOptions({
70
- breaks: true,
71
- gfm: true,
72
- headerIds: false
73
- });
74
-
75
- // Configuration de MathJax
76
- MathJax = {
77
- tex: {
78
- inlineMath: [['$', '$'], ['\\(', '\\)']],
79
- displayMath: [['$$', '$$'], ['\\[', '\\]']],
80
- processEscapes: true,
81
- macros: {
82
- R: "{\\mathbb{R}}",
83
- N: "{\\mathbb{N}}",
84
- Z: "{\\mathbb{Z}}",
85
- vecv: ["\\begin{pmatrix}#1\\\\#2\\\\#3\\end{pmatrix}", 3]
86
- }
87
- },
88
- svg: {
89
- fontCache: 'global'
90
- },
91
- options: {
92
- renderActions: {
93
- addMenu: [],
94
- checkLoading: [150, (doc) => {
95
- document.querySelectorAll('.math-content').forEach(el => {
96
- el.classList.remove('math-hidden');
97
- });
98
- }]
99
- }
100
- }
101
- };
102
  </script>
103
  </head>
104
 
@@ -136,9 +52,8 @@
136
  </div>
137
  <input id="image-input" type="file" name="image" class="hidden" accept="image/*" />
138
  </label>
139
- <button id="submit-button" type="button"
140
- class="mt-4 px-6 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition duration-300 disabled:bg-gray-400 disabled:cursor-not-allowed"
141
- disabled>
142
  Soumettre
143
  </button>
144
  </div>
@@ -157,12 +72,16 @@
157
 
158
  <!-- Result Section -->
159
  <div id="result-container" class="hidden mt-8">
160
- <div class="flex justify-between items-center mb-4">
161
- <h2 class="text-xl font-semibold text-gray-800">Résolution détaillée :</h2>
162
  <button id="copy-button"
163
- class="px-4 py-2 bg-gray-200 text-gray-800 rounded-lg hover:bg-gray-300 transition duration-300">
164
  <i class="fas fa-copy mr-2"></i>Copier
165
  </button>
 
 
 
 
166
  </div>
167
  <div id="result" class="bg-gray-50 rounded-lg p-6 prose max-w-none math-content math-hidden"></div>
168
  </div>
@@ -170,100 +89,105 @@
170
  </div>
171
 
172
  <script>
 
173
  const imageInput = document.getElementById('image-input');
174
  const submitButton = document.getElementById('submit-button');
 
 
 
 
175
  const copyButton = document.getElementById('copy-button');
176
- const resultDiv = document.getElementById('result');
 
177
 
178
- // Gérer l'état du bouton "Soumettre"
179
- imageInput.addEventListener('change', () => {
180
- submitButton.disabled = !imageInput.files.length;
181
- });
182
-
183
- // Fonction pour charger la dernière réponse depuis le localStorage
184
- function loadLastResponse() {
185
- const lastResponse = localStorage.getItem('lastResponse');
186
- if (lastResponse) {
187
- resultDiv.innerHTML = marked.parse(lastResponse);
188
- MathJax.typesetPromise([resultDiv]).then(() => {
189
- resultDiv.classList.remove('math-hidden');
190
- });
191
- document.getElementById('result-container').classList.remove('hidden');
192
- }
193
- }
194
-
195
- // Charger la dernière réponse au chargement de la page
196
- loadLastResponse();
197
-
198
- // Soumettre l'image et afficher la réponse
199
- submitButton.addEventListener('click', async () => {
200
- const file = imageInput.files[0];
201
  if (file) {
202
  // Show preview
203
- const preview = document.getElementById('image-preview');
204
  const reader = new FileReader();
205
  reader.onload = function (e) {
206
- preview.src = e.target.result;
207
- preview.classList.remove('hidden');
 
208
  };
209
  reader.readAsDataURL(file);
 
 
 
 
 
 
210
 
211
- // Show loading
212
- document.getElementById('loading').classList.remove('hidden');
213
- document.getElementById('result-container').classList.add('hidden');
214
- resultDiv.classList.add('math-hidden');
215
 
216
- try {
217
- const formData = new FormData();
218
- formData.append('image', file);
 
 
219
 
220
- const response = await fetch('/generate', {
221
- method: 'POST',
222
- body: formData
223
- });
224
 
225
- const data = await response.json();
 
 
 
 
226
 
227
- // Hide loading
228
- document.getElementById('loading').classList.add('hidden');
229
 
230
- // Show result
231
- document.getElementById('result-container').classList.remove('hidden');
232
- const formattedResult = marked.parse(data.result);
233
- resultDiv.innerHTML = formattedResult;
234
 
235
- // Sauvegarder dans le localStorage
236
- localStorage.setItem('lastResponse', data.result);
 
237
 
238
- // Rendre les maths avec MathJax
239
- MathJax.typesetPromise([resultDiv]).then(() => {
240
- resultDiv.classList.remove('math-hidden');
241
- }).catch((err) => {
 
 
242
  console.error('Erreur MathJax:', err);
243
- resultDiv.innerHTML = "Erreur lors du rendu des mathématiques.";
244
- resultDiv.classList.remove('math-hidden');
245
  });
246
 
247
- } catch (error) {
248
- console.error('Erreur:', error);
249
- document.getElementById('loading').classList.add('hidden');
250
- alert('Une erreur est survenue lors du traitement de l\'image.');
251
- }
252
  }
253
  });
254
 
255
- // Copier la réponse dans le presse-papiers
256
- copyButton.addEventListener('click', () => {
257
- const textToCopy = resultDiv.innerText;
258
- navigator.clipboard.writeText(textToCopy).then(() => {
259
- // Confirmation visuelle (optionnel)
260
- copyButton.innerHTML = '<i class="fas fa-check mr-2"></i>Copié !';
261
- setTimeout(() => {
262
- copyButton.innerHTML = '<i class="fas fa-copy mr-2"></i>Copier';
263
- }, 2000);
264
- }).catch(err => {
265
- console.error('Erreur lors de la copie:', err);
266
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
267
  });
268
  </script>
269
  </body>
 
11
  <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
12
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
13
  <style>
14
+ /* ... (votre CSS existant) ... */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  </style>
16
  <script>
17
+ // ... (votre configuration de marked et MathJax) ...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  </script>
19
  </head>
20
 
 
52
  </div>
53
  <input id="image-input" type="file" name="image" class="hidden" accept="image/*" />
54
  </label>
55
+ <button type="submit" id="submit-button"
56
+ class="mt-4 bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-lg hidden">
 
57
  Soumettre
58
  </button>
59
  </div>
 
72
 
73
  <!-- Result Section -->
74
  <div id="result-container" class="hidden mt-8">
75
+ <h2 class="text-xl font-semibold text-gray-800 mb-4">Résolution détaillée :</h2>
76
+ <div class="flex items-center mb-4">
77
  <button id="copy-button"
78
+ class="bg-gray-200 hover:bg-gray-300 text-gray-800 font-bold py-2 px-4 rounded-lg">
79
  <i class="fas fa-copy mr-2"></i>Copier
80
  </button>
81
+ <button id="save-button"
82
+ class="ml-4 bg-green-200 hover:bg-green-300 text-green-800 font-bold py-2 px-4 rounded-lg">
83
+ <i class="fas fa-save mr-2"></i>Sauvegarder
84
+ </button>
85
  </div>
86
  <div id="result" class="bg-gray-50 rounded-lg p-6 prose max-w-none math-content math-hidden"></div>
87
  </div>
 
89
  </div>
90
 
91
  <script>
92
+ const form = document.getElementById('upload-form');
93
  const imageInput = document.getElementById('image-input');
94
  const submitButton = document.getElementById('submit-button');
95
+ const imagePreview = document.getElementById('image-preview');
96
+ const loading = document.getElementById('loading');
97
+ const resultContainer = document.getElementById('result-container');
98
+ const result = document.getElementById('result');
99
  const copyButton = document.getElementById('copy-button');
100
+ const saveButton = document.getElementById('save-button');
101
+ let generatedResult = '';
102
 
103
+ imageInput.addEventListener('change', function (e) {
104
+ const file = e.target.files[0];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  if (file) {
106
  // Show preview
 
107
  const reader = new FileReader();
108
  reader.onload = function (e) {
109
+ imagePreview.src = e.target.result;
110
+ imagePreview.classList.remove('hidden');
111
+ submitButton.classList.remove('hidden');
112
  };
113
  reader.readAsDataURL(file);
114
+ } else {
115
+ imagePreview.src = "";
116
+ imagePreview.classList.add('hidden');
117
+ submitButton.classList.add('hidden');
118
+ }
119
+ });
120
 
121
+ form.addEventListener('submit', async function (e) {
122
+ e.preventDefault();
 
 
123
 
124
+ // Show loading
125
+ loading.classList.remove('hidden');
126
+ resultContainer.classList.add('hidden');
127
+ result.classList.add('math-hidden');
128
+ submitButton.classList.add('hidden');
129
 
130
+ const formData = new FormData(form);
 
 
 
131
 
132
+ try {
133
+ const response = await fetch('/generate', {
134
+ method: 'POST',
135
+ body: formData
136
+ });
137
 
138
+ const data = await response.json();
139
+ generatedResult = data.result;
140
 
141
+ // Hide loading
142
+ loading.classList.add('hidden');
 
 
143
 
144
+ // Show result
145
+ resultContainer.classList.remove('hidden');
146
+ result.innerHTML = marked.parse(generatedResult);
147
 
148
+ // Rendre les maths avec MathJax
149
+ MathJax.typesetPromise([result])
150
+ .then(() => {
151
+ result.classList.remove('math-hidden');
152
+ })
153
+ .catch((err) => {
154
  console.error('Erreur MathJax:', err);
155
+ result.innerHTML = "Erreur lors du rendu des mathématiques.";
156
+ result.classList.remove('math-hidden');
157
  });
158
 
159
+ } catch (error) {
160
+ console.error('Erreur:', error);
161
+ loading.classList.add('hidden');
162
+ alert('Une erreur est survenue lors du traitement de l\'image.');
 
163
  }
164
  });
165
 
166
+ // Copier la réponse
167
+ copyButton.addEventListener('click', function () {
168
+ navigator.clipboard.writeText(generatedResult)
169
+ .then(() => {
170
+ // Message de confirmation (optionnel)
171
+ alert('Réponse copiée dans le presse-papiers!');
172
+ })
173
+ .catch(err => {
174
+ console.error('Erreur lors de la copie:', err);
175
+ });
176
+ });
177
+
178
+ // Sauvegarder la réponse dans le localStorage
179
+ saveButton.addEventListener('click', function () {
180
+ const timestamp = new Date().toLocaleString();
181
+ const savedData = {
182
+ timestamp: timestamp,
183
+ image: imagePreview.src,
184
+ result: generatedResult
185
+ };
186
+
187
+ localStorage.setItem('savedResult-' + Date.now(), JSON.stringify(savedData));
188
+
189
+ // Message de confirmation (optionnel)
190
+ alert('Réponse sauvegardée!');
191
  });
192
  </script>
193
  </body>