sivakornchong commited on
Commit
d5050b9
1 Parent(s): aab7ecd
Files changed (4) hide show
  1. .gitignore +1 -0
  2. app.py +3 -8
  3. main.py +20 -88
  4. requirements.txt +2 -1
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ ./h5
app.py CHANGED
@@ -4,20 +4,15 @@ from main import main_fn
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()
 
4
  #Input structure
5
  ##Postal_,age_,town_,storey_,room_ = 680705, 30, 'CHOA CHU KANG', 12, '5 ROOM'
6
 
 
 
7
 
8
  iface = gr.Interface(
9
  fn=main_fn,
10
  inputs= [
11
+ gr.inputs.Textbox(type="text", label='Name'),
 
 
 
 
12
  ],
13
  outputs= [
14
+ gr.outputs.Textbox(type="text", label='Gender')
15
+ gr.outputs.Number(label = 'Percentage confidence')
16
  ]
17
  )
18
  iface.launch()
main.py CHANGED
@@ -1,96 +1,28 @@
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)
 
 
 
 
 
1
  import os
2
  import pandas as pd
3
+ import keras
4
+ ### This is to predict gender
5
 
6
+ def main_fn(Name_):
 
 
 
7
  ##Input structure into model is##
8
+ filename = "training_2/gender_v1_freezebert.h5"
9
+ if os.path.exists(filename):
10
+ model = tf.keras.models.load_model((filename), custom_objects={'KerasLayer':hub.KerasLayer})
11
+ print('loaded model')
 
12
  else:
13
  print('failed loading model')
14
 
15
+ prob = model.predict([Name_])
16
+ female_prob = prob[0][0]
17
+ if female_prob>0.5:
18
+ gender = 'female'
19
+ prob = female_prob
20
+ else:
21
+ gender = 'male'
22
+ prob = (1-female_prob)
23
+ return gender, prob
24
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  if __name__ == "__main__":
26
+ Name_ = 'John'
27
+ gender, female_prob = main_fn(Name_)
28
+ print(gender)
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
- geopy
 
2
  scikit-learn==1.0.2
 
1
+ keras
2
+ pandas
3
  scikit-learn==1.0.2