yasirabd commited on
Commit
08c00f6
·
verified ·
1 Parent(s): 7b16738

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
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!")