Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +48 -39
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,49 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import onnxruntime as ort
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# 1. Navigasi Path agar bisa menemukan model.onnx di luar folder src
|
| 7 |
+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 8 |
+
MODEL_PATH = os.path.join(BASE_DIR, "..", "model.onnx")
|
| 9 |
+
|
| 10 |
+
# 2. Nilai Scaler Manual
|
| 11 |
+
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])
|
| 12 |
+
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])
|
| 13 |
+
|
| 14 |
+
st.title("🚜 Beta Front Fork Prediction")
|
| 15 |
+
|
| 16 |
+
# 3. Form Input
|
| 17 |
+
st.subheader("Input Fitur")
|
| 18 |
+
feature_names = [
|
| 19 |
+
"pipe_r_front_max", "pipe_r_front_min", "pipe_l_front_max", "pipe_l_front_min",
|
| 20 |
+
"pipe_r_rear_max", "pipe_r_rear_min", "pipe_l_rear_max", "pipe_l_rear_min",
|
| 21 |
+
"bridge_r_front_max", "bridge_r_front_min", "bridge_l_front_max", "bridge_l_front_min",
|
| 22 |
+
"bridge_r_rear_max", "bridge_r_rear_min", "bridge_l_rear_max", "bridge_l_rear_min"
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
input_data = []
|
| 26 |
+
col1, col2 = st.columns(2)
|
| 27 |
+
for i, name in enumerate(feature_names):
|
| 28 |
+
with col1 if i < 8 else col2:
|
| 29 |
+
val = st.number_input(name, value=0.0)
|
| 30 |
+
input_data.append(val)
|
| 31 |
+
|
| 32 |
+
# 4. Prediksi
|
| 33 |
+
if st.button("Predict", type="primary"):
|
| 34 |
+
if os.path.exists(MODEL_PATH):
|
| 35 |
+
# Preprocessing
|
| 36 |
+
x = (np.array(input_data) - MEAN) / SCALE
|
| 37 |
+
x = x.astype(np.float32).reshape(1, 16)
|
| 38 |
+
|
| 39 |
+
# Inference
|
| 40 |
+
session = ort.InferenceSession(MODEL_PATH)
|
| 41 |
+
input_name = session.get_inputs()[0].name
|
| 42 |
+
output = session.run(None, {input_name: x})[0]
|
| 43 |
+
|
| 44 |
+
# Hasil
|
| 45 |
+
res1, res2 = st.columns(2)
|
| 46 |
+
res1.metric("Load Angle", f"{output[0][0]:.4f}")
|
| 47 |
+
res2.metric("Target Load", f"{output[0][1]:.4f}")
|
| 48 |
+
else:
|
| 49 |
+
st.error("File model.onnx tidak ditemukan!")
|