sivakornchong commited on
Commit
aab7ecd
1 Parent(s): 614da02

first commit

Browse files
Files changed (4) hide show
  1. app.py +23 -0
  2. gender_v1_freezebert.h5 +3 -0
  3. main.py +96 -0
  4. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from main import main_fn
3
+
4
+ #Input structure
5
+ ##Postal_,age_,town_,storey_,room_ = 680705, 30, 'CHOA CHU KANG', 12, '5 ROOM'
6
+
7
+ town_list = ['ANG MO KIO', 'BEDOK', 'BISHAN', 'BUKIT BATOK', 'BUKIT MERAH', 'BUKIT PANJANG', 'BUKIT TIMAH', 'CENTRAL AREA', 'CHOA CHU KANG', 'CLEMENTI', 'GEYLANG', 'HOUGANG', 'JURONG EAST', 'JURONG WEST', 'KALLANG/WHAMPOA', 'MARINE PARADE', 'PASIR RIS', 'PUNGGOL', 'QUEENSTOWN', 'SEMBAWANG', 'SENGKANG', 'SERANGOON', 'TAMPINES', 'TOA PAYOH', 'WOODLANDS', 'YISHUN']
8
+ room_list = ['1 ROOM', '2 ROOM', '3 ROOM', '4 ROOM', '5 ROOM', 'EXECUTIVE', 'MULTI-GENERATION']
9
+
10
+ iface = gr.Interface(
11
+ fn=main_fn,
12
+ inputs= [
13
+ gr.inputs.Number(default=680705, label='Postal Code'),
14
+ gr.inputs.Number(default=25, label='Years since lease commencement (TOP)'),
15
+ gr.inputs.Dropdown(choices=town_list, type="value", default=None, label='Town'),
16
+ gr.inputs.Number(default=11, label='Floor'),
17
+ gr.inputs.Dropdown(choices=room_list, type="value", default=None, label='Room')
18
+ ],
19
+ outputs= [
20
+ gr.outputs.Textbox(type="text", label='Predicted House Price ($)')
21
+ ]
22
+ )
23
+ iface.launch()
gender_v1_freezebert.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:da62d65566a82c6b846e56852812f384a5682978a573c0c9470aaaec71be1efa
3
+ size 438157232
main.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import requests
3
+ from misc import nearest_mrt
4
+ import pickle
5
+ import os
6
+ import pandas as pd
7
+
8
+ ###This is to create MRT names and MRT locations
9
+
10
+
11
+ def main_fn(Postal_,age_,town_,storey_,room_):
12
+ ##Input structure into model is##
13
+ filename = 'finalized_model.sav'
14
+
15
+ if os.path.exists("./finalized_model.sav"):
16
+ model = pickle.load(open(filename, 'rb'))
17
+ print('loaded model')
18
+ else:
19
+ print('failed loading model')
20
+
21
+ #extract feature names#
22
+ feature_names = model.feature_names
23
+ input = [0]*len(feature_names)
24
+ # print(feature_names)
25
+
26
+ #Set up mrt_list
27
+ mrt_name = []
28
+ mrt_loc = []
29
+ with open('data/mrt_list.json', 'r') as file:
30
+ for line in file:
31
+ item = json.loads(line)
32
+ mrt_name.append(item['MRT'])
33
+ loc = tuple([float(i) for i in item['location']])
34
+ mrt_loc.append(loc)
35
+
36
+ #Query for latitude and longitude
37
+
38
+ ##POSTAL
39
+ Postal_input = int(Postal_)
40
+ # Postal_input = 680705
41
+ input[feature_names.index('Postal')] = Postal_input
42
+
43
+ ##DISTANCE TO MRT
44
+ search_term = Postal_input
45
+ query_string='https://developers.onemap.sg/commonapi/search?searchVal={}&returnGeom=Y&getAddrDetails=Y&pageNum=1'.format(search_term)
46
+ resp = requests.get(query_string)
47
+ data = json.loads(resp.content)
48
+ print(query_string)
49
+ print(data)
50
+ chosen_result = data['results'][0]
51
+
52
+ #Calculate the distance to nearest MRT
53
+ distance_km, nearest_mr = nearest_mrt(chosen_result['LATITUDE'], chosen_result['LONGITUDE'], mrt_name, mrt_loc)
54
+ input[feature_names.index('distance_mrt')] = distance_km
55
+
56
+ ##STOREY
57
+ #Height is input, but then converted to the scale we used for iterating model
58
+ height_input = int(storey_)
59
+ # height_input = 51
60
+ Height = (height_input+2)//3
61
+ input[feature_names.index('storey_height')] = Height
62
+
63
+ ##TOWN
64
+ town_input = town_
65
+ # town_input = 'CHOA CHU KANG'
66
+ input[feature_names.index("town_"+town_input)] = 1
67
+
68
+ ##ROOM
69
+ room_input = room_
70
+ # room_input = '4 ROOM'
71
+ input[feature_names.index("flat_num_"+room_input)] = 1
72
+
73
+ ##AGE/ TRANSACTION YEAR [Current default to 2022]
74
+ age_input = int(age_)
75
+ # age_input = 30
76
+ input[feature_names.index('age_transation')] = age_input
77
+ input[feature_names.index('transaction_yr')] = 2022 #Default to 2022 first
78
+
79
+ #Create final_dataframe as input to model
80
+
81
+ Actual = dict(zip(feature_names,input))
82
+ Actual_df = pd.DataFrame(Actual, index=[0])
83
+
84
+ resale_adj_price = model.predict(Actual_df)[0]
85
+
86
+ #New resale index is set arbitrarily as 170
87
+ resale_index = 170
88
+ price = resale_adj_price*resale_index/133.9
89
+ print(Actual_df)
90
+
91
+ return int(price)
92
+
93
+ if __name__ == "__main__":
94
+ Postal_,age_,town_,storey_,room_ = 680705, 30, 'CHOA CHU KANG', 12, '5 ROOM'
95
+ price = main_fn(Postal_,age_,town_,storey_,room_)
96
+ print(price)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ geopy
2
+ scikit-learn==1.0.2