Manvikk commited on
Commit
709f5f1
·
verified ·
1 Parent(s): 67f676f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +132 -117
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
- <!doctype html>
246
- <html>
247
- <head>
248
- <title>Multi-Detection & Measurement</title>
249
- <!-- Bootstrap CSS -->
250
- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
251
- <style>
252
- body {
253
- background-color: #f8f9fa;
254
- font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
255
- }
256
- .container {
257
- margin-top: 30px;
258
- }
259
- .header {
260
  text-align: center;
261
- margin-bottom: 30px;
262
- }
263
- .card {
264
- margin-bottom: 30px;
265
- }
266
- .result-img {
267
- width: 100%;
268
- border: 1px solid #ddd;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
  padding: 5px;
270
- }
271
- .table-responsive {
272
  margin-top: 20px;
273
- }
274
- .footer {
275
- text-align: center;
276
  font-size: 0.9em;
277
- color: #777;
278
- margin-top: 30px;
279
- }
280
- </style>
281
- </head>
282
- <body>
283
- <div class="container">
284
- <h1 class="header">Multi-Detection & Measurement</h1>
285
- <!-- Upload Form -->
286
- <div class="card">
287
- <div class="card-body">
288
- <form method="post" enctype="multipart/form-data">
289
- <div class="form-group">
290
- <label for="file">Choose an image to upload:</label>
291
- <input type="file" class="form-control-file" name="file" accept="image/*" id="file">
292
- </div>
293
- <button type="submit" class="btn btn-primary">Upload</button>
294
- </form>
295
- {% with messages = get_flashed_messages() %}
296
- {% if messages %}
297
- <div class="alert alert-danger mt-3">
298
- <ul>
299
- {% for message in messages %}
300
- <li>{{ message }}</li>
301
- {% endfor %}
302
- </ul>
303
- </div>
304
- {% endif %}
305
- {% endwith %}
306
- </div>
307
- </div>
308
- {% if image_data or detection_info %}
309
- <div class="row">
310
- <div class="col-md-8">
311
- <div class="card">
312
- <div class="card-header">
313
- Processed Image
314
- </div>
315
- <div class="card-body">
316
- <img src="data:image/jpeg;base64,{{ image_data }}" alt="Processed Image" class="result-img">
317
- </div>
318
- </div>
319
- </div>
320
- <div class="col-md-4">
321
- <div class="card">
322
- <div class="card-header">
323
- Detection Results
324
- </div>
325
- <div class="card-body">
326
- <p>Total Results: <strong>{{ detection_info|length }}</strong></p>
327
- <div class="table-responsive">
328
- <table class="table table-striped table-bordered">
329
- <thead class="thead-dark">
330
- <tr>
331
- <th>#</th>
332
- <th>Class</th>
333
- <th>Confidence</th>
334
- <th>Width (cm)</th>
335
- <th>Height (cm)</th>
336
- </tr>
337
- </thead>
338
- <tbody>
339
- {% for det in detection_info %}
340
- <tr>
341
- <td>{{ loop.index }}</td>
342
- <td>{{ det.class }}</td>
343
- <td>{{ det.confidence }}</td>
344
- <td>{{ det.width_cm }}</td>
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>&copy; 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">&copy; 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
+