rc-column-ui / app.py
DK 이대근
Deploy RC column predictor with Gradio
13a3c1c
raw
history blame
3.04 kB
import gradio as gr
import numpy as np
import joblib
import tensorflow as tf
from huggingface_hub import hf_hub_download
# 1) 허브에서 모델·스케일러 파일 다운로드
model_path = hf_hub_download(repo_id="dklee2013/rc-column-predictor",
filename="model0526.keras")
sx_path = hf_hub_download(repo_id="dklee2013/rc-column-predictor",
filename="sx.save")
sy_path = hf_hub_download(repo_id="dklee2013/rc-column-predictor",
filename="sy.save")
model = tf.keras.models.load_model(model_path)
scaler_X = joblib.load(sx_path)
scaler_y = joblib.load(sy_path)
def predict(f_ck, f_yk, N_Ed, M_Edz, M_Edy, cover, rebar_dia, dc_ratio):
# 1차 예측
X1 = np.array([f_ck, f_yk, N_Ed, M_Edz, M_Edy, cover, rebar_dia]).reshape(1,-1)
Y1 = scaler_y.inverse_transform(model.predict(scaler_X.transform(X1)))
a = Y1[0,5]
# 모멘트 보정
M_Edz_sc = M_Edz * (1/dc_ratio)**a
M_Edy_sc = M_Edy * (1/dc_ratio)**a
# 2차 예측
X2 = np.array([f_ck, f_yk, N_Ed, M_Edz_sc, M_Edy_sc, cover, rebar_dia]).reshape(1,-1)
Y2 = scaler_y.inverse_transform(model.predict(scaler_X.transform(X2)))
# 결과
b_pred = int(round(Y2[0,0]/50)*50)
h_pred = int(round(Y2[0,1]/50)*50)
rr = float(Y2[0,2])
rx = int(round(Y2[0,3]))
ry = int(round(Y2[0,4]))
z1_a = float(Y2[0,5])
z2_N = float(Y2[0,6])
z3_Mz = float(Y2[0,7])
z4_My = float(Y2[0,8])
SF = (M_Edz / z3_Mz)**z1_a + (M_Edy / z4_My)**z1_a
return {
"b_pred": b_pred,
"h_pred": h_pred,
"reinforcement_ratio": rr,
"rebar_x": rx,
"rebar_y": ry,
"exponent_a": round(z1_a,4),
"N_Rd": round(z2_N,2),
"M_Rdz": round(z3_Mz,2),
"M_Rdy": round(z4_My,2),
"SF": round(SF,4)
}
# 3) Gradio UI 정의
inputs = [
gr.Number(label="f_ck (MPa)", value=40),
gr.Number(label="f_yk (MPa)", value=500),
gr.Number(label="N_Ed (kN)", value=500),
gr.Number(label="M_Edz (kN·m)", value=100),
gr.Number(label="M_Edy (kN·m)", value=150),
gr.Number(label="cover (mm)", value=40),
gr.Number(label="rebar_dia (mm)", value=25),
gr.Number(label="dc_ratio", value=0.9, precision=2)
]
outputs = {
"b_pred": gr.Number(label="b_pred (mm)"),
"h_pred": gr.Number(label="h_pred (mm)"),
"reinforcement_ratio": gr.Number(label="reinforcement_ratio"),
"rebar_x": gr.Number(label="rebar_x (개)"),
"rebar_y": gr.Number(label="rebar_y (개)"),
"exponent_a": gr.Number(label="exponent a"),
"N_Rd": gr.Number(label="N_Rd"),
"M_Rdz": gr.Number(label="M_Rdz"),
"M_Rdy": gr.Number(label="M_Rdy"),
"SF": gr.Number(label="Safety Factor")
}
demo = gr.Interface(fn=predict,
inputs=inputs,
outputs=outputs,
title="🔧 RC 기둥 단면 예측기",
description="Eurocode 2 기반 ML 모델을 이용한 RC 기둥 단면 예측")
if __name__ == "__main__":
demo.launch()