Update app.py
Browse files
app.py
CHANGED
|
@@ -242,127 +242,141 @@ def index():
|
|
| 242 |
except Exception as e:
|
| 243 |
print("DEBUG: Error removing uploaded file:", e)
|
| 244 |
return render_template_string('''
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
}
|
| 259 |
-
.header {
|
| 260 |
text-align: center;
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
padding: 5px;
|
| 270 |
-
|
| 271 |
-
|
| 272 |
margin-top: 20px;
|
| 273 |
-
}
|
| 274 |
-
.footer {
|
| 275 |
-
text-align: center;
|
| 276 |
font-size: 0.9em;
|
| 277 |
-
color: #
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
<
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
<
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
<td>{{ det.height_cm }}</td>
|
| 346 |
-
</tr>
|
| 347 |
-
{% endfor %}
|
| 348 |
-
</tbody>
|
| 349 |
-
</table>
|
| 350 |
-
</div>
|
| 351 |
-
</div>
|
| 352 |
-
</div>
|
| 353 |
-
</div>
|
| 354 |
-
</div>
|
| 355 |
-
{% endif %}
|
| 356 |
-
<div class="footer">
|
| 357 |
-
<p>© 2023 Multi-Detection App. All rights reserved.</p>
|
| 358 |
-
</div>
|
| 359 |
-
</div>
|
| 360 |
-
<!-- Bootstrap JS and dependencies -->
|
| 361 |
-
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
|
| 362 |
-
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
|
| 363 |
-
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
| 364 |
-
</body>
|
| 365 |
-
</html>
|
| 366 |
''', image_data=image_data, detection_info=detection_info)
|
| 367 |
|
| 368 |
#########################################
|
|
@@ -372,3 +386,4 @@ def index():
|
|
| 372 |
if __name__ == '__main__':
|
| 373 |
# Ensure the app runs on 0.0.0.0 and port 7860 for Hugging Face Spaces.
|
| 374 |
app.run(host="0.0.0.0", port=7860)
|
|
|
|
|
|
| 242 |
except Exception as e:
|
| 243 |
print("DEBUG: Error removing uploaded file:", e)
|
| 244 |
return render_template_string('''
|
| 245 |
+
<!DOCTYPE html>
|
| 246 |
+
<html lang="en">
|
| 247 |
+
<head>
|
| 248 |
+
<meta charset="UTF-8">
|
| 249 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 250 |
+
<title>MathLens - AI Detection & Measurement</title>
|
| 251 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
|
| 252 |
+
<style>
|
| 253 |
+
@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&display=swap');
|
| 254 |
+
body {
|
| 255 |
+
background-color: #fff;
|
| 256 |
+
color: #000;
|
| 257 |
+
font-family: "Share Tech Mono", monospace;
|
|
|
|
|
|
|
| 258 |
text-align: center;
|
| 259 |
+
display: flex;
|
| 260 |
+
flex-direction: column;
|
| 261 |
+
justify-content: center;
|
| 262 |
+
align-items: center;
|
| 263 |
+
height: 100vh;
|
| 264 |
+
overflow: hidden;
|
| 265 |
+
}
|
| 266 |
+
.typing-effect {
|
| 267 |
+
font-size: 2rem;
|
| 268 |
+
font-weight: bold;
|
| 269 |
+
margin-bottom: 10px;
|
| 270 |
+
height: 50px;
|
| 271 |
+
}
|
| 272 |
+
input[type="file"], button {
|
| 273 |
+
display: block;
|
| 274 |
+
margin: 10px auto;
|
| 275 |
+
padding: 10px;
|
| 276 |
+
background: none;
|
| 277 |
+
border: 2px solid #000;
|
| 278 |
+
color: #000;
|
| 279 |
+
font-size: 1rem;
|
| 280 |
+
font-family: "Share Tech Mono", monospace;
|
| 281 |
+
cursor: pointer;
|
| 282 |
+
}
|
| 283 |
+
input[type="file"]::file-selector-button {
|
| 284 |
+
background: none;
|
| 285 |
+
border: none;
|
| 286 |
+
color: #000;
|
| 287 |
+
font-family: "Share Tech Mono", monospace;
|
| 288 |
+
}
|
| 289 |
+
.content-wrapper {
|
| 290 |
+
display: flex;
|
| 291 |
+
flex-direction: row;
|
| 292 |
+
align-items: center;
|
| 293 |
+
justify-content: space-evenly;
|
| 294 |
+
width: 90%;
|
| 295 |
+
max-width: 1200px;
|
| 296 |
+
}
|
| 297 |
+
.result-img {
|
| 298 |
+
max-width: 45%;
|
| 299 |
+
border: 2px solid #000;
|
| 300 |
+
}
|
| 301 |
+
table {
|
| 302 |
+
max-width: 45%;
|
| 303 |
+
border-collapse: collapse;
|
| 304 |
+
}
|
| 305 |
+
th, td {
|
| 306 |
+
border: 1px solid #000;
|
| 307 |
padding: 5px;
|
| 308 |
+
}
|
| 309 |
+
.footer {
|
| 310 |
margin-top: 20px;
|
|
|
|
|
|
|
|
|
|
| 311 |
font-size: 0.9em;
|
| 312 |
+
color: #000;
|
| 313 |
+
}
|
| 314 |
+
</style>
|
| 315 |
+
</head>
|
| 316 |
+
<body>
|
| 317 |
+
<div class="typing-effect" id="typing"></div>
|
| 318 |
+
<form method="post" enctype="multipart/form-data">
|
| 319 |
+
<input type="file" name="file" accept="image/*" required>
|
| 320 |
+
<button type="submit">Analyze Image</button>
|
| 321 |
+
</form>
|
| 322 |
+
{% if image_data or detection_info %}
|
| 323 |
+
<div class="content-wrapper">
|
| 324 |
+
<img src="data:image/jpeg;base64,{{ image_data }}" alt="Processed Image" class="result-img">
|
| 325 |
+
<table>
|
| 326 |
+
<thead>
|
| 327 |
+
<tr>
|
| 328 |
+
<th>#</th>
|
| 329 |
+
<th>Class</th>
|
| 330 |
+
<th>Confidence</th>
|
| 331 |
+
<th>Width (cm)</th>
|
| 332 |
+
<th>Height (cm)</th>
|
| 333 |
+
</tr>
|
| 334 |
+
</thead>
|
| 335 |
+
<tbody>
|
| 336 |
+
{% for det in detection_info %}
|
| 337 |
+
<tr>
|
| 338 |
+
<td>{{ loop.index }}</td>
|
| 339 |
+
<td>{{ det.class }}</td>
|
| 340 |
+
<td>{{ det.confidence }}</td>
|
| 341 |
+
<td>{{ det.width_cm }}</td>
|
| 342 |
+
<td>{{ det.height_cm }}</td>
|
| 343 |
+
</tr>
|
| 344 |
+
{% endfor %}
|
| 345 |
+
</tbody>
|
| 346 |
+
</table>
|
| 347 |
+
</div>
|
| 348 |
+
{% endif %}
|
| 349 |
+
<div class="footer">© 2024 MathLens AI Detection App. All rights reserved.</div>
|
| 350 |
+
<script>
|
| 351 |
+
const textArray = ["MathLens", "Smart Counting with Maths"];
|
| 352 |
+
let textIndex = 0;
|
| 353 |
+
let charIndex = 0;
|
| 354 |
+
let isDeleting = false;
|
| 355 |
+
const typingElement = document.getElementById("typing");
|
| 356 |
+
function typeEffect() {
|
| 357 |
+
let currentText = textArray[textIndex];
|
| 358 |
+
if (isDeleting) {
|
| 359 |
+
typingElement.textContent = currentText.substring(0, charIndex--);
|
| 360 |
+
} else {
|
| 361 |
+
typingElement.textContent = currentText.substring(0, charIndex++);
|
| 362 |
+
}
|
| 363 |
+
if (!isDeleting && charIndex === currentText.length) {
|
| 364 |
+
setTimeout(() => { isDeleting = true; typeEffect(); }, 3000);
|
| 365 |
+
} else if (isDeleting && charIndex === 0) {
|
| 366 |
+
isDeleting = false;
|
| 367 |
+
textIndex = (textIndex + 1) % textArray.length;
|
| 368 |
+
setTimeout(typeEffect, 500);
|
| 369 |
+
} else {
|
| 370 |
+
setTimeout(typeEffect, isDeleting ? 50 : 100);
|
| 371 |
+
}
|
| 372 |
+
}
|
| 373 |
+
document.addEventListener("DOMContentLoaded", () => {
|
| 374 |
+
setTimeout(typeEffect, 500);
|
| 375 |
+
});
|
| 376 |
+
</script>
|
| 377 |
+
</body>
|
| 378 |
+
</html>
|
| 379 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 380 |
''', image_data=image_data, detection_info=detection_info)
|
| 381 |
|
| 382 |
#########################################
|
|
|
|
| 386 |
if __name__ == '__main__':
|
| 387 |
# Ensure the app runs on 0.0.0.0 and port 7860 for Hugging Face Spaces.
|
| 388 |
app.run(host="0.0.0.0", port=7860)
|
| 389 |
+
|