File size: 5,482 Bytes
fd7e04e
9ae8083
6676090
842df92
fd7e04e
5250b05
08625ae
fd7e04e
5a66be2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86120d5
 
 
5a66be2
86120d5
 
5a66be2
86120d5
 
 
 
b042d9f
86120d5
 
 
 
 
 
 
 
 
 
 
 
0a6e3ff
 
86120d5
a677df8
86120d5
 
 
 
 
 
0a6e3ff
86120d5
 
 
 
 
 
a677df8
0a6e3ff
 
86120d5
 
 
 
0a6e3ff
86120d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a677df8
86120d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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
}
    
# Display the predicted price at the top of the app
price_placeholder.write(f"Predicted Price: ${predicted_price[0][0]:,.2f}")

# 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:
    # Placeholder for displaying the predicted price at the top
    price_placeholder = st.empty()
    
    st.subheader('City Selection')
    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'],
         
    )

    # Create sliders for each item in the dictionaries
    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'])
    waterfront = st.checkbox('Waterfront', value=False, )
    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'])

    if (city != 'Algona' or # Assuming Algona as the default value
        bedrooms != min_dict['bedrooms'] or
        bathrooms != min_dict['bathrooms'] or
        sqft_living != min_dict['sqft_living'] or
        sqft_lot != min_dict['sqft_lot'] or
        floors != min_dict['floors'] or
        int(waterfront) != 0 or  # Assuming default value for waterfront is 0
        view != min_dict['view'] or
        condition != min_dict['condition'] or
        sqft_above != min_dict['sqft_above'] or
        sqft_basement != min_dict['sqft_basement'] or
        yr_built != min_dict['yr_built'] or
        yr_renovated != 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')
    data = pd.DataFrame({
        'latitude': [47.6097, 47.6205, 47.6762],  # Example latitudes
        'longitude': [-122.3331, -122.3493, -122.3198]  # Example longitudes
    })
    st.map(data)