rc-column-ui / app.py
DK 이대근
Fix
1a47281
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,
h_pred,
rr,
rx,
ry,
z1_a,
z2_N,
z3_Mz,
z4_My,
SF
)
# 3) Gradio UI 정의
inputs = [
gr.Number(label="f_ck (MPa) 범위: 30,35,40,45,50", value=40),
gr.Number(label="f_yk (MPa) 범위: 400, 500, 600", value=600),
gr.Number(label="N_Ed (N) 범위: 200e3 ~ 800e3", value=455000),
gr.Number(label="M_Edz (N·mm) 범위: 50e6 ~ 200e6", value=186200000),
gr.Number(label="M_Edy (N·mm) 범위: 50e6 ~ 200e6", value=126100000),
gr.Number(label="cover (mm) 고정", value=50),
gr.Number(label="rebar_dia (mm) 범위: 16,20,25,32,40", value=20),
gr.Number(label="Safety Factor", value=0.9, precision=2)
]
outputs = [
gr.Number(label="b_pred (mm)"),
gr.Number(label="h_pred (mm)"),
gr.Number(label="reinforcement_ratio"),
gr.Number(label="rebar_x (개)"),
gr.Number(label="rebar_y (개)"),
gr.Number(label="exponent a"),
gr.Number(label="N_Rd (N)"),
gr.Number(label="M_Rdz (N·mm)"),
gr.Number(label="M_Rdy (N·mm)"),
gr.Number(label="SF")
]
demo = gr.Interface(
fn=predict,
inputs=inputs,
outputs=outputs,
title="🔧 RC 기둥 단면 설계",
description="Eurocode 2 기반 ML 모델"
)
if __name__ == "__main__":
demo.launch()