Manvikk commited on
Commit
95ee92b
ยท
verified ยท
1 Parent(s): c0d4e9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -47
app.py CHANGED
@@ -278,7 +278,7 @@ landing_template = '''
278
  </html>
279
  '''
280
 
281
- # --- Upload & Result Page Template (Original Design with Home Button and Progress Bar Loading Overlay) ---
282
  upload_template = '''
283
  <!DOCTYPE html>
284
  <html lang="en">
@@ -344,38 +344,36 @@ upload_template = '''
344
  background-color: #000;
345
  color: #fff;
346
  }
347
- /* Progress bar overlay styles */
348
- #loading {
349
  position: fixed;
350
  top: 0;
351
  left: 0;
352
  width: 100%;
353
  height: 100%;
354
- background: rgba(255,255,255,0.95);
355
  display: none;
356
- flex-direction: column;
357
  align-items: center;
358
  justify-content: center;
 
359
  z-index: 9999;
360
  }
361
  #progressContainer {
362
  width: 80%;
363
- max-width: 600px;
364
- background: #ddd;
365
- border: 2px solid #000;
366
- border-radius: 5px;
367
- overflow: hidden;
368
- margin-bottom: 20px;
369
  }
370
  #progressBar {
371
- width: 0%;
372
- height: 30px;
373
- background: #000;
374
- transition: width 0.2s;
 
 
375
  }
376
  #progressText {
 
377
  font-size: 1.2rem;
378
- font-weight: bold;
379
  }
380
  .content-wrapper {
381
  display: flex;
@@ -427,16 +425,16 @@ upload_template = '''
427
  <body>
428
  <!-- Home button -->
429
  <a href="{{ url_for('landing') }}" class="home-btn">Home</a>
430
- <!-- Progress bar loading overlay -->
431
- <div id="loading">
432
- <div id="progressContainer">
433
- <div id="progressBar"></div>
434
- </div>
435
- <div id="progressText">Initializing... ๐Ÿ”„</div>
436
  </div>
437
  <div class="typing-effect" id="typing"></div>
438
- <!-- onsubmit calls the showLoading() function -->
439
- <form method="post" enctype="multipart/form-data" onsubmit="showLoading()">
440
  <input type="file" name="file" accept="image/*" required>
441
  <!-- Hidden field to pass the selected object type -->
442
  <input type="hidden" name="object_type" value="{{ object_type }}">
@@ -471,39 +469,49 @@ upload_template = '''
471
  {% endif %}
472
  <div class="footer">&copy; 2024 MathLens AI Detection App. All rights reserved.</div>
473
  <script>
474
- // Function to show the loading overlay with a progress bar and cool phrases
475
- function showLoading() {
476
- document.getElementById("loading").style.display = "flex";
477
- let progress = 0;
478
- const progressBar = document.getElementById("progressBar");
479
- const progressText = document.getElementById("progressText");
480
- // Array of phrases with their upper progress limits
481
- const phrases = [
482
- {limit: 20, text: "Writing scripts... โœ๏ธ"},
483
- {limit: 40, text: "Calculating formulas... ๐Ÿ”ข"},
484
- {limit: 60, text: "Mixing up magic... โœจ"},
485
- {limit: 80, text: "Almost there... ๐Ÿš€"},
486
- {limit: 100, text: "Finalizing details... โœ…"}
 
 
 
 
 
 
 
 
 
 
 
 
487
  ];
488
- // Update progress every 50ms (simulation)
489
- const interval = setInterval(() => {
490
- // Increase progress by a random value (to add some variability)
491
- progress += Math.floor(Math.random() * 3) + 1;
492
  if (progress > 100) progress = 100;
493
  progressBar.style.width = progress + "%";
494
- // Update phrase based on current progress
495
- for (let i = 0; i < phrases.length; i++) {
496
- if (progress <= phrases[i].limit) {
497
  progressText.textContent = phrases[i].text;
498
  break;
499
  }
500
  }
501
- // If progress reaches 100, clear the interval
502
- if (progress >= 100) {
503
  clearInterval(interval);
 
504
  }
505
- }, 50);
506
  }
 
507
  // Existing typing effect code
508
  const textArray = ["MathLens", "Smart Counting with Maths"];
509
  let textIndex = 0;
 
278
  </html>
279
  '''
280
 
281
+ # --- Upload & Result Page Template (Original Design with Home Button and Progress Bar Overlay) ---
282
  upload_template = '''
283
  <!DOCTYPE html>
284
  <html lang="en">
 
344
  background-color: #000;
345
  color: #fff;
346
  }
