Spaces:
Sleeping
Sleeping
File size: 2,842 Bytes
13a3c1c 2f77190 13a3c1c 1a47281 13a3c1c 2f77190 1a47281 2f77190 1a47281 2f77190 83fe380 13a3c1c |
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 |
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()
|