RMHalak commited on
Commit
1523bf0
·
verified ·
1 Parent(s): e704f1e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -243
app.py CHANGED
@@ -4,6 +4,20 @@ import pickle
4
  import json
5
  from utils import create_new_features, normalize, bucketize, init_new_pred
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  with open('./trained_model.pkl', 'rb') as file:
8
  model = pickle.load(file)
9
  with open("./min_dict.json", "r") as f:
@@ -13,29 +27,28 @@ with open("./max_dict.json", "r") as f:
13
  with open("./cities_geo.json", "r") as f:
14
  cities_geo = json.load(f)
15
 
16
- st.set_page_config(layout="wide")
17
-
18
  # Create two columns: one for the city and one for the map
19
  col1, col2 = st.columns([1, 2]) # Adjust the width ratios as needed
20
 
21
  with col1:
22
  st.subheader('Features')
23
-
24
- # Display city dropdown in the first column
25
- city = st.selectbox(
26
- 'Select City',
27
- ['Algona', 'Auburn', 'Beaux Arts Village', 'Bellevue',
28
- 'Black Diamond', 'Bothell', 'Burien', 'Carnation', 'Clyde Hill',
29
- 'Covington', 'Des Moines', 'Duvall', 'Enumclaw', 'Fall City',
30
- 'Federal Way', 'Inglewood-Finn Hill', 'Issaquah', 'Kenmore',
31
- 'Kent', 'Kirkland', 'Lake Forest Park', 'Maple Valley', 'Medina',
32
- 'Mercer Island', 'Milton', 'Newcastle', 'Normandy Park',
33
- 'North Bend', 'Pacific', 'Preston', 'Ravensdale', 'Redmond',
34
- 'Renton', 'Sammamish', 'SeaTac', 'Seattle', 'Shoreline',
35
- 'Skykomish', 'Snoqualmie', 'Snoqualmie Pass', 'Tukwila', 'Vashon',
36
- 'Woodinville', 'Yarrow Point'],
37
- )
38
- waterfront = st.checkbox('Waterfront', value=False)
 
39
  bedrooms = st.slider('Bedrooms', min_value=min_dict['bedrooms'], max_value=max_dict['bedrooms'], value=3)
40
  bathrooms = st.slider('Bathrooms', min_value=min_dict['bathrooms'], max_value=max_dict['bathrooms'], value=2)
41
  sqft_living = st.slider('Square Feet (Living)', min_value=min_dict['sqft_living'], max_value=max_dict['sqft_living'], value=1000)
@@ -47,6 +60,8 @@ with col1:
47
  sqft_basement = st.slider('Square Feet (Basement)', min_value=min_dict['sqft_basement'], max_value=max_dict['sqft_basement'], value=0)
48
  yr_built = st.slider('Year Built', min_value=min_dict['yr_built'], max_value=max_dict['yr_built'], value=2000)
49
  yr_renovated = st.slider('Year Renovated', min_value=min_dict['yr_renovated'], max_value=max_dict['yr_renovated'], value=2010)
 
 
50
 
51
  new_pred = init_new_pred()
52
  new_pred['bedrooms'] = bedrooms
@@ -78,230 +93,7 @@ with col2:
78
  price_placeholder = st.empty()
79
  price_placeholder.markdown(
80
  f"<h1 style='font-size: 24px;'>Predicted Price: ${predicted_price[0][0]:,.2f}</h1>",
81
- unsafe_allow_html=True
82
- )
83
 
84
  map_data = pd.DataFrame(cities_geo[city])
