File size: 11,204 Bytes
fd7e04e
9ae8083
6676090
842df92
fd7e04e
5250b05
08625ae
fd7e04e
5a66be2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86120d5
 
5a66be2
86120d5
 
46440c4
b042d9f
86120d5
 
 
 
 
 
 
 
 
 
 
0a6e3ff
86120d5
35cf0ae
86120d5
 
 
 
 
 
 
 
 
 
 
 
8f827eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86120d5
 
 
46440c4
5add387
 
 
 
46440c4
 
 
 
 
 
8f827eb
46440c4
 
8f827eb
 
 
46440c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8f827eb
46440c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8f827eb
46440c4
 
7affa2b
46440c4
 
7affa2b
 
 
 
 
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
import streamlit as st
import pandas as pd
import pickle
from utils import create_new_features, normalize, init_new_pred

with open('./trained_model.pkl', 'rb') as file:
    model = pickle.load(file)

# Define min and max values from the dictionaries
min_dict = {
    'bedrooms': 0,
    'bathrooms': 0,
    'sqft_living': 370,
    'sqft_lot': 638,
    'floors': 1,
    'waterfront': 0,
    'view': 0,
    'condition': 1,
    'sqft_above': 370,
    'sqft_basement': 0,
    'yr_built': 1900,
    'yr_renovated': 0,
    'house_age': 0,
    'years_since_renovation': 0
}

max_dict = {
    'bedrooms': 9,
    'bathrooms': 8,
    'sqft_living': 13540,
    'sqft_lot': 1074218,
    'floors': 3,
    'waterfront': 1,
    'view': 4,
    'condition': 5,
    'sqft_above': 9410,
    'sqft_basement': 4820,
    'yr_built': 2014,
    'yr_renovated': 2014,
    'house_age': 114,
    'years_since_renovation': 2014
}

# Create two columns: one for the city and one for the map
col1, col2 = st.columns([1, 2])  # Adjust the width ratios as needed

# Display city dropdown in the first column
with col1:
    st.subheader('Features')
    
    city = st.selectbox(
        'Select City', 
        ['Algona', 'Auburn', 'Beaux Arts Village', 'Bellevue',
         'Black Diamond', 'Bothell', 'Burien', 'Carnation', 'Clyde Hill',
         'Covington', 'Des Moines', 'Duvall', 'Enumclaw', 'Fall City',
         'Federal Way', 'Inglewood-Finn Hill', 'Issaquah', 'Kenmore',
         'Kent', 'Kirkland', 'Lake Forest Park', 'Maple Valley', 'Medina',
         'Mercer Island', 'Milton', 'Newcastle', 'Normandy Park',
         'North Bend', 'Pacific', 'Preston', 'Ravensdale', 'Redmond',
         'Renton', 'Sammamish', 'SeaTac', 'Seattle', 'Shoreline',
         'Skykomish', 'Snoqualmie', 'Snoqualmie Pass', 'Tukwila', 'Vashon',
         'Woodinville', 'Yarrow Point'],
    )
    waterfront = st.checkbox('Waterfront', value=False)
    bedrooms = st.slider('Bedrooms', min_value=min_dict['bedrooms'], max_value=max_dict['bedrooms'], value=min_dict['bedrooms'])
    bathrooms = st.slider('Bathrooms', min_value=min_dict['bathrooms'], max_value=max_dict['bathrooms'], value=min_dict['bathrooms'])
    sqft_living = st.slider('Square Feet (Living)', min_value=min_dict['sqft_living'], max_value=max_dict['sqft_living'], value=min_dict['sqft_living'])
    sqft_lot = st.slider('Square Feet (Lot)', min_value=min_dict['sqft_lot'], max_value=max_dict['sqft_lot'], value=min_dict['sqft_lot'])
    floors = st.slider('Floors', min_value=min_dict['floors'], max_value=max_dict['floors'], value=min_dict['floors'])
    view = st.slider('View', min_value=min_dict['view'], max_value=max_dict['view'], value=min_dict['view'])
    condition = st.slider('Condition', min_value=min_dict['condition'], max_value=max_dict['condition'], value=min_dict['condition'])
    sqft_above = st.slider('Square Feet (Above)', min_value=min_dict['sqft_above'], max_value=max_dict['sqft_above'], value=min_dict['sqft_above'])
    sqft_basement = st.slider('Square Feet (Basement)', min_value=min_dict['sqft_basement'], max_value=max_dict['sqft_basement'], value=min_dict['sqft_basement'])
    yr_built = st.slider('Year Built', min_value=min_dict['yr_built'], max_value=max_dict['yr_built'], value=min_dict['yr_built'])
    yr_renovated = st.slider('Year Renovated', min_value=min_dict['yr_renovated'], max_value=max_dict['yr_renovated'], value=min_dict['yr_renovated'])
        
    new_pred = init_new_pred()
    new_pred['bedrooms'] = bedrooms
    new_pred['bathrooms'] = bathrooms
    new_pred['sqft_living'] = sqft_living
    new_pred['sqft_lot'] = sqft_lot
    new_pred['floors'] = floors
    new_pred['waterfront'] = int(waterfront)
    new_pred['view'] = view
    new_pred['condition'] = condition
    new_pred['sqft_above'] = sqft_above
    new_pred['sqft_basement'] = sqft_basement
    new_pred['yr_built'] = yr_built
    new_pred['yr_renovated'] = yr_renovated
    new_pred[f'city_{city}'] = 1

    # Process the prediction
    new_pred = pd.DataFrame([new_pred])
    new_pred = create_new_features(new_pred)
    new_pred = normalize(new_pred)

    # Predict the price
    predicted_price = model.predict(new_pred)

