Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
65 lines (52 loc) · 1.84 KB
/
Copy pathscript.js
File metadata and controls
65 lines (52 loc) · 1.84 KB
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
function predict() {
const sl = document.getElementById("sl").value;
const sw = document.getElementById("sw").value;
const pl = document.getElementById("pl").value;
const pw = document.getElementById("pw").value;
const result = document.getElementById("result");
const error = document.getElementById("error");
result.innerText = "";
error.innerText = "";
if (!sl || !sw || !pl || !pw) {
error.innerText = "⚠️ Please enter all values";
return;
}
fetch('http://127.0.0.1:5000/predict', {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
features: [parseFloat(sl), parseFloat(sw), parseFloat(pl), parseFloat(pw)]
})
})
.then(res => res.json())
.then(data => {
result.innerText = "🌼 Prediction: " + data.prediction;
});
}
function showInfo(type) {
const modal = document.getElementById("modal");
const text = document.getElementById("modal-text");
let message = "";
if (type === "setosa") {
message = "🌸 Setosa: Small petals, easiest to classify. Usually found in colder regions.";
}
else if (type === "versicolor") {
message = "🌼 Versicolor: Medium-sized petals, very common iris species.";
}
else if (type === "virginica") {
message = "🌺 Virginica: Large petals, grows in wetter environments.";
}
text.innerText = message;
modal.style.display = "flex";
}
// close modal
function closeModal() {
document.getElementById("modal").style.display = "none";
}
// optional: click outside to close
window.onclick = function(event) {
const modal = document.getElementById("modal");
if (event.target === modal) {
modal.style.display = "none";
}
}