85
-
86
- # if city == 'Seattle':
87
- # map_data = pd.DataFrame({
88
- # 'latitude': [47.6097, 47.6205, 47.6762],
89
- # 'longitude': [-122.3331, -122.3493, -122.3198]
90
- # })
91
- # elif city == 'Bellevue':
92
- # map_data = pd.DataFrame({
93
- # 'latitude': [47.6101, 47.6183],
94
- # 'longitude': [-122.2015, -122.2046]
95
- # })
96
- # elif city == 'Algona':
97
- # map_data = pd.DataFrame({
98
- # 'latitude': [47.3162],
99
- # 'longitude': [-122.2295]
100
- # })
101
- # elif city == 'Auburn':
102
- # map_data = pd.DataFrame({
103
- # 'latitude': [47.3073],
104
- # 'longitude': [-122.2284]
105
- # })
106
- # elif city == 'Beaux Arts Village':
107
- # map_data = pd.DataFrame({
108
- # 'latitude': [47.6141],
109
- # 'longitude': [-122.2125]
110
- # })
111
- # elif city == 'Black Diamond':
112
- # map_data = pd.DataFrame({
113
- # 'latitude': [47.3465],
114
- # 'longitude': [-121.9877]
115
- # })
116
- # elif city == 'Bothell':
117
- # map_data = pd.DataFrame({
118
- # 'latitude': [47.7595],
119
- # 'longitude': [-122.2056]
120
- # })
121
- # elif city == 'Burien':
122
- # map_data = pd.DataFrame({
123
- # 'latitude': [47.4702],
124
- # 'longitude': [-122.3359]
125
- # })
126
- # elif city == 'Carnation':
127
- # map_data = pd.DataFrame({
128
- # 'latitude': [47.6460],
129
- # 'longitude': [-121.9758]
130
- # })
131
- # elif city == 'Clyde Hill':
132
- # map_data = pd.DataFrame({
133
- # 'latitude': [47.6330],
134
- # 'longitude': [-122.2107]
135
- # })
136
- # elif city == 'Covington':
137
- # map_data = pd.DataFrame({
138
- # 'latitude': [47.3765],
139
- # 'longitude': [-122.0288]
140
- # })
141
- # elif city == 'Des Moines':
142
- # map_data = pd.DataFrame({
143
- # 'latitude': [47.3840],
144
- # 'longitude': [-122.3061]
145
- # })
146
- # elif city == 'Duvall':
147
- # map_data = pd.DataFrame({
148
- # 'latitude': [47.7332],
149
- # 'longitude': [-121.9916]
150
- # })
151
- # elif city == 'Enumclaw':
152
- # map_data = pd.DataFrame({
153
- # 'latitude': [47.2059],
154
- # 'longitude': [-121.9876]
155
- # })
156
- # elif city == 'Fall City':
157
- # map_data = pd.DataFrame({
158
- # 'latitude': [47.5980],
159
- # 'longitude': [-121.8896]
160
- # })
161
- # elif city == 'Federal Way':
162
- # map_data = pd.DataFrame({
163
- # 'latitude': [47.3220],
164
- # 'longitude': [-122.3126]
165
- # })
166
- # elif city == 'Inglewood-Finn Hill':
167
- # map_data = pd.DataFrame({
168
- # 'latitude': [47.7338],
169
- # 'longitude': [-122.2780]
170
- # })
171
- # elif city == 'Issaquah':
172
- # map_data = pd.DataFrame({
173
- # 'latitude': [47.5410],
174
- # 'longitude': [-122.0311]
175
- # })
176
- # elif city == 'Kenmore':
177
- # map_data = pd.DataFrame({
178
- # 'latitude': [47.7557],
179
- # 'longitude': [-122.2416]
180
- # })
181
- # elif city == 'Kent':
182
- # map_data = pd.DataFrame({
183
- # 'latitude': [47.3809],
184
- # 'longitude': [-122.2348]
185
- # })
186
- # elif city == 'Kirkland':
187
- # map_data = pd.DataFrame({
188
- # 'latitude': [47.6810],
189
- # 'longitude': [-122.2087]
190
- # })
191
- # elif city == 'Lake Forest Park':
192
- # map_data = pd.DataFrame({
193
- # 'latitude': [47.7318],
194
- # 'longitude': [-122.2764]
195
- # })
196
- # elif city == 'Maple Valley':
197
- # map_data = pd.DataFrame({
198
- # 'latitude': [47.3610],
199
- # 'longitude': [-122.0240]
200
- # })
201
- # elif city == 'Medina':
202
- # map_data = pd.DataFrame({
203
- # 'latitude': [47.6357],
204
- # 'longitude': [-122.2169]
205
- # })
206
- # elif city == 'Mercer Island':
207
- # map_data = pd.DataFrame({
208
- # 'latitude': [47.5703],
209
- # 'longitude': [-122.2264]
210
- # })
211
- # elif city == 'Milton':
212
- # map_data = pd.DataFrame({
213
- # 'latitude': [47.2335],
214
- # 'longitude': [-122.2730]
215
- # })
216
- # elif city == 'Newcastle':
217
- # map_data = pd.DataFrame({
218
- # 'latitude': [47.5477],
219
- # 'longitude': [-122.1711]
220
- # })
221
- # elif city == 'Normandy Park':
222
- # map_data = pd.DataFrame({
223
- # 'latitude': [47.4051],
224
- # 'longitude': [-122.3376]
225
- # })
226
- # elif city == 'North Bend':
227
- # map_data = pd.DataFrame({
228
- # 'latitude': [47.4904],
229
- # 'longitude': [-121.7852]
230
- # })
231
- # elif city == 'Pacific':
232
- # map_data = pd.DataFrame({
233
- # 'latitude': [47.3197],
234
- # 'longitude': [-122.2786]
235
- # })
236
- # elif city == 'Preston':
237
- # map_data = pd.DataFrame({
238
- # 'latitude': [47.5420],
239
- # 'longitude': [-121.9214]
240
- # })
241
- # elif city == 'Ravensdale':
242
- # map_data = pd.DataFrame({
243
- # 'latitude': [47.3485],
244
- # 'longitude': [-121.9807]
245
- # })
246
- # elif city == 'Redmond':
247
- # map_data = pd.DataFrame({
248
- # 'latitude': [47.6734],
249
- # 'longitude': [-122.1215]
250
- # })
251
- # elif city == 'Renton':
252
- # map_data = pd.DataFrame({
253
- # 'latitude': [47.4829],
254
- # 'longitude': [-122.2170]
255
- # })
256
- # elif city == 'Sammamish':
257
- # map_data = pd.DataFrame({
258
- # 'latitude': [47.6162],
259
- # 'longitude': [-122.0394]
260
- # })
261
- # elif city == 'SeaTac':
262
- # map_data = pd.DataFrame({
263
- # 'latitude': [47.4484],
264
- # 'longitude': [-122.3085]
265
- # })
266
- # elif city == 'Shoreline':
267
- # map_data = pd.DataFrame({
268
- # 'latitude': [47.7554],
269
- # 'longitude': [-122.3410]
270
- # })
271
- # elif city == 'Skykomish':
272
- # map_data = pd.DataFrame({
273
- # 'latitude': [47.7054],
274
- # 'longitude': [-121.4848]
275
- # })
276
- # elif city == 'Snoqualmie':
277
- # map_data = pd.DataFrame({
278
- # 'latitude': [47.5410],
279
- # 'longitude': [-121.8340]
280
- # })
281
- # elif city == 'Snoqualmie Pass':
282
- # map_data = pd.DataFrame({
283
- # 'latitude': [47.4286],
284
- # 'longitude': [-121.4420]
285
- # })
286
- # elif city == 'Tukwila':
287
- # map_data = pd.DataFrame({
288
- # 'latitude': [47.4835],
289
- # 'longitude': [-122.2585]
290
- # })
291
- # elif city == 'Vashon':
292
- # map_data = pd.DataFrame({
293
- # 'latitude': [47.4337],
294
- # 'longitude': [-122.4660]
295
- # })
296
- # elif city == 'Woodinville':
297
- # map_data = pd.DataFrame({
298
- # 'latitude': [47.7524],
299
- # 'longitude': [-122.1576]
300
- # })
301
- # elif city == 'Yarrow Point':
302
- # map_data = pd.DataFrame({
303
- # 'latitude': [47.6348],
304
- # 'longitude': [-122.2218]
305
- # })
306
-
307
- st.map(map_data, zoom=11)
 
