-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.py
More file actions
110 lines (90 loc) · 5.3 KB
/
Copy pathweb.py
File metadata and controls
110 lines (90 loc) · 5.3 KB
1
2
3
4
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import streamlit as st
import plotly.graph_objects as go
import numpy as np
import pandas as pd
import joblib
import math
from sklearn.preprocessing import StandardScaler
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.models import load_model
from tensorflow.keras.losses import MeanSquaredError
st.set_page_config(page_title="MSE Wall Prediction", layout="wide")
col1, col2, col3 = st.columns([2, 1, 2])
with col2:
try:
st.image("logo.png", use_container_width=True)
except:
st.markdown("<div style='text-align: center;'>(พื้นที่สำหรับใส่โลโก้)</div>", unsafe_allow_html=True)
@st.cache_resource
def load_assets():
sc_in = joblib.load('scaler_All_input.pkl')
sc_out = joblib.load('scaler_All_output.pkl')
model = load_model('model_All_1_(256, 256, 128).h5', custom_objects={'mse': MeanSquaredError()})
return sc_in, sc_out, model
scaler, all_output, model_All = load_assets()
st.title("Machine Learning-Based Prediction for Mechanically Stabilized Earth Walls")
st.subheader("Fast and accurate estimation of Displacement and Factor of Safety (FOS) using Deep Learning trained on Finite Element Method.")
st.subheader("Please complete all fields to proceed.")
user1 = st.number_input("Height of wall (m) : ", min_value=0.1, value=6.0)
user2 = st.number_input("Distance behind the wall (m) : ", min_value=0.1, value=15.0)
user3 = st.number_input("Spacing of Geogrid (m) : ", min_value=0.1, value=0.5)
user4 = st.number_input("Length of Geogrid (m) : ", min_value=0.1, value=6.0)
user5 = st.number_input("Axial Stiffness of Geogrid (kN/m) : ", min_value=0.1, value=3200.0)
if st.button("ENTER", type="primary"):
user_input = {
'Spacing of Geogrid (m)': user3/user4,
'Length of Geogrid (m)': user4/user1,
'EA of Geogrid (KN/m)': user5,
'Distance behind the wall' : user2/15}
user_df = pd.DataFrame([user_input])
user_scaled = scaler.transform(user_df)
All_pred = model_All.predict(user_scaled)
All_pred_scaled = all_output.inverse_transform(All_pred).flatten()
hor_disp = All_pred_scaled[0:16]
ver_settle = All_pred_scaled[16:32]
fos_value = All_pred_scaled[32]
fig = go.Figure()
# 1. วาดเส้นระดับดินเดิม (Original Ground Surface)
dist_levels = np.linspace(0, user2, 16)
original_ground = np.full(16, user1)
fig.add_trace(go.Scatter(x=dist_levels, y=original_ground, name="Original Ground", line=dict(color='grey', dash='dash')))
# 2. วาดการทรุดตัวของผิวดิน (Settled Ground Surface)
height_levels = np.linspace(-1.5, user1, 16)
settled_ground = original_ground + (ver_settle*5)
fig.add_trace(go.Scatter(x=dist_levels, y=settled_ground, name="Vertical Displacement", fill='tozeroy'))
fig.add_trace(go.Scatter(x=[-5, user2, user2, -5],y=[0, 0, -2, -2],fill='toself',fillcolor='rgba(200, 200, 200, 0.3)',line=dict(width=0),name="Foundation Soil"))
# 3. วาดการเคลื่อนตัวของกำแพง (Wall Displacement)
fig.add_trace(go.Scatter(x=hor_disp*10, y=height_levels, mode='lines+markers',name='Horizontal Displacement',line=dict(color='royalblue', width=4)))
# 4. วาดตำแหน่งกำแพงเดิม (จุดอ้างอิง x=0)
fig.add_trace(go.Scatter(x=[0, 0], y=[-1.5, user1],mode='lines',name='Original Wall Position',line=dict(color='black', width=1)))
fig.add_trace(go.Scatter(x=[-1, 1], y=[-1.5, -1.5],mode='lines',name='Footing',line=dict(color='black', width=4)))
# 5. วาดเส้นจีโอกริด
ratio = user1 / user3
if abs(ratio - round(ratio)) < 1e-6:
num_geogrids = int(round(ratio)) - 1
else:
num_geogrids = math.floor(ratio)
geogrid_y_levels = [user3 * (i + 1) for i in range(num_geogrids)]
for i, y_elev in enumerate(geogrid_y_levels):
fig.add_trace(go.Scatter(x=[0, user4],y=[y_elev, y_elev],mode='lines',line=dict(color='forestgreen', width=2, dash='dot'),name="Geogrid",showlegend=(i == 0)))
# ตั้งค่า Layout ให้เหมือนรูปตัดขวาง
fig.update_layout(title="MSE Wall Deformation Cross-section",xaxis_title="Horizontal Distance / Displacement (m)",yaxis_title="Elevation (m)",width=1500, height=600,
yaxis=dict(scaleanchor="x",scaleratio=1,range=[-2, user1 + 1]),xaxis=dict(range=[-10, user2 + 5]),template="plotly_white",margin=dict(l=40, r=40, t=60, b=40))
st.plotly_chart(fig, use_container_width=False)
st.divider()
st.metric(label="Maximum Horizontal Displacement (m)", value=f"{min(hor_disp):.3f} m")
st.divider()
st.metric(label="Maximum Vertical Displacement (m)", value=f"{min(ver_settle):.3f} m")
st.divider()
col1, col2 = st.columns(2)
with col1:
st.metric(label="Factor of Safety (FOS)", value=f"{fos_value:.3f}")
with col2:
if fos_value < 1.0:
st.error("Status: Unsafety (Stable Failure)")
else:
st.success("Status: Safety")
else :
st.info("Please complete all fields to proceed.")
st.divider()
st.warning("For preliminary study only. Not for design.")