347
+ /* Progress overlay styles */
348
+ #progressOverlay {
349
  position: fixed;
350
  top: 0;
351
  left: 0;
352
  width: 100%;
353
  height: 100%;
354
+ background: rgba(255,255,255,0.9);
355
  display: none;
 
356
  align-items: center;
357
  justify-content: center;
358
+ flex-direction: column;
359
  z-index: 9999;
360
  }
361
  #progressContainer {
362
  width: 80%;
363
+ max-width: 400px;
 
 
 
 
 
364
  }
365
  #progressBar {
366
+ height: 20px;
367
+ width: 0;
368
+ background-color: #000;
369
+ border-radius: 10px;
370
+ -webkit-transition: width 0.05s linear;
371
+ transition: width 0.05s linear;
372
  }
373
  #progressText {
374
+ margin-top: 10px;
375
  font-size: 1.2rem;
376
+ font-family: "Share Tech Mono", monospace;
377
  }
378
  .content-wrapper {
379
  display: flex;
 
425
  <body>
426
  <!-- Home button -->
427
  <a href="{{ url_for('landing') }}" class="home-btn">Home</a>
428
+ <!-- Progress overlay with progress bar and dynamic text -->
429
+ <div id="progressOverlay">
430
+ <div id="progressContainer">
431
+ <div id="progressBar"></div>
432
+ <div id="progressText">Starting up... ๐Ÿ› ๏ธ</div>
433
+ </div>
434
  </div>
435
  <div class="typing-effect" id="typing"></div>
436
+ <!-- The form now has an id and an onsubmit handler -->
437
+ <form id="uploadForm" method="post" enctype="multipart/form-data" onsubmit="handleFormSubmit(event)">
438
  <input type="file" name="file" accept="image/*" required>
439
  <!-- Hidden field to pass the selected object type -->
440
  <input type="hidden" name="object_type" value="{{ object_type }}">
 
469
  {% endif %}
470
  <div class="footer">&copy; 2024 MathLens AI Detection App. All rights reserved.</div>
471
  <script>
472
+ // Intercept form submission and simulate a progress bar animation
473
+ function handleFormSubmit(e) {
474
+ e.preventDefault();
475
+ // Determine if the visitor is on mobile (adjust delay accordingly)
476
+ var isMobile = /Mobi|Android/i.test(navigator.userAgent);
477
+ var totalDelay = isMobile ? 5000 : 2000; // 5 seconds on mobile, 2 seconds on desktop
478
+ startProgressAndSubmit(totalDelay);
479
+ }
480
+
481
+ // Animate the progress overlay and then submit the form after the simulated delay
482
+ function startProgressAndSubmit(totalTime) {
483
+ var progressOverlay = document.getElementById("progressOverlay");
484
+ progressOverlay.style.display = "flex";
485
+ var progressBar = document.getElementById("progressBar");
486
+ var progressText = document.getElementById("progressText");
487
+ var progress = 0;
488
+ var updateInterval = totalTime / 100; // time (ms) per 1% increment
489
+ var phrases = [
490
+ { threshold: 0, text: "Starting up... ๐Ÿ› ๏ธ" },
491
+ { threshold: 10, text: "Writing scripts... ๐Ÿค–" },
492
+ { threshold: 30, text: "Calculating formulas... ๐Ÿงฎ" },
493
+ { threshold: 50, text: "Crunching numbers... ๐Ÿ”ข" },
494
+ { threshold: 70, text: "Almost there... ๐Ÿš€" },
495
+ { threshold: 90, text: "Finalizing... ๐Ÿ" },
496
+ { threshold: 100, text: "Done! โœ…" }
497
  ];
498
+ var interval = setInterval(function() {
499
+ progress++;
 
 
500
  if (progress > 100) progress = 100;
501
  progressBar.style.width = progress + "%";
502
+ for (var i = phrases.length - 1; i >= 0; i--) {
503
+ if (progress >= phrases[i].threshold) {
 
504
  progressText.textContent = phrases[i].text;
505
  break;
506
  }
507
  }
508
+ if (progress === 100) {
 
509
  clearInterval(interval);
510
+ document.getElementById("uploadForm").submit();
511
  }
512
+ }, updateInterval);
513
  }
514
+
515
  // Existing typing effect code
516
  const textArray = ["MathLens", "Smart Counting with Maths"];
517
  let textIndex = 0;