Update templates/math.html
Browse files- templates/math.html +88 -53
templates/math.html
CHANGED
@@ -4,55 +4,81 @@
|
|
4 |
<title>Résolution de problème mathématique</title>
|
5 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML"></script>
|
6 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/plotly.js/2.24.2/plotly.min.js"></script>
|
|
|
7 |
<style>
|
8 |
-
|
9 |
-
|
10 |
-
margin: 0 auto;
|
11 |
-
padding: 20px;
|
12 |
}
|
13 |
-
.
|
14 |
-
|
15 |
-
padding: 20px;
|
16 |
-
text-align: center;
|
17 |
-
margin-bottom: 20px;
|
18 |
-
}
|
19 |
-
#preview {
|
20 |
-
max-width: 300px;
|
21 |
-
margin: 10px auto;
|
22 |
-
}
|
23 |
-
.result {
|
24 |
-
margin-top: 20px;
|
25 |
-
padding: 20px;
|
26 |
-
border: 1px solid #eee;
|
27 |
-
}
|
28 |
-
.loading {
|
29 |
-
display: none;
|
30 |
-
margin: 20px 0;
|
31 |
-
}
|
32 |
-
.error-message {
|
33 |
-
color: red;
|
34 |
-
margin-top: 10px;
|
35 |
-
display: none;
|
36 |
}
|
37 |
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
</head>
|
39 |
-
<body>
|
40 |
-
<div class="
|
41 |
-
<
|
42 |
-
|
43 |
-
<
|
44 |
-
<
|
45 |
-
<
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
</div>
|
53 |
-
<div id="errorMessage" class="error-message"></div>
|
54 |
</div>
|
55 |
-
<div id="result" class="result"></div>
|
56 |
</div>
|
57 |
|
58 |
<script>
|
@@ -63,7 +89,7 @@
|
|
63 |
|
64 |
reader.onload = function() {
|
65 |
preview.src = reader.result;
|
66 |
-
preview.
|
67 |
}
|
68 |
|
69 |
if (file) {
|
@@ -72,16 +98,16 @@
|
|
72 |
}
|
73 |
|
74 |
document.getElementById('uploadForm').addEventListener('submit', function(e) {
|
75 |
-
e.preventDefault();
|
76 |
|
77 |
const formData = new FormData(this);
|
78 |
const loading = document.getElementById('loading');
|
79 |
const result = document.getElementById('result');
|
80 |
const errorMessage = document.getElementById('errorMessage');
|
81 |
|
82 |
-
// Afficher le
|
83 |
-
loading.
|
84 |
-
errorMessage.
|
85 |
result.innerHTML = '';
|
86 |
|
87 |
fetch('/upload', {
|
@@ -90,23 +116,32 @@
|
|
90 |
})
|
91 |
.then(response => response.json())
|
92 |
.then(data => {
|
93 |
-
loading.
|
94 |
|
95 |
if (data.error) {
|
96 |
errorMessage.textContent = data.error;
|
97 |
-
errorMessage.
|
98 |
} else {
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
if (window.MathJax) {
|
102 |
MathJax.Hub.Queue(["Typeset", MathJax.Hub, result]);
|
103 |
}
|
104 |
}
|
105 |
})
|
106 |
.catch(error => {
|
107 |
-
loading.
|
108 |
errorMessage.textContent = "Une erreur s'est produite lors de l'analyse.";
|
109 |
-
errorMessage.
|
110 |
console.error('Erreur:', error);
|
111 |
});
|
112 |
});
|
|
|
4 |
<title>Résolution de problème mathématique</title>
|
5 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML"></script>
|
6 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/plotly.js/2.24.2/plotly.min.js"></script>
|
7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
8 |
<style>
|
9 |
+
@keyframes spin {
|
10 |
+
to { transform: rotate(360deg); }
|
|
|
|
|
11 |
}
|
12 |
+
.animate-spin-slow {
|
13 |
+
animation: spin 1.5s linear infinite;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
}
|
15 |
</style>
|
16 |
+
<script>
|
17 |
+
MathJax.Hub.Config({
|
18 |
+
tex2jax: {
|
19 |
+
inlineMath: [['$','$'], ['\\(','\\)']],
|
20 |
+
displayMath: [['$$','$$'], ['\\[','\\]']],
|
21 |
+
processEscapes: true
|
22 |
+
}
|
23 |
+
});
|
24 |
+
</script>
|
25 |
</head>
|
26 |
+
<body class="bg-gray-50">
|
27 |
+
<div class="min-h-screen bg-gradient-to-b from-blue-50 to-white">
|
28 |
+
<div class="max-w-4xl mx-auto px-4 py-8">
|
29 |
+
<!-- En-tête -->
|
30 |
+
<div class="text-center mb-8">
|
31 |
+
<h1 class="text-3xl font-bold text-blue-800 mb-2">Résolution de Problèmes Mathématiques</h1>
|
32 |
+
<p class="text-gray-600">Soumettez une image de votre problème mathématique pour obtenir une solution détaillée</p>
|
33 |
+
</div>
|
34 |
+
|
35 |
+
<!-- Zone de téléchargement -->
|
36 |
+
<div class="bg-white rounded-lg shadow-lg p-6 mb-8">
|
37 |
+
<form id="uploadForm" class="space-y-4" enctype="multipart/form-data">
|
38 |
+
<!-- Zone de drop -->
|
39 |
+
<div class="border-2 border-dashed border-blue-300 rounded-lg p-8 text-center hover:border-blue-500 transition-colors">
|
40 |
+
<div class="flex flex-col items-center">
|
41 |
+
<div class="mb-4">
|
42 |
+
<svg class="w-12 h-12 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
43 |
+
<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"/>
|
44 |
+
</svg>
|
45 |
+
</div>
|
46 |
+
<label class="cursor-pointer">
|
47 |
+
<span class="bg-blue-500 text-white px-4 py-2 rounded-lg hover:bg-blue-600 transition-colors">
|
48 |
+
Sélectionner une image
|
49 |
+
</span>
|
50 |
+
<input type="file" id="imageInput" name="image" accept="image/*" class="hidden" onchange="previewImage(event)">
|
51 |
+
</label>
|
52 |
+
</div>
|
53 |
+
<img id="preview" class="max-h-64 mx-auto mt-4 hidden rounded-lg">
|
54 |
+
</div>
|
55 |
+
|
56 |
+
<!-- Bouton d'analyse -->
|
57 |
+
<div class="text-center">
|
58 |
+
<button type="submit" class="bg-blue-600 text-white px-8 py-3 rounded-lg hover:bg-blue-700 transition-colors focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2">
|
59 |
+
Analyser l'image
|
60 |
+
</button>
|
61 |
+
</div>
|
62 |
+
</form>
|
63 |
+
|
64 |
+
<!-- Loading spinner -->
|
65 |
+
<div id="loading" class="hidden">
|
66 |
+
<div class="flex items-center justify-center py-8">
|
67 |
+
<div class="animate-spin-slow rounded-full h-16 w-16 border-4 border-blue-500 border-t-transparent"></div>
|
68 |
+
</div>
|
69 |
+
<p class="text-center text-gray-600">Analyse en cours... Veuillez patienter.</p>
|
70 |
+
</div>
|
71 |
+
|
72 |
+
<!-- Message d'erreur -->
|
73 |
+
<div id="errorMessage" class="hidden mt-4 p-4 bg-red-50 text-red-700 rounded-lg">
|
74 |
+
</div>
|
75 |
+
</div>
|
76 |
+
|
77 |
+
<!-- Zone de résultat -->
|
78 |
+
<div id="result" class="bg-white rounded-lg shadow-lg p-6 prose max-w-none">
|
79 |
+
<!-- Les résultats seront insérés ici -->
|
80 |
</div>
|
|
|
81 |
</div>
|
|
|
82 |
</div>
|
83 |
|
84 |
<script>
|
|
|
89 |
|
90 |
reader.onload = function() {
|
91 |
preview.src = reader.result;
|
92 |
+
preview.classList.remove('hidden');
|
93 |
}
|
94 |
|
95 |
if (file) {
|
|
|
98 |
}
|
99 |
|
100 |
document.getElementById('uploadForm').addEventListener('submit', function(e) {
|
101 |
+
e.preventDefault();
|
102 |
|
103 |
const formData = new FormData(this);
|
104 |
const loading = document.getElementById('loading');
|
105 |
const result = document.getElementById('result');
|
106 |
const errorMessage = document.getElementById('errorMessage');
|
107 |
|
108 |
+
// Afficher le loading
|
109 |
+
loading.classList.remove('hidden');
|
110 |
+
errorMessage.classList.add('hidden');
|
111 |
result.innerHTML = '';
|
112 |
|
113 |
fetch('/upload', {
|
|
|
116 |
})
|
117 |
.then(response => response.json())
|
118 |
.then(data => {
|
119 |
+
loading.classList.add('hidden');
|
120 |
|
121 |
if (data.error) {
|
122 |
errorMessage.textContent = data.error;
|
123 |
+
errorMessage.classList.remove('hidden');
|
124 |
} else {
|
125 |
+
// Formater la réponse en LaTeX si nécessaire
|
126 |
+
let formattedResult = data.result;
|
127 |
+
|
128 |
+
// Si la réponse n'est pas déjà en LaTeX, on peut l'entourer de balises mathématiques
|
129 |
+
if (!formattedResult.includes('$$') && !formattedResult.includes('\\[')) {
|
130 |
+
formattedResult = `\\[${formattedResult}\\]`;
|
131 |
+
}
|
132 |
+
|
133 |
+
result.innerHTML = formattedResult;
|
134 |
+
|
135 |
+
// Recharger MathJax
|
136 |
if (window.MathJax) {
|
137 |
MathJax.Hub.Queue(["Typeset", MathJax.Hub, result]);
|
138 |
}
|
139 |
}
|
140 |
})
|
141 |
.catch(error => {
|
142 |
+
loading.classList.add('hidden');
|
143 |
errorMessage.textContent = "Une erreur s'est produite lors de l'analyse.";
|
144 |
+
errorMessage.classList.remove('hidden');
|
145 |
console.error('Erreur:', error);
|
146 |
});
|
147 |
});
|