import gradio as gr import pandas as pd import pickle # 모델 로딩 함수 def load_model(): with open("model.pkl", "rb") as file: loaded_pipeline = pickle.load(file) return loaded_pipeline # 예측 함수 정의 def predict(construction_type, underground_floors, aboveground_floors, total_area, land_area, building_area, landscape_area, parking_lot_count, order_year, order_month, construction_period, location, building_purpose): new_project = { '구조': [construction_type], '지하층수': [underground_floors], '지상층수': [aboveground_floors], '연면적': [total_area], '대지면적': [land_area], '건축면적': [building_area], '조경면적': [landscape_area], '주차수': [parking_lot_count], '발주년': [order_year], '발주월': [order_month], '공사기간': [construction_period], '현장위치': [location], '건축법상용도': [building_purpose], } model = load_model() prediction = model.predict(pd.DataFrame.from_dict(new_project)) return prediction[0].tolist() # Gradio 인터페이스 생성 iface = gr.Interface( fn=predict, inputs=[ gr.Textbox(label="구조"), gr.Number(label="지하층수"), gr.Number(label="지상층수"), gr.Number(label="연면적(m2)"), gr.Number(label="대지면적(m2)"), gr.Number(label="건축면적(m2)"), gr.Number(label="조경면적(m2)"), gr.Number(label="주차대수"), gr.Number(label="발주년도"), gr.Dropdown(range(1, 13), label="발주월"), gr.Number(label="공사기간(일))"), gr.Textbox(label="현장위치(도/시)"), gr.Textbox(label="건축법상용도") ], outputs=[ gr.Textbox(label="건축공사비"), gr.Textbox(label="기계공사비"), gr.Textbox(label="전기공사비"), gr.Textbox(label="통신공사비"), gr.Textbox(label="토목공사비"), gr.Textbox(label="조경공사비") ] ) # Gradio 앱을 실행합니다. iface.launch()