-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
161 lines (137 loc) · 4.84 KB
/
app.py
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
import streamlit as st
import pandas as pd
from predict.prediction import predict
from preprocessing.cleaning_data import preprocess
# Load the DataFrame from the file in the 'model' folder
df = pd.read_csv("model/features_data.csv")
# Page setup
st.set_page_config(
page_title="Real Estate Price Predictor",
page_icon="🏠",
layout="centered",
)
# Main page header
st.markdown(
"""
<h1 style="font-size: 2.5rem; text-align: center;">Real Estate Price Predictor</h1>
<p style="text-align: center;">Predict Belgian property prices based on locality and building characteristics</p>
""",
unsafe_allow_html=True,
)
# CSS for select box color
st.markdown(
"""
<style>
/* Apply custom text color to all sidebar elements */
section[data-testid="stSidebar"] .st-expander,
section[data-testid="stSidebar"] .st-expander-content,
section[data-testid="stSidebar"] {
color: #e7e1d2 !important;
}
/* Change the color of the collapse button when the sidebar is expanded */
section[data-testid="stSidebar"][aria-expanded="true"] [data-testid="stSidebarCollapseButton"] {
color: #e7e1d2 !important;
}
/* Change the color of the collapse button when the sidebar is collapsed */
section[data-testid="stSidebar"][aria-expanded="false"] [data-testid="stSidebarCollapseButton"] {
color: #000000 !important;
}
/* Change text color when the option is selected */
.st-bm.st-ak {
color: #e7e1d2 !important;
}
</style>
""",
unsafe_allow_html=True,
)
# Sidebar content with sections
with st.sidebar:
# About this App section
with st.expander("About this App"):
st.markdown(
"""
This app is designed to help users predict Belgian property prices by providing building characteristics and location information.
It uses a Random Forest Regression model trained on data collected from Immoweb, Belgium's largest real estate platform.
"""
)
# Instructions section
with st.expander("Instructions"):
st.markdown(
"""
1. **Select the locality and property features.**
Start by choosing the province and municipality where the property is located.
2. **Provide property details.**
Specify the living area (m²), the state of the building, and whether the kitchen is fully equipped.
3. **Click 'Predict Property Price.'**
The app will process your input and predict the property's price.
"""
)
# Header 2:
st.markdown(
"""
<h3 style="font-size: 1.8rem;">Select the desired property characteristics and locality</h3>
""",
unsafe_allow_html=True,
)
col1, col2 = st.columns(2)
# Column 1
with col1:
st.text("Locality")
# Unique provinces from the DataFrame
provinces = df["province"].unique()
province = st.selectbox("Select the province:", provinces)
# Filter municipalities based on the selected province
municipalities = df[df["province"] == province]["municipality"].unique()
municipality = st.selectbox("Select the municipality:", municipalities)
# Column 2
with col2:
st.text("Property characteristics")
livable_space = st.slider("Livable space (m²):", 10, 500, 20)
state = st.selectbox(
"State of the building:",
[
"Just renovated",
"As new",
"Good",
"To renovate",
"To be done up",
"To restore",
],
)
kitchen = st.selectbox("Fully equipped kitchen:", ["Yes", "No"])
if st.button("Predict Property Price"):
# Prepare user input for preprocessing
user_input = {
"living_area": livable_space,
"province": province,
"municipality": municipality,
"state": state,
"kitchen": kitchen,
}
# Apply the preprocessing function
preprocessed_input = preprocess(user_input)
# Extract preprocessed features for the prediction function
living_area = preprocessed_input["living_area"]
province = preprocessed_input["province"]
prosperity_index = preprocessed_input.get("prosperity_index", 0)
extra_investment = preprocessed_input.get("extra_investment", 0)
# Predict
result = predict(living_area, province, prosperity_index, extra_investment)
# Result message
st.markdown(
f"""
<div style="background-color:#ded1ff; padding:5px; border-radius:10px; margin-top:20px;">
<h4 style="color:#431f79; text-align:center;">Predicted property price: {result}</h4>
</div>
""",
unsafe_allow_html=True,
)
st.markdown("---")
st.markdown(
"""
**App developed by: Jess Rojas-Alvarado**\n
Connect with me: [GitHub](https://github.com/jessrojasal)
[BeCode](https://becode.org/) learning project\n
AI & Data Science Bootcamp
"""
)