Spaces:
Sleeping
Sleeping
DK 이대근
commited on
Commit
·
13a3c1c
1
Parent(s):
1a7de91
Deploy RC column predictor with Gradio
Browse files- app.py +89 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import joblib
|
4 |
+
import tensorflow as tf
|
5 |
+
from huggingface_hub import hf_hub_download
|
6 |
+
|
7 |
+
# 1) 허브에서 모델·스케일러 파일 다운로드
|
8 |
+
model_path = hf_hub_download(repo_id="dklee2013/rc-column-predictor",
|
9 |
+
filename="model0526.keras")
|
10 |
+
sx_path = hf_hub_download(repo_id="dklee2013/rc-column-predictor",
|
11 |
+
filename="sx.save")
|
12 |
+
sy_path = hf_hub_download(repo_id="dklee2013/rc-column-predictor",
|
13 |
+
filename="sy.save")
|
14 |
+
|
15 |
+
model = tf.keras.models.load_model(model_path)
|
16 |
+
scaler_X = joblib.load(sx_path)
|
17 |
+
scaler_y = joblib.load(sy_path)
|
18 |
+
|
19 |
+
def predict(f_ck, f_yk, N_Ed, M_Edz, M_Edy, cover, rebar_dia, dc_ratio):
|
20 |
+
# 1차 예측
|
21 |
+
X1 = np.array([f_ck, f_yk, N_Ed, M_Edz, M_Edy, cover, rebar_dia]).reshape(1,-1)
|
22 |
+
Y1 = scaler_y.inverse_transform(model.predict(scaler_X.transform(X1)))
|
23 |
+
a = Y1[0,5]
|
24 |
+
|
25 |
+
# 모멘트 보정
|
26 |
+
M_Edz_sc = M_Edz * (1/dc_ratio)**a
|
27 |
+
M_Edy_sc = M_Edy * (1/dc_ratio)**a
|
28 |
+
|
29 |
+
# 2차 예측
|
30 |
+
X2 = np.array([f_ck, f_yk, N_Ed, M_Edz_sc, M_Edy_sc, cover, rebar_dia]).reshape(1,-1)
|
31 |
+
Y2 = scaler_y.inverse_transform(model.predict(scaler_X.transform(X2)))
|
32 |
+
|
33 |
+
# 결과
|
34 |
+
b_pred = int(round(Y2[0,0]/50)*50)
|
35 |
+
h_pred = int(round(Y2[0,1]/50)*50)
|
36 |
+
rr = float(Y2[0,2])
|
37 |
+
rx = int(round(Y2[0,3]))
|
38 |
+
ry = int(round(Y2[0,4]))
|
39 |
+
z1_a = float(Y2[0,5])
|
40 |
+
z2_N = float(Y2[0,6])
|
41 |
+
z3_Mz = float(Y2[0,7])
|
42 |
+
z4_My = float(Y2[0,8])
|
43 |
+
SF = (M_Edz / z3_Mz)**z1_a + (M_Edy / z4_My)**z1_a
|
44 |
+
|
45 |
+
return {
|
46 |
+
"b_pred": b_pred,
|
47 |
+
"h_pred": h_pred,
|
48 |
+
"reinforcement_ratio": rr,
|
49 |
+
"rebar_x": rx,
|
50 |
+
"rebar_y": ry,
|
51 |
+
"exponent_a": round(z1_a,4),
|
52 |
+
"N_Rd": round(z2_N,2),
|
53 |
+
"M_Rdz": round(z3_Mz,2),
|
54 |
+
"M_Rdy": round(z4_My,2),
|
55 |
+
"SF": round(SF,4)
|
56 |
+
}
|
57 |
+
|
58 |
+
# 3) Gradio UI 정의
|
59 |
+
inputs = [
|
60 |
+
gr.Number(label="f_ck (MPa)", value=40),
|
61 |
+
gr.Number(label="f_yk (MPa)", value=500),
|
62 |
+
gr.Number(label="N_Ed (kN)", value=500),
|
63 |
+
gr.Number(label="M_Edz (kN·m)", value=100),
|
64 |
+
gr.Number(label="M_Edy (kN·m)", value=150),
|
65 |
+
gr.Number(label="cover (mm)", value=40),
|
66 |
+
gr.Number(label="rebar_dia (mm)", value=25),
|
67 |
+
gr.Number(label="dc_ratio", value=0.9, precision=2)
|
68 |
+
]
|
69 |
+
outputs = {
|
70 |
+
"b_pred": gr.Number(label="b_pred (mm)"),
|
71 |
+
"h_pred": gr.Number(label="h_pred (mm)"),
|
72 |
+
"reinforcement_ratio": gr.Number(label="reinforcement_ratio"),
|
73 |
+
"rebar_x": gr.Number(label="rebar_x (개)"),
|
74 |
+
"rebar_y": gr.Number(label="rebar_y (개)"),
|
75 |
+
"exponent_a": gr.Number(label="exponent a"),
|
76 |
+
"N_Rd": gr.Number(label="N_Rd"),
|
77 |
+
"M_Rdz": gr.Number(label="M_Rdz"),
|
78 |
+
"M_Rdy": gr.Number(label="M_Rdy"),
|
79 |
+
"SF": gr.Number(label="Safety Factor")
|
80 |
+
}
|
81 |
+
|
82 |
+
demo = gr.Interface(fn=predict,
|
83 |
+
inputs=inputs,
|
84 |
+
outputs=outputs,
|
85 |
+
title="🔧 RC 기둥 단면 예측기",
|
86 |
+
description="Eurocode 2 기반 ML 모델을 이용한 RC 기둥 단면 예측")
|
87 |
+
|
88 |
+
if __name__ == "__main__":
|
89 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
tensorflow
|
3 |
+
scikit-learn
|
4 |
+
joblib
|
5 |
+
huggingface-hub
|