omaralaa2004 commited on
Commit
2838bad
·
verified ·
1 Parent(s): e84de77

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +21 -9
templates/index.html CHANGED
@@ -323,7 +323,6 @@
323
  opacity: 1;
324
  }
325
 
326
- /* Ensure summary labels are clean */
327
  .summary-label {
328
  font-weight: 600;
329
  color: var(--primary-color);
@@ -646,7 +645,7 @@
646
  e.preventDefault();
647
 
648
  if (validateStep(currentStep)) {
649
- // Show loading overlay
650
  $('#loading-overlay').fadeIn();
651
 
652
  // Collect form data
@@ -662,6 +661,7 @@
662
  bmi: $('#bmi').val(),
663
  smoking_status: $('#smoking_status').val()
664
  };
 
665
 
666
  // Send data to Flask backend
667
  $.ajax({
@@ -669,12 +669,15 @@
669
  type: 'POST',
670
  contentType: 'application/json',
671
  data: JSON.stringify({ input: formData }),
 
 
 
672
  success: function(response) {
 
 
 
673
  if (response.success) {
674
- // Hide loading overlay
675
- $('#loading-overlay').fadeOut();
676
-
677
- // Process and display result
678
  $('#prediction-result').text(response.prediction);
679
  $('#result').removeClass('high-risk low-risk');
680
  if (response.prediction === 'Stroke Risk') {
@@ -685,16 +688,25 @@
685
  $('#result').show().removeClass('animate__fadeOut').addClass('animate__fadeIn');
686
  $('#prediction-form').hide();
687
  } else {
688
- $('#loading-overlay').fadeOut();
689
  alert('Error: ' + response.error);
 
690
  }
691
  },
692
  error: function(xhr, status, error) {
693
- console.error('Error submitting data:', error);
694
  $('#loading-overlay').fadeOut();
695
- alert('An error occurred while processing your request. Please try again.');
 
 
 
 
 
 
696
  }
697
  });
 
 
698
  }
699
  });
700
  });
 
323
  opacity: 1;
324
  }
325
 
 
326
  .summary-label {
327
  font-weight: 600;
328
  color: var(--primary-color);
 
645
  e.preventDefault();
646
 
647
  if (validateStep(currentStep)) {
648
+ console.log("Form validated, initiating prediction request");
649
  $('#loading-overlay').fadeIn();
650
 
651
  // Collect form data
 
661
  bmi: $('#bmi').val(),
662
  smoking_status: $('#smoking_status').val()
663
  };
664
+ console.log("Form data collected:", formData);
665
 
666
  // Send data to Flask backend
667
  $.ajax({
 
669
  type: 'POST',
670
  contentType: 'application/json',
671
  data: JSON.stringify({ input: formData }),
672
+ beforeSend: function() {
673
+ console.log("Sending AJAX request to /predict");
674
+ },
675
  success: function(response) {
676
+ console.log("Received response:", response);
677
+ $('#loading-overlay').fadeOut();
678
+
679
  if (response.success) {
680
+ console.log("Prediction successful, rendering result");
 
 
 
681
  $('#prediction-result').text(response.prediction);
682
  $('#result').removeClass('high-risk low-risk');
683
  if (response.prediction === 'Stroke Risk') {
 
688
  $('#result').show().removeClass('animate__fadeOut').addClass('animate__fadeIn');
689
  $('#prediction-form').hide();
690
  } else {
691
+ console.error("Prediction failed:", response.error);
692
  alert('Error: ' + response.error);
693
+ $('#result').hide();
694
  }
695
  },
696
  error: function(xhr, status, error) {
697
+ console.error("AJAX request failed:", { status: status, error: error, response: xhr.responseText });
698
  $('#loading-overlay').fadeOut();
699
+ $('#prediction-result').text("Error occurred while processing your request.");
700
+ $('#result').removeClass('high-risk low-risk').addClass('high-risk');
701
+ $('#result').show().removeClass('animate__fadeOut').addClass('animate__fadeIn');
702
+ $('#prediction-form').hide();
703
+ },
704
+ complete: function() {
705
+ console.log("AJAX request completed");
706
  }
707
  });
708
+ } else {
709
+ console.log("Form validation failed");
710
  }
711
  });
712
  });