Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import numpy as np | |
| import onnxruntime as ort | |
| import os | |
| # 1. Navigasi Path agar bisa menemukan model.onnx di luar folder src | |
| BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | |
| MODEL_PATH = os.path.join(BASE_DIR, "..", "model.onnx") | |
| # 2. Nilai Scaler Manual | |
| MEAN = np.array([568.64435, -826.0645, 466.6756, -989.498, 246.6452, -352.4072, 177.49335, -168.12985, 148.05485, -322.05495, 193.01935, -424.63435, 605.80795, -755.47005, 553.1577, -790.659]) | |
| SCALE = np.array([117.07176288, 124.34028285, 207.7301335, 221.50159863, 63.38759671, 59.32603297, 21.54848616, 11.90921866, 68.10403763, 76.06642249, 92.40615659, 105.37879602, 61.45968896, 70.74213457, 82.39041528, 95.09934868]) | |
| st.title("๐ Beta Front Fork Prediction") | |
| # 3. Form Input | |
| st.subheader("Input Fitur") | |
| feature_names = [ | |
| "pipe_r_front_max", "pipe_r_front_min", "pipe_l_front_max", "pipe_l_front_min", | |
| "pipe_r_rear_max", "pipe_r_rear_min", "pipe_l_rear_max", "pipe_l_rear_min", | |
| "bridge_r_front_max", "bridge_r_front_min", "bridge_l_front_max", "bridge_l_front_min", | |
| "bridge_r_rear_max", "bridge_r_rear_min", "bridge_l_rear_max", "bridge_l_rear_min" | |
| ] | |
| input_data = [] | |
| col1, col2 = st.columns(2) | |
| for i, name in enumerate(feature_names): | |
| with col1 if i < 8 else col2: | |
| val = st.number_input(name, value=0.0) | |
| input_data.append(val) | |
| # 4. Prediksi | |
| if st.button("Predict", type="primary"): | |
| if os.path.exists(MODEL_PATH): | |
| # Preprocessing | |
| x = (np.array(input_data) - MEAN) / SCALE | |
| x = x.astype(np.float32).reshape(1, 16) | |
| # Inference | |
| session = ort.InferenceSession(MODEL_PATH) | |
| input_name = session.get_inputs()[0].name | |
| output = session.run(None, {input_name: x})[0] | |
| # Hasil | |
| res1, res2 = st.columns(2) | |
| res1.metric("Load Angle", f"{output[0][0]:.4f}") | |
| res2.metric("Target Load", f"{output[0][1]:.4f}") | |
| else: | |
| st.error("File model.onnx tidak ditemukan!") |