Spaces:
Sleeping
Sleeping
import gradio as gr | |
from sklearn.ensemble import RandomForestRegressor | |
import xgboost | |
from xgboost import XGBRegressor | |
import pickle | |
import pandas as pd | |
filename = 'xgboost_model_all.pickle' | |
xgb = pickle.load(open(filename, 'rb')) | |
def predict_price(area, year, rooms, floor_number, distance_from_center, alarm_system, | |
security_system, terrasse, parking, high_ceiling, multy_storey_apartment, private_yard, | |
kitchen_plus_livingroom): | |
x = pd.DataFrame([{'details__Plotas': area, 'details__Metai': year, | |
'details__Kambarių sk.': rooms, | |
'details__Aukštas':floor_number, | |
'dist_from_cntr': distance_from_center, | |
'details__Apsauga__Signalizacija': alarm_system, | |
'details__Apsauga__Vaizdo kameros': security_system, | |
# 'details__Papildoma įranga__Indaplovė', | |
# 'details__Papildoma įranga__Rekuperacinė sistema', | |
# 'details__Papildoma įranga__Šildomos grindys', | |
# 'details__Papildoma įranga__Židinys', | |
'details__Papildomos patalpos__Terasa': terrasse, | |
'details__Papildomos patalpos__Vieta automobiliui': parking, | |
'details__Ypatybės__Aukštos lubos': high_ceiling, | |
'details__Ypatybės__Butas per kelis aukštus': multy_storey_apartment, | |
'details__Ypatybės__Uždaras kiemas': private_yard, | |
'details__Ypatybės__Virtuvė sujungta su kambariu': kitchen_plus_livingroom | |
}]) | |
print(x) | |
return float(rf.predict(x)) | |
iface = gr.Interface(fn=predict_price, inputs=[gr.inputs.Slider(10, 180, 1, 80), | |
gr.inputs.Slider(1900, 2023, 1, 2010), | |
gr.inputs.Slider(1, 8, 1, 2), | |
gr.inputs.Slider(1, 15, 1, 2), | |
gr.inputs.Slider(0, 10, 0.5, 0.5), | |
"checkbox", | |
"checkbox", | |
"checkbox", | |
"checkbox", | |
"checkbox", | |
"checkbox", | |
"checkbox", | |
"checkbox", | |
], outputs="text") | |
iface.launch() | |
# filename = 'simple_rf_model.pickle' | |
# rf = pickle.load(open(filename, 'rb')) | |
# | |
# def predict_price(area, year, if_center, if_senamiestis, rooms): | |
# x = pd.DataFrame([{'details__Plotas': area, 'details__Metai': year, 'seniunija__Centras': int(if_center), | |
# 'seniunija__Senamiestis': int(if_senamiestis), 'details__Kambarių sk.': rooms}]) | |
# print(x) | |
# return float(rf.predict(x)) | |
# | |
# | |
# iface = gr.Interface(fn=predict_price, inputs=[gr.inputs.Slider(10, 200, 1, 80), gr.inputs.Slider(1950, 2022, 1, 2010), | |
# "checkbox", "checkbox", gr.inputs.Slider(1, 5, 1, 2)], outputs="text") | |
# iface.launch() |