Spaces:
Runtime error
Runtime error
feat: fetch api using ajax
Browse files- templates/index.html +49 -37
templates/index.html
CHANGED
|
@@ -5,6 +5,7 @@
|
|
| 5 |
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet" />
|
|
|
|
| 8 |
<title>Aplikasi Prediksi Biaya Asuransi</title>
|
| 9 |
</head>
|
| 10 |
|
|
@@ -19,7 +20,7 @@
|
|
| 19 |
<main class="bg-white p-16 rounded-lg">
|
| 20 |
<h1 class="text-3xl font-bold mb-8">Prediksi Biaya Asuransi Anda:</h1>
|
| 21 |
|
| 22 |
-
<form
|
| 23 |
<label for="age" class="mb-2">Usia</label>
|
| 24 |
<input type="text" name="age" placeholder="Usia" required="required" class="p-4 bg-gray-100 rounded-md" />
|
| 25 |
|
|
@@ -60,17 +61,15 @@
|
|
| 60 |
<section class="mt-8 h-full flex-auto rounded-lg md:mt-0 md:ml-8">
|
| 61 |
<div class="bg-white p-16 rounded-lg">
|
| 62 |
<h1 class="text-2xl mb-8">Estimasi biaya asuransi Anda adalah</h1>
|
| 63 |
-
<h2 class="text-5xl font-bold"
|
| 64 |
-
{% if insurance_cost != 0 %}
|
| 65 |
<div class="mt-8">
|
| 66 |
-
<p><strong>Usia:</strong>
|
| 67 |
-
<p><strong>Jenis kelamin:</strong>
|
| 68 |
-
<p><strong>Status perokok:</strong>
|
| 69 |
-
<p><strong>BMI:</strong>
|
| 70 |
-
<p><strong>Jumlah Anak:</strong>
|
| 71 |
-
<p><strong>Region:</strong>
|
| 72 |
</div>
|
| 73 |
-
{% endif %}
|
| 74 |
</div>
|
| 75 |
<div class="flex justify-around p-16 rounded-lg mt-8">
|
| 76 |
<img class="h-24 md:h-28" src="https://elib.its.ac.id/conf/cyberdas/public/assets/img/img_navbar.svg" alt="logo-dts" />
|
|
@@ -79,33 +78,12 @@
|
|
| 79 |
</section>
|
| 80 |
</div>
|
| 81 |
|
| 82 |
-
<div id="Model2" class="Model
|
| 83 |
-
<
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
<label for="">
|
| 89 |
-
|
| 90 |
-
</label>
|
| 91 |
-
<button type="submit" class="flex justify-center align-center mt-8 p-4 bg-gradient-to-r from-green-400 to-green-700 text-white rounded-md">
|
| 92 |
-
PREDIKSI SEKARANG<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-right ml-4">
|
| 93 |
-
<line x1="5" y1="12" x2="19" y2="12"></line>
|
| 94 |
-
<polyline points="12 5 19 12 12 19"></polyline>
|
| 95 |
-
</svg>
|
| 96 |
-
</button>
|
| 97 |
-
</form>
|
| 98 |
-
</div>
|
| 99 |
-
</section>
|
| 100 |
-
<section class="mt-8 h-full flex-auto rounded-lg md:mt-0 md:ml-8">
|
| 101 |
-
<div class="bg-white p-16 rounded-lg">
|
| 102 |
-
<h1 class="text-3xl font-bold mb-8"> Hasil Prediksi :</h1>
|
| 103 |
-
</div>
|
| 104 |
-
<div class="flex justify-around p-16 rounded-lg mt-8">
|
| 105 |
-
<img class="h-24 md:h-28" src="https://elib.its.ac.id/conf/cyberdas/public/assets/img/img_navbar.svg" alt="logo-dts" />
|
| 106 |
-
</div>
|
| 107 |
-
</section>
|
| 108 |
-
</section>
|
| 109 |
</div>
|
| 110 |
|
| 111 |
<style>
|
|
@@ -133,4 +111,38 @@
|
|
| 133 |
evt.currentTarget.className += " active";
|
| 134 |
}
|
| 135 |
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
</html>
|
|
|
|
| 5 |
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet" />
|
| 8 |
+
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
| 9 |
<title>Aplikasi Prediksi Biaya Asuransi</title>
|
| 10 |
</head>
|
| 11 |
|
|
|
|
| 20 |
<main class="bg-white p-16 rounded-lg">
|
| 21 |
<h1 class="text-3xl font-bold mb-8">Prediksi Biaya Asuransi Anda:</h1>
|
| 22 |
|
| 23 |
+
<form enctype="multipart/form-data" class="flex flex-col" id="upload_form">
|
| 24 |
<label for="age" class="mb-2">Usia</label>
|
| 25 |
<input type="text" name="age" placeholder="Usia" required="required" class="p-4 bg-gray-100 rounded-md" />
|
| 26 |
|
|
|
|
| 61 |
<section class="mt-8 h-full flex-auto rounded-lg md:mt-0 md:ml-8">
|
| 62 |
<div class="bg-white p-16 rounded-lg">
|
| 63 |
<h1 class="text-2xl mb-8">Estimasi biaya asuransi Anda adalah</h1>
|
| 64 |
+
<h2 class="text-5xl font-bold">$<span id="insurance_cost"></span></h2>
|
|
|
|
| 65 |
<div class="mt-8">
|
| 66 |
+
<p><strong>Usia:</strong> <span id="respAge"></span> tahun</p>
|
| 67 |
+
<p><strong>Jenis kelamin:</strong> <span id="respSex"></span></p>
|
| 68 |
+
<p><strong>Status perokok:</strong> <span id="respSmoker"></span></p>
|
| 69 |
+
<p><strong>BMI:</strong> <span id="respBmi"></span></p>
|
| 70 |
+
<p><strong>Jumlah Anak:</strong> <span id="respChildren"></span></p>
|
| 71 |
+
<p><strong>Region:</strong> <span id="respRegion"></span></p>
|
| 72 |
</div>
|
|
|
|
| 73 |
</div>
|
| 74 |
<div class="flex justify-around p-16 rounded-lg mt-8">
|
| 75 |
<img class="h-24 md:h-28" src="https://elib.its.ac.id/conf/cyberdas/public/assets/img/img_navbar.svg" alt="logo-dts" />
|
|
|
|
| 78 |
</section>
|
| 79 |
</div>
|
| 80 |
|
| 81 |
+
<div id="Model2" class="Model">
|
| 82 |
+
<iframe
|
| 83 |
+
src="https://alproits-yolov8-pothole.hf.space"
|
| 84 |
+
frameborder="0"
|
| 85 |
+
class="h-screen w-screen"
|
| 86 |
+
></iframe>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
</div>
|
| 88 |
|
| 89 |
<style>
|
|
|
|
| 111 |
evt.currentTarget.className += " active";
|
| 112 |
}
|
| 113 |
</script>
|
| 114 |
+
<script>
|
| 115 |
+
$(document).ready(function () {
|
| 116 |
+
$("#upload_form").submit(function (event) {
|
| 117 |
+
event.preventDefault(); // Prevent the default form submission
|
| 118 |
+
|
| 119 |
+
// Get the form data
|
| 120 |
+
var formData = new FormData(this);
|
| 121 |
+
|
| 122 |
+
// Make the Ajax request
|
| 123 |
+
$.ajax({
|
| 124 |
+
type: "POST",
|
| 125 |
+
url: "http://127.0.0.1:8000/predict", // Replace with the correct URL
|
| 126 |
+
data: formData,
|
| 127 |
+
processData: false,
|
| 128 |
+
contentType: false,
|
| 129 |
+
success: function (response) {
|
| 130 |
+
// Handle the response data
|
| 131 |
+
$('#respAge').html(response.age);
|
| 132 |
+
$('#respSex').html(response.sex);
|
| 133 |
+
$('#respSmoker').html(response.smoker);
|
| 134 |
+
$('#respBmi').html(response.bmi);
|
| 135 |
+
$('#respChildren').html(response.children);
|
| 136 |
+
$('#respRegion').html(response.region);
|
| 137 |
+
$('#insurance_cost').html(response.insurance_cost);
|
| 138 |
+
console.log(response);
|
| 139 |
+
},
|
| 140 |
+
error: function (error) {
|
| 141 |
+
console.error("Error:", error);
|
| 142 |
+
}
|
| 143 |
+
});
|
| 144 |
+
});
|
| 145 |
+
});
|
| 146 |
+
</script>
|
| 147 |
+
</body>
|
| 148 |
</html>
|