Spaces:
Running
Running
File size: 1,416 Bytes
03632f3 | 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 67 68 69 70 |
let session = null;
async function loadModel() {
try {
session = await ort.InferenceSession.create("iris_model.onnx");
document.getElementById("result").innerText =
"Model loaded successfully!";
} catch (error) {
document.getElementById("result").innerText =
"Error loading model: " + error;
}
}
async function predict() {
if (!session) {
alert("Model is still loading. Please wait.");
return;
}
const sepalLength = parseFloat(
document.getElementById("sepalLength").value
);
const sepalWidth = parseFloat(
document.getElementById("sepalWidth").value
);
const petalLength = parseFloat(
document.getElementById("petalLength").value
);
const petalWidth = parseFloat(
document.getElementById("petalWidth").value
);
const input = new Float32Array([
sepalLength,
sepalWidth,
petalLength,
petalWidth
]);
const tensor = new ort.Tensor(
"float32",
input,
[1, 4]
);
const results = await session.run({
float_input: tensor
});
const prediction = results.label.data[0];
const flowers = [
"Setosa",
"Versicolor",
"Virginica"
];
document.getElementById("result").innerText =
"Prediction: " + flowers[prediction];
}
loadModel();
|