File size: 3,572 Bytes
8910b73
ea196a8
747f6bd
7fd0941
ea196a8
090352c
6b71fc3
8910b73
2b592f6
 
 
77c764b
 
2b592f6
5e361ba
304aa88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3d971db
99dfc6f
ea196a8
 
304aa88
 
 
 
 
 
 
 
 
 
 
 
 
 
ea196a8
81b56f4
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from sklearn.ensemble import RandomForestRegressor
import xgboost
from xgboost import XGBRegressor
import pickle
import pandas as pd
import numpy as np

# filename = 'xgboost_model_all.pickle'
# xgb = pickle.load(open(filename, 'rb'))

print(xgboost.__version__)

xgb = XGBRegressor(n_estimators=1000, learning_rate=0.04, objective='reg:squarederror') #xgboost. # or which ever sklearn booster you're are using
xgb.load_model("xgboost_model_all.ubj")

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 int(xgb.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()