Spaces:
Runtime error
Runtime error
Update templates/index.html
Browse filesintégration de la jauge euclidienne
- templates/index.html +86 -34
templates/index.html
CHANGED
@@ -55,7 +55,36 @@
|
|
55 |
font-size: 18px;
|
56 |
color: #555;
|
57 |
}
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
margin-top: 30px;
|
60 |
text-align: center;
|
61 |
}
|
@@ -134,28 +163,39 @@
|
|
134 |
</div>
|
135 |
<div id="results"></div>
|
136 |
</div>
|
137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
</div>
|
139 |
|
140 |
<!-- Scripts -->
|
141 |
<script>
|
142 |
let file1 = null;
|
143 |
let file2 = null;
|
144 |
-
|
145 |
function resetSelection(target) {
|
146 |
for (let i = 1; i <= 3; i++) {
|
147 |
const img = document.getElementById(`preset-${i}-${target}`);
|
148 |
if (img) img.classList.remove('selected');
|
149 |
}
|
150 |
}
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
function selectPreset(presetNumber, target) {
|
155 |
const imgElement = document.getElementById(`preset-${presetNumber}-${target}`);
|
156 |
const imagePath = imgElement.getAttribute('src'); // Récupère le chemin exact
|
157 |
const fileName = imagePath.split('/').pop(); // Extrait le nom du fichier
|
158 |
-
|
159 |
fetch(imagePath)
|
160 |
.then(res => {
|
161 |
if (!res.ok) throw new Error(`Impossible de charger ${fileName}`);
|
@@ -181,8 +221,6 @@
|
|
181 |
})
|
182 |
.then(() => checkReadyToCompare());
|
183 |
}
|
184 |
-
|
185 |
-
|
186 |
function updatePreview(blob, target) {
|
187 |
const reader = new FileReader();
|
188 |
reader.onload = (event) => {
|
@@ -197,21 +235,18 @@
|
|
197 |
};
|
198 |
reader.readAsDataURL(blob);
|
199 |
}
|
200 |
-
|
201 |
document.getElementById('fileInput1').addEventListener('change', (e) => {
|
202 |
file1 = e.target.files[0];
|
203 |
updatePreview(file1, 1);
|
204 |
resetSelection(1);
|
205 |
checkReadyToCompare();
|
206 |
});
|
207 |
-
|
208 |
document.getElementById('fileInput2').addEventListener('change', (e) => {
|
209 |
file2 = e.target.files[0];
|
210 |
updatePreview(file2, 2);
|
211 |
resetSelection(2);
|
212 |
checkReadyToCompare();
|
213 |
});
|
214 |
-
|
215 |
function checkReadyToCompare() {
|
216 |
const container = document.getElementById('compareButtonContainer');
|
217 |
if (file1 && file2) {
|
@@ -222,50 +257,67 @@
|
|
222 |
container.innerHTML = '';
|
223 |
}
|
224 |
}
|
225 |
-
|
226 |
async function processImages() {
|
227 |
if (!file1 || !file2) {
|
228 |
alert('Please select two images first!');
|
229 |
return;
|
230 |
}
|
231 |
-
|
232 |
const formData = new FormData();
|
233 |
formData.append('image1', file1);
|
234 |
formData.append('image2', file2);
|
235 |
-
|
236 |
const resultsDiv = document.getElementById('results');
|
237 |
resultsDiv.innerHTML = `
|
238 |
<div class="loading-container">
|
239 |
<div class="spinner-border text-primary" role="status"></div>
|
240 |
<div class="loading-text">Processing...</div>
|
241 |
</div>`;
|
242 |
-
|
243 |
try {
|
244 |
const response = await fetch('/process', {
|
245 |
method: 'POST',
|
246 |
body: formData
|
247 |
});
|
248 |
-
|
249 |
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
250 |
const data = await response.json();
|
251 |
-
|
252 |
if (data.distance !== undefined) {
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
</script>
|
270 |
|
271 |
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
|
55 |
font-size: 18px;
|
56 |
color: #555;
|
57 |
}
|
58 |
+
.jauge-container {
|
59 |
+
display: flex;
|
60 |
+
align-items: center;
|
61 |
+
}
|
62 |
+
.jauge {
|
63 |
+
position: relative;
|
64 |
+
width: 40px;
|
65 |
+
height: 200px;
|
66 |
+
border: 2px solid #ccc;
|
67 |
+
border-radius: 10px;
|
68 |
+
background: #f0f0f0;
|
69 |
+
overflow: hidden;
|
70 |
+
margin-right: 20px;
|
71 |
+
}
|
72 |
+
.jauge-level {
|
73 |
+
position: absolute;
|
74 |
+
width: 100%;
|
75 |
+
bottom: 0;
|
76 |
+
border-radius: 8px;
|
77 |
+
transition: height 1s ease, background-color 1s ease;
|
78 |
+
}
|
79 |
+
.jauge-labels {
|
80 |
+
display: flex;
|
81 |
+
flex-direction: column;
|
82 |
+
justify-content: space-between;
|
83 |
+
height: 200px;
|
84 |
+
font-size: 0.8rem;
|
85 |
+
text-align: left;
|
86 |
+
}
|
87 |
+
#compareSection {
|
88 |
margin-top: 30px;
|
89 |
text-align: center;
|
90 |
}
|
|
|
163 |
</div>
|
164 |
<div id="results"></div>
|
165 |
</div>
|
166 |
+
|
167 |
+
<h2>Euclidean Distance: <span id="euclidVal"></span></h2>
|
168 |
+
|
169 |
+
<div class="jauge-container">
|
170 |
+
<div class="jauge">
|
171 |
+
<div class="jauge-level" id="jaugeLevel"></div>
|
172 |
+
</div>
|
173 |
+
<div class="jauge-labels">
|
174 |
+
<span>most certainly</span>
|
175 |
+
<span>very probably</span>
|
176 |
+
<span>probably</span>
|
177 |
+
<span>possibly</span>
|
178 |
+
<span>probably not</span>
|
179 |
+
<span>definitely not</span>
|
180 |
+
</div>
|
181 |
+
</div>
|
182 |
+
|
183 |
</div>
|
184 |
|
185 |
<!-- Scripts -->
|
186 |
<script>
|
187 |
let file1 = null;
|
188 |
let file2 = null;
|
|
|
189 |
function resetSelection(target) {
|
190 |
for (let i = 1; i <= 3; i++) {
|
191 |
const img = document.getElementById(`preset-${i}-${target}`);
|
192 |
if (img) img.classList.remove('selected');
|
193 |
}
|
194 |
}
|
|
|
|
|
|
|
195 |
function selectPreset(presetNumber, target) {
|
196 |
const imgElement = document.getElementById(`preset-${presetNumber}-${target}`);
|
197 |
const imagePath = imgElement.getAttribute('src'); // Récupère le chemin exact
|
198 |
const fileName = imagePath.split('/').pop(); // Extrait le nom du fichier
|
|
|
199 |
fetch(imagePath)
|
200 |
.then(res => {
|
201 |
if (!res.ok) throw new Error(`Impossible de charger ${fileName}`);
|
|
|
221 |
})
|
222 |
.then(() => checkReadyToCompare());
|
223 |
}
|
|
|
|
|
224 |
function updatePreview(blob, target) {
|
225 |
const reader = new FileReader();
|
226 |
reader.onload = (event) => {
|
|
|
235 |
};
|
236 |
reader.readAsDataURL(blob);
|
237 |
}
|
|
|
238 |
document.getElementById('fileInput1').addEventListener('change', (e) => {
|
239 |
file1 = e.target.files[0];
|
240 |
updatePreview(file1, 1);
|
241 |
resetSelection(1);
|
242 |
checkReadyToCompare();
|
243 |
});
|
|
|
244 |
document.getElementById('fileInput2').addEventListener('change', (e) => {
|
245 |
file2 = e.target.files[0];
|
246 |
updatePreview(file2, 2);
|
247 |
resetSelection(2);
|
248 |
checkReadyToCompare();
|
249 |
});
|
|
|
250 |
function checkReadyToCompare() {
|
251 |
const container = document.getElementById('compareButtonContainer');
|
252 |
if (file1 && file2) {
|
|
|
257 |
container.innerHTML = '';
|
258 |
}
|
259 |
}
|
|
|
260 |
async function processImages() {
|
261 |
if (!file1 || !file2) {
|
262 |
alert('Please select two images first!');
|
263 |
return;
|
264 |
}
|
|
|
265 |
const formData = new FormData();
|
266 |
formData.append('image1', file1);
|
267 |
formData.append('image2', file2);
|
|
|
268 |
const resultsDiv = document.getElementById('results');
|
269 |
resultsDiv.innerHTML = `
|
270 |
<div class="loading-container">
|
271 |
<div class="spinner-border text-primary" role="status"></div>
|
272 |
<div class="loading-text">Processing...</div>
|
273 |
</div>`;
|
|
|
274 |
try {
|
275 |
const response = await fetch('/process', {
|
276 |
method: 'POST',
|
277 |
body: formData
|
278 |
});
|
|
|
279 |
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
280 |
const data = await response.json();
|
|
|
281 |
if (data.distance !== undefined) {
|
282 |
+
//insertion de la jauge
|
283 |
+
const euclid = data.distance;
|
284 |
+
document.getElementById('euclidVal').textContent = euclid.toFixed(2);
|
285 |
+
|
286 |
+
let height = 0, color = '#ccc';
|
287 |
+
|
288 |
+
if (euclid > 60) {
|
289 |
+
height = 0; color = '#198754'; // green
|
290 |
+
} else if (euclid > 55) {
|
291 |
+
height = 16.66; color = '#0d6efd'; // blue
|
292 |
+
} else if (euclid > 50) {
|
293 |
+
height = 33.33; color = '#0dcaf0'; // light blue
|
294 |
+
} else if (euclid > 40) {
|
295 |
+
height = 50; color = '#ffc107'; // yellow
|
296 |
+
} else if (euclid > 35) {
|
297 |
+
height = 66.66; color = '#fd7e14'; // orange
|
298 |
+
} else {
|
299 |
+
height = 83.33; color = '#dc3545'; // red
|
300 |
+
}
|
301 |
+
|
302 |
+
document.getElementById('jaugeLevel').style.height = height + '%';
|
303 |
+
document.getElementById('jaugeLevel').style.backgroundColor = color;
|
304 |
+
//fin d'insertion de la jauge
|
305 |
+
resultsDiv.innerHTML = `
|
306 |
+
<div class="card mt-3 p-4 text-center">
|
307 |
+
<h4>Euclidean Distance</h4>
|
308 |
+
<p class="display-6">${data.distance.toFixed(4)}</p>
|
309 |
+
</div>`;
|
310 |
+
} else {
|
311 |
+
throw new Error('Invalid server response.');
|
312 |
+
}
|
313 |
+
} catch (error) {
|
314 |
+
console.error('Error:', error);
|
315 |
+
resultsDiv.innerHTML = `
|
316 |
+
<div class="alert alert-danger" role="alert">
|
317 |
+
${error.message}
|
318 |
+
</div>`;
|
319 |
+
}
|
320 |
+
}
|
321 |
</script>
|
322 |
|
323 |
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
|