Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +32 -102
templates/index.html
CHANGED
@@ -136,10 +136,6 @@
|
|
136 |
</div>
|
137 |
<input id="image-input" type="file" name="image" class="hidden" accept="image/*" />
|
138 |
</label>
|
139 |
-
<button type="submit" id="submit-button"
|
140 |
-
class="mt-4 bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-lg hidden">
|
141 |
-
Soumettre
|
142 |
-
</button>
|
143 |
</div>
|
144 |
</form>
|
145 |
|
@@ -157,130 +153,64 @@
|
|
157 |
<!-- Result Section -->
|
158 |
<div id="result-container" class="hidden mt-8">
|
159 |
<h2 class="text-xl font-semibold text-gray-800 mb-4">Résolution détaillée :</h2>
|
160 |
-
<div class="flex items-center mb-4">
|
161 |
-
<button id="copy-button"
|
162 |
-
class="bg-gray-200 hover:bg-gray-300 text-gray-800 font-bold py-2 px-4 rounded-lg">
|
163 |
-
<i class="fas fa-copy mr-2"></i>Copier
|
164 |
-
</button>
|
165 |
-
<button id="save-button"
|
166 |
-
class="ml-4 bg-green-200 hover:bg-green-300 text-green-800 font-bold py-2 px-4 rounded-lg">
|
167 |
-
<i class="fas fa-save mr-2"></i>Sauvegarder
|
168 |
-
</button>
|
169 |
-
</div>
|
170 |
<div id="result" class="bg-gray-50 rounded-lg p-6 prose max-w-none math-content math-hidden"></div>
|
171 |
</div>
|
172 |
</div>
|
173 |
</div>
|
174 |
|
175 |
<script>
|
176 |
-
|
177 |
-
const imageInput = document.getElementById('image-input');
|
178 |
-
const submitButton = document.getElementById('submit-button');
|
179 |
-
const imagePreview = document.getElementById('image-preview');
|
180 |
-
const loading = document.getElementById('loading');
|
181 |
-
const resultContainer = document.getElementById('result-container');
|
182 |
-
const result = document.getElementById('result');
|
183 |
-
const copyButton = document.getElementById('copy-button');
|
184 |
-
const saveButton = document.getElementById('save-button');
|
185 |
-
let generatedResult = '';
|
186 |
-
|
187 |
-
imageInput.addEventListener('change', function (e) {
|
188 |
const file = e.target.files[0];
|
189 |
if (file) {
|
190 |
// Show preview
|
|
|
191 |
const reader = new FileReader();
|
192 |
reader.onload = function (e) {
|
193 |
-
|
194 |
-
|
195 |
-
submitButton.classList.remove('hidden');
|
196 |
};
|
197 |
reader.readAsDataURL(file);
|
198 |
-
} else {
|
199 |
-
imagePreview.src = "";
|
200 |
-
imagePreview.classList.add('hidden');
|
201 |
-
submitButton.classList.add('hidden');
|
202 |
-
}
|
203 |
-
});
|
204 |
-
|
205 |
-
form.addEventListener('submit', async function (e) {
|
206 |
-
e.preventDefault();
|
207 |
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
submitButton.classList.add('hidden');
|
213 |
|
214 |
-
|
|
|
|
|
215 |
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
});
|
221 |
|
222 |
-
|
223 |
-
generatedResult = data.result;
|
224 |
|
225 |
-
|
226 |
-
|
227 |
|
228 |
-
|
229 |
-
|
230 |
-
|
|
|
231 |
|
232 |
-
|
233 |
-
|
234 |
-
MathJax.typesetPromise([result])
|
235 |
.then(() => {
|
236 |
-
result.classList.remove('math-hidden');
|
237 |
})
|
238 |
.catch((err) => {
|
239 |
console.error('Erreur MathJax:', err);
|
240 |
-
result.innerHTML = "Erreur lors du rendu des mathématiques.";
|
241 |
-
result.classList.remove('math-hidden');
|
242 |
});
|
243 |
-
}, 0);
|
244 |
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
});
|
251 |
-
|
252 |
-
// Copier la réponse
|
253 |
-
copyButton.addEventListener('click', function () {
|
254 |
-
navigator.clipboard.writeText(generatedResult)
|
255 |
-
.then(() => {
|
256 |
-
// Message de confirmation (optionnel)
|
257 |
-
alert('Réponse copiée dans le presse-papiers!');
|
258 |
-
})
|
259 |
-
.catch(err => {
|
260 |
-
console.error('Erreur lors de la copie:', err);
|
261 |
-
});
|
262 |
-
});
|
263 |
-
|
264 |
-
// Sauvegarder la réponse dans le localStorage
|
265 |
-
saveButton.addEventListener('click', function () {
|
266 |
-
const timestamp = new Date().toLocaleString();
|
267 |
-
const file = imageInput.files[0];
|
268 |
-
|
269 |
-
if (file) {
|
270 |
-
const reader = new FileReader();
|
271 |
-
reader.onload = function (e) {
|
272 |
-
const savedData = {
|
273 |
-
timestamp: timestamp,
|
274 |
-
image: e.target.result, // On sauvegarde la data URL de l'image
|
275 |
-
result: generatedResult
|
276 |
-
};
|
277 |
-
|
278 |
-
localStorage.setItem('savedResult-' + Date.now(), JSON.stringify(savedData));
|
279 |
-
alert('Réponse sauvegardée!');
|
280 |
-
};
|
281 |
-
reader.readAsDataURL(file); // On lit l'image comme une data URL
|
282 |
-
} else {
|
283 |
-
alert('Aucune image sélectionnée.');
|
284 |
}
|
285 |
});
|
286 |
</script>
|
|
|
136 |
</div>
|
137 |
<input id="image-input" type="file" name="image" class="hidden" accept="image/*" />
|
138 |
</label>
|
|
|
|
|
|
|
|
|
139 |
</div>
|
140 |
</form>
|
141 |
|
|
|
153 |
<!-- Result Section -->
|
154 |
<div id="result-container" class="hidden mt-8">
|
155 |
<h2 class="text-xl font-semibold text-gray-800 mb-4">Résolution détaillée :</h2>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
<div id="result" class="bg-gray-50 rounded-lg p-6 prose max-w-none math-content math-hidden"></div>
|
157 |
</div>
|
158 |
</div>
|
159 |
</div>
|
160 |
|
161 |
<script>
|
162 |
+
document.getElementById('image-input').addEventListener('change', async function (e) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
const file = e.target.files[0];
|
164 |
if (file) {
|
165 |
// Show preview
|
166 |
+
const preview = document.getElementById('image-preview');
|
167 |
const reader = new FileReader();
|
168 |
reader.onload = function (e) {
|
169 |
+
preview.src = e.target.result;
|
170 |
+
preview.classList.remove('hidden');
|
|
|
171 |
};
|
172 |
reader.readAsDataURL(file);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
|
174 |
+
// Show loading
|
175 |
+
document.getElementById('loading').classList.remove('hidden');
|
176 |
+
document.getElementById('result-container').classList.add('hidden');
|
177 |
+
document.getElementById('result').classList.add('math-hidden');
|
|
|
178 |
|
179 |
+
try {
|
180 |
+
const formData = new FormData();
|
181 |
+
formData.append('image', file);
|
182 |
|
183 |
+
const response = await fetch('/generate', {
|
184 |
+
method: 'POST',
|
185 |
+
body: formData
|
186 |
+
});
|
|
|
187 |
|
188 |
+
const data = await response.json();
|
|
|
189 |
|
190 |
+
// Hide loading
|
191 |
+
document.getElementById('loading').classList.add('hidden');
|
192 |
|
193 |
+
// Show result
|
194 |
+
document.getElementById('result-container').classList.remove('hidden');
|
195 |
+
// Utiliser marked pour convertir le markdown en HTML
|
196 |
+
document.getElementById('result').innerHTML = marked.parse(data.result);
|
197 |
|
198 |
+
// Rendre les maths avec MathJax
|
199 |
+
MathJax.typesetPromise([document.getElementById('result')])
|
|
|
200 |
.then(() => {
|
201 |
+
document.getElementById('result').classList.remove('math-hidden');
|
202 |
})
|
203 |
.catch((err) => {
|
204 |
console.error('Erreur MathJax:', err);
|
205 |
+
document.getElementById('result').innerHTML = "Erreur lors du rendu des mathématiques.";
|
206 |
+
document.getElementById('result').classList.remove('math-hidden');
|
207 |
});
|
|
|
208 |
|
209 |
+
} catch (error) {
|
210 |
+
console.error('Erreur:', error);
|
211 |
+
document.getElementById('loading').classList.add('hidden');
|
212 |
+
alert('Une erreur est survenue lors du traitement de l\'image.');
|
213 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
}
|
215 |
});
|
216 |
</script>
|