Spaces:
Sleeping
Sleeping
File size: 1,930 Bytes
b6aa8ff | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Cow Breed Classifier</title>
<style>
body { font-family: Arial, sans-serif; text-align: center; margin-top: 50px; }
.preview { margin-top: 20px; }
img { max-width: 300px; margin-top: 10px; }
.result { margin-top: 20px; font-size: 18px; font-weight: bold; }
</style>
</head>
<body>
<h1>Cow Breed Classifier</h1>
<form id="uploadForm">
<input type="file" name="image" id="imageInput" accept="image/*" required>
<button type="submit">Upload & Predict</button>
</form>
<div class="preview">
<p>Selected Image:</p>
<img id="previewImg" src="" alt="Preview">
</div>
<div class="result" id="result"></div>
<script>
const form = document.getElementById("uploadForm");
const imageInput = document.getElementById("imageInput");
const previewImg = document.getElementById("previewImg");
const resultDiv = document.getElementById("result");
imageInput.addEventListener("change", () => {
const file = imageInput.files[0];
if (file) {
previewImg.src = URL.createObjectURL(file);
}
});
form.addEventListener("submit", async (e) => {
e.preventDefault();
const file = imageInput.files[0];
if (!file) {
alert("Please select an image first!");
return;
}
const formData = new FormData();
formData.append("image", file);
try {
const response = await fetch("/predict", { method: "POST", body: formData });
const data = await response.json();
if (data.error) {
resultDiv.textContent = "Error: " + data.error;
} else {
resultDiv.textContent = `Prediction: ${data.label} (Confidence: ${(data.confidence * 100).toFixed(2)}%)`;
}
} catch (err) {
resultDiv.textContent = "Request failed: " + err;
}
});
</script>
</body>
</html>
|