Spaces:
Sleeping

final-sp / index.html
ayush0100's picture
Add FastAPI app, frontend, Dockerfile, and ML model
e6f62db
Raw History Blame Contribute Delete
2.71 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Student Pass/Fail Prediction</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 500px;
margin: 50px auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 10px;
background-color: #f9f9f9;
}
h1 {
text-align: center;
}
label {
display: inline-block;
width: 80px;
}
input {
width: 200px;
padding: 5px;
margin-bottom: 10px;
}
button {
padding: 8px 20px;
cursor: pointer;
}
#result {
margin-top: 20px;
font-size: 1.2em;
font-weight: bold;
}
</style>
</head>
<body>
<h1>Student Pass/Fail Prediction</h1>
<form id="predictionForm">
<label for="Math">Math:</label>
<input type="number" id="Math" required><br>
<label for="English">English:</label>
<input type="number" id="English" required><br>
<label for="Science">Science:</label>
<input type="number" id="Science" required><br>
<button type="submit">Predict</button>
</form>
<div id="result"></div>
<script>
const form = document.getElementById("predictionForm");
form.addEventListener("submit", async (e) => {
e.preventDefault(); // prevent page reload
const data = {
Math: parseFloat(document.getElementById("Math").value),
English: parseFloat(document.getElementById("English").value),
Science: parseFloat(document.getElementById("Science").value)
};
try {
const response = await fetch("/predict", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data)
});
if (!response.ok) throw new Error(`Server error: ${response.status}`);
const result = await response.json();
if (result && result.result) {
document.getElementById("result").innerText = "Prediction: " + result.result;
} else {
document.getElementById("result").innerText = "Prediction failed: Invalid response";
}
} catch (error) {
console.error(error);
document.getElementById("result").innerText = "Prediction failed: " + error.message;
}
});
</script>
</body>
</html>