4
  import json
5
  from utils import create_new_features, normalize, bucketize, init_new_pred
6
 
7
+ st.set_page_config(layout="wide")
8
+
9
+ st.markdown("""
10
+ <style>
11
+ .scroll-container {
12
+ height: 500px; /* Set the height of the scrollable section */
13
+ overflow-y: scroll;
14
+ padding: 10px;
15
+ border: 1px solid #ccc; /* Optional: Add border to make the scrollable area more visible */
16
+ }
17
+ </style>
18
+ """, unsafe_allow_html=True)
19
+
20
+ # load model and files
21
  with open('./trained_model.pkl', 'rb') as file:
22
  model = pickle.load(file)
23
  with open("./min_dict.json", "r") as f:
 
27
  with open("./cities_geo.json", "r") as f:
28
  cities_geo = json.load(f)
29
 
 
 
30
  # Create two columns: one for the city and one for the map
31
  col1, col2 = st.columns([1, 2]) # Adjust the width ratios as needed
32
 
33
  with col1:
34
  st.subheader('Features')
35
+
36
+ with st.container():
37
+ st.markdown('<div class="scroll-container">', unsafe_allow_html=True)
38
+
39
+ # Create two columns for City and Waterfront
40
+ col3, col4 = st.columns(2)
41
+
42
+ # City dropdown in the first column
43
+ with col3:
44
+ city = st.selectbox('City', list(cities_geo.keys()))
45
+
46
+ # Waterfront checkbox in the second column
47
+ with col4:
48
+ waterfront = st.checkbox('Waterfront', value=False)
49
+
50
+ # city = st.selectbox('City', list(cities_geo.keys())) # Display city dropdown in the first column
51
+ # waterfront = st.checkbox('Waterfront', value=False)
52
  bedrooms = st.slider('Bedrooms', min_value=min_dict['bedrooms'], max_value=max_dict['bedrooms'], value=3)
53
  bathrooms = st.slider('Bathrooms', min_value=min_dict['bathrooms'], max_value=max_dict['bathrooms'], value=2)
54
  sqft_living = st.slider('Square Feet (Living)', min_value=min_dict['sqft_living'], max_value=max_dict['sqft_living'], value=1000)
 
60
  sqft_basement = st.slider('Square Feet (Basement)', min_value=min_dict['sqft_basement'], max_value=max_dict['sqft_basement'], value=0)
61
  yr_built = st.slider('Year Built', min_value=min_dict['yr_built'], max_value=max_dict['yr_built'], value=2000)
62
  yr_renovated = st.slider('Year Renovated', min_value=min_dict['yr_renovated'], max_value=max_dict['yr_renovated'], value=2010)
63
+
64
+ st.markdown('</div>', unsafe_allow_html=True)
65
 
66
  new_pred = init_new_pred()
67
  new_pred['bedrooms'] = bedrooms
 
93
  price_placeholder = st.empty()
94
  price_placeholder.markdown(
95
  f"<h1 style='font-size: 24px;'>Predicted Price: ${predicted_price[0][0]:,.2f}</h1>",
96
+ unsafe_allow_html=True)
 
97
 
98
  map_data = pd.DataFrame(cities_geo[city])
99
+ st.map(map_data, zoom=11)