Spaces:
Running
Running
Download script.js from faisalbilal/iris-ml-predictor: direct link, hf CLI and curl.
- Browser
- Download file 2.15 kB
-
https://huggingface.co/spaces/faisalbilal/iris-ml-predictor/resolve/main/script.js
- Command line
-
hf download hf://spaces/faisalbilal/iris-ml-predictor/script.js
-
curl -L -o script.js https://huggingface.co/spaces/faisalbilal/iris-ml-predictor/resolve/main/script.js
2.15 kB
| 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(); |