File size: 5,647 Bytes
fd7e04e
9ae8083
6676090
7c90a6c
13bce48
f00ad3a
fd7e04e
1523bf0
 
a651923
5250b05
08625ae
cd9721e
 
 
 
1fedf0d
 
5a66be2
4d950ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2d4db89
9202d78
2d4db89
 
9202d78
e26c3f5
 
 
 
2d4db89
 
9202d78
2d4db89
86120d5
 
5a66be2
86120d5
45576df
d4d3bd5
651bbaf
a651923
 
4d950ec
 
 
 
 
 
 
 
 
 
 
a9b4435
 
d4d3bd5
f00ad3a
a9b4435
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f00ad3a
 
 
a9b4435
 
 
8f827eb
86120d5
fe351a4
 
923de78
be61306
651bbaf
06fbd01
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
import streamlit as st
import pandas as pd
import pickle
import json
import pydeck as pdk
import utils

st.set_page_config(layout="wide")

# Load model and files
with open('./trained_model.pkl', 'rb') as file:
    model = pickle.load(file)
with open("./min_dict.json", "r") as f:
    min_dict = json.load(f)
with open("./max_dict.json", "r") as f:
    max_dict = json.load(f)
with open("./cities_geo.json", "r") as f:
    cities_geo = json.load(f)

help_dict = {
    'bedrooms': "Select the number of bedrooms in the house. The value ranges from the minimum to the maximum available in the dataset.",
    'bathrooms': "Select the number of bathrooms in the house. The value ranges from the minimum to the maximum available in the dataset.",
    'yr_built': "Select the year the house was built. The value ranges from the earliest to the latest year available in the dataset.",
    'yr_renovated': "Select the year the house was renovated. This value cannot be earlier than the year the house was built and ranges up to the maximum renovation year in the dataset.",
    'floors': "Select the number of floors in the house. The value ranges from the minimum to the maximum number of floors available in the dataset.",
    'view': "Select the quality of the view from the house. The value ranges from 0 (no view) to the highest view quality available in the dataset.",
    'condition': "Select the overall condition of the house. The value ranges from the poorest to the best condition available in the dataset.",
    'sqft_living': "Select the total square footage of the living space. The value ranges from the minimum to the maximum square footage available in the dataset.",
    'sqft_lot': "Select the total square footage of the lot. The value ranges from the minimum to the maximum lot size available in the dataset.",
    'sqft_above': "Select the square footage of the living space above ground level. The value ranges from the minimum to the maximum above-ground square footage available in the dataset.",
    'sqft_basement': "Select the square footage of the basement. The value ranges from the minimum to the maximum basement square footage available in the dataset."
}


# Custom CSS to adjust the slider width

st.markdown("""
    <style>
    .stSlider [data-baseweb=slider]{
        width: 95%;
    }
    .stCheckbox, .stSelectbox {
        width: 95%px; 
    }
    </style>
    """,unsafe_allow_html=True)

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

with col1:
    st.subheader('Features')
    
    with st.container(height=550, border=True):
        city = st.selectbox('City', list(cities_geo.keys()))  # Display city dropdown in the first column
        waterfront = st.checkbox('Waterfront', value=False)
        bedrooms = st.slider('Bedrooms', min_value=min_dict['bedrooms'], max_value=max_dict['bedrooms'], value=3, help=help_dict['bedrooms'])
        bathrooms = st.slider('Bathrooms', min_value=min_dict['bathrooms'], max_value=max_dict['bathrooms'], value=2, help=help_dict['bathrooms'])
        yr_built = st.slider('Year Built', min_value=min_dict['yr_built'], max_value=max_dict['yr_built'], value=2000, help=help_dict['yr_built'])
        yr_renovated = st.slider('Year Renovated', min_value=yr_built, max_value=max_dict['yr_renovated'], value=yr_built, help=help_dict['yr_renovated'])
        floors = st.slider('Floors', min_value=min_dict['floors'], max_value=max_dict['floors'], value=1, help=help_dict['floors'])
        view = st.slider('View', min_value=min_dict['view'], max_value=max_dict['view'], value=0, help=help_dict['view'])
        condition = st.slider('Condition', min_value=min_dict['condition'], max_value=max_dict['condition'], value=3, help=help_dict['condition'])
        sqft_living = st.slider('Square Feet (Living)', min_value=min_dict['sqft_living'], max_value=max_dict['sqft_living'], value=1000, help=help_dict['sqft_living'])
        sqft_lot = st.slider('Square Feet (Lot)', min_value=min_dict['sqft_lot'], max_value=max_dict['sqft_lot'], value=2000, help=help_dict['sqft_lot'])
        sqft_above = st.slider('Square Feet (Above)', min_value=min_dict['sqft_above'], max_value=max_dict['sqft_above'], value=1000, help=help_dict['sqft_above'])
        sqft_basement = st.slider('Square Feet (Basement)', min_value=min_dict['sqft_basement'], max_value=max_dict['sqft_basement'], value=0, help=help_dict['sqft_basement'])

    st.markdown('</div>', unsafe_allow_html=True)
    
    new_pred = utils.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 = utils.create_new_features(new_pred)
    new_pred = utils.bucketize(new_pred)
    new_pred = utils.normalize(new_pred)

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

with col2:
    # Placeholder for displaying the predicted price at the top
    price_placeholder = st.empty()
    price_placeholder.subheader(f'Predicted Price: ${predicted_price[0][0]:,.2f}')
    map_data = pd.DataFrame(cities_geo[city])
    with st.container(height=550, border=True):
        st.map(map_data, zoom=11)