# Display the map in the second column
with col2:
    st.subheader('Map')
    if city == 'Seattle':
        map_data = pd.DataFrame({
            'latitude': [47.6097, 47.6205, 47.6762],
            'longitude': [-122.3331, -122.3493, -122.3198]
        })
    elif city == 'Bellevue':
        map_data = pd.DataFrame({
            'latitude': [47.6101, 47.6183],
            'longitude': [-122.2015, -122.2046]
        })
    elif city == 'Algona':
        map_data = pd.DataFrame({
            'latitude': [47.3162],
            'longitude': [-122.2295]
        })
    elif city == 'Auburn':
        map_data = pd.DataFrame({
            'latitude': [47.3073],
            'longitude': [-122.2284]
        })
    elif city == 'Beaux Arts Village':
        map_data = pd.DataFrame({
            'latitude': [47.6141],
            'longitude': [-122.2125]
        })
    elif city == 'Black Diamond':
        map_data = pd.DataFrame({
            'latitude': [47.3465],
            'longitude': [-121.9877]
        })
    elif city == 'Bothell':
        map_data = pd.DataFrame({
            'latitude': [47.7595],
            'longitude': [-122.2056]
        })
    elif city == 'Burien':
        map_data = pd.DataFrame({
            'latitude': [47.4702],
            'longitude': [-122.3359]
        })
    elif city == 'Carnation':
        map_data = pd.DataFrame({
            'latitude': [47.6460],
            'longitude': [-121.9758]
        })
    elif city == 'Clyde Hill':
        map_data = pd.DataFrame({
            'latitude': [47.6330],
            'longitude': [-122.2107]
        })
    elif city == 'Covington':
        map_data = pd.DataFrame({
            'latitude': [47.3765],
            'longitude': [-122.0288]
        })
    elif city == 'Des Moines':
        map_data = pd.DataFrame({
            'latitude': [47.3840],
            'longitude': [-122.3061]
        })
    elif city == 'Duvall':
        map_data = pd.DataFrame({
            'latitude': [47.7332],
            'longitude': [-121.9916]
        })
    elif city == 'Enumclaw':
        map_data = pd.DataFrame({
            'latitude': [47.2059],
            'longitude': [-121.9876]
        })
    elif city == 'Fall City':
        map_data = pd.DataFrame({
            'latitude': [47.5980],
            'longitude': [-121.8896]
        })
    elif city == 'Federal Way':
        map_data = pd.DataFrame({
            'latitude': [47.3220],
            'longitude': [-122.3126]
        })
    elif city == 'Inglewood-Finn Hill':
        map_data = pd.DataFrame({
            'latitude': [47.7338],
            'longitude': [-122.2780]
        })
    elif city == 'Issaquah':
        map_data = pd.DataFrame({
            'latitude': [47.5410],
            'longitude': [-122.0311]
        })
    elif city == 'Kenmore':
        map_data = pd.DataFrame({
            'latitude': [47.7557],
            'longitude': [-122.2416]
        })
    elif city == 'Kent':
        map_data = pd.DataFrame({
            'latitude': [47.3809],
            'longitude': [-122.2348]
        })
    elif city == 'Kirkland':
        map_data = pd.DataFrame({
            'latitude': [47.6810],
            'longitude': [-122.2087]
        })
    elif city == 'Lake Forest Park':
        map_data = pd.DataFrame({
            'latitude': [47.7318],
            'longitude': [-122.2764]
        })
    elif city == 'Maple Valley':
        map_data = pd.DataFrame({
            'latitude': [47.3610],
            'longitude': [-122.0240]
        })
    elif city == 'Medina':
        map_data = pd.DataFrame({
            'latitude': [47.6357],
            'longitude': [-122.2169]
        })
    elif city == 'Mercer Island':
        map_data = pd.DataFrame({
            'latitude': [47.5703],
            'longitude': [-122.2264]
        })
    elif city == 'Milton':
        map_data = pd.DataFrame({
            'latitude': [47.2335],
            'longitude': [-122.2730]
        })
    elif city == 'Newcastle':
        map_data = pd.DataFrame({
            'latitude': [47.5477],
            'longitude': [-122.1711]
        })
    elif city == 'Normandy Park':
        map_data = pd.DataFrame({
            'latitude': [47.4051],
            'longitude': [-122.3376]
        })
    elif city == 'North Bend':
        map_data = pd.DataFrame({
            'latitude': [47.4904],
            'longitude': [-121.7852]
        })
    elif city == 'Pacific':
        map_data = pd.DataFrame({
            'latitude': [47.3197],
            'longitude': [-122.2786]
        })
    elif city == 'Preston':
        map_data = pd.DataFrame({
            'latitude': [47.5420],
            'longitude': [-121.9214]
        })
    elif city == 'Ravensdale':
        map_data = pd.DataFrame({
            'latitude': [47.3485],
            'longitude': [-121.9807]
        })
    elif city == 'Redmond':
        map_data = pd.DataFrame({
            'latitude': [47.6734],
            'longitude': [-122.1215]
        })
    elif city == 'Renton':
        map_data = pd.DataFrame({
            'latitude': [47.4829],
            'longitude': [-122.2170]
        })
    elif city == 'Sammamish':
        map_data = pd.DataFrame({
            'latitude': [47.6162],
            'longitude': [-122.0394]
        })
    elif city == 'SeaTac':
        map_data = pd.DataFrame({
            'latitude': [47.4484],
            'longitude': [-122.3085]
        })
    elif city == 'Shoreline':
        map_data = pd.DataFrame({
            'latitude': [47.7554],
            'longitude': [-122.3410]
        })
    elif city == 'Skykomish':
        map_data = pd.DataFrame({
            'latitude': [47.7054],
            'longitude': [-121.4848]
        })
    elif city == 'Snoqualmie':
        map_data = pd.DataFrame({
            'latitude': [47.5410],
            'longitude': [-121.8340]
        })
    elif city == 'Snoqualmie Pass':
        map_data = pd.DataFrame({
            'latitude': [47.4286],
            'longitude': [-121.4420]
        })
    elif city == 'Tukwila':
        map_data = pd.DataFrame({
            'latitude': [47.4835],
            'longitude': [-122.2585]
        })
    elif city == 'Vashon':
        map_data = pd.DataFrame({
            'latitude': [47.4337],
            'longitude': [-122.4660]
        })
    elif city == 'Woodinville':
        map_data = pd.DataFrame({
            'latitude': [47.7524],
            'longitude': [-122.1576]
        })
    elif city == 'Yarrow Point':
        map_data = pd.DataFrame({
            'latitude': [47.6348],
            'longitude': [-122.2218]
        })

    st.map(map_data)
    
    # Placeholder for displaying the predicted price at the top
    price_placeholder = st.empty()

    # Display the predicted price at the top of the app
    # price_placeholder.write(f"Predicted Price: ${predicted_price[0][0]:,.2f}")
    price_placeholder.markdown(
        f"<h1 style='font-size: 24px;'>Predicted Price: ${predicted_price[0][0]:,.2f}</h1>",
        unsafe_allow_html=True
    )