Spaces:
Running
Running
File size: 2,152 Bytes
771bd14 cef88ed acf98bd 771bd14 cef88ed acf98bd 771bd14 acf98bd 771bd14 cef88ed 771bd14 cef88ed 771bd14 03ec3ce acf98bd cef88ed acf98bd cef88ed 03ec3ce acf98bd cef88ed acf98bd cef88ed 03ec3ce cef88ed 03ec3ce cef88ed 03ec3ce 771bd14 cef88ed 03ec3ce acf98bd cef88ed acf98bd cef88ed acf98bd cef88ed 03ec3ce acf98bd 771bd14 acf98bd | 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | let session = null;
async function loadModel() {
try {
session = await ort.InferenceSession.create("iris_model.onnx");
document.getElementById("result").innerText =
"Model loaded successfully!";
console.log("INPUT NAMES:", session.inputNames);
console.log("OUTPUT NAMES:", session.outputNames);
} catch (error) {
document.getElementById("result").innerText =
"Model loading error: " + error.message;
console.error(error);
}
}
async function predict() {
const resultBox = document.getElementById("result");
if (!session) {
resultBox.innerText = "Model is not ready.";
return;
}
const values = [
parseFloat(document.getElementById("sepalLength").value),
parseFloat(document.getElementById("sepalWidth").value),
parseFloat(document.getElementById("petalLength").value),
parseFloat(document.getElementById("petalWidth").value)
];
if (values.some(v => Number.isNaN(v))) {
resultBox.innerText = "Please enter all four values.";
return;
}
try {
const inputTensor = new ort.Tensor(
"float32",
new Float32Array(values),
[1, 4]
);
const results = await session.run({
float_input: inputTensor
});
console.log("========== ONNX RESULTS ==========");
for (const name of session.outputNames) {
const output = results[name];
console.log("NAME:", name);
console.log("OUTPUT:", output);
console.log("TYPE:", typeof output);
if (output) {
console.log("DATA:", output.data);
console.log("DIMS:", output.dims);
}
console.log("--------------------------------");
}
resultBox.innerText =
"Prediction executed. Press F12 → Console and check the output.";
} catch (error) {
console.error("PREDICTION ERROR:", error);
resultBox.innerText =
"Prediction error: " + error.message;
}
}
loadModel(); |