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();