Spaces:
Sleeping
Sleeping
Commit
·
daeeec9
1
Parent(s):
6f34772
commit 2
Browse files
app.py
CHANGED
@@ -147,28 +147,37 @@ locations = {
|
|
147 |
"Bachenbülach": 51,
|
148 |
"Horgen": 295
|
149 |
}
|
150 |
-
def predict_apartment(rooms, area, town):
|
151 |
bfs_number = locations[town]
|
152 |
df = df_bfs_data[df_bfs_data['bfs_number']==bfs_number].copy()
|
153 |
df.reset_index(inplace=True)
|
154 |
df.loc[0, 'rooms'] = rooms
|
155 |
df.loc[0, 'area'] = area
|
156 |
-
df.loc[0, 'proximity_to_public_transportation'] =
|
157 |
|
158 |
if len(df) != 1:
|
159 |
return -1
|
160 |
|
161 |
features = ['rooms', 'area', 'pop', 'pop_dens', 'frg_pct', 'emp', 'tax_income', 'proximity_to_public_transportation']
|
162 |
-
X = df[features].values
|
163 |
prediction = random_forest_model.predict(X)
|
164 |
return np.round(prediction[0], 0)
|
165 |
|
166 |
# Create the Gradio interface
|
167 |
iface = gr.Interface(
|
168 |
fn=predict_apartment,
|
169 |
-
inputs=[
|
170 |
-
|
171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
)
|
173 |
-
|
174 |
iface.launch()
|
|
|
147 |
"Bachenbülach": 51,
|
148 |
"Horgen": 295
|
149 |
}
|
150 |
+
def predict_apartment(rooms, area, proximity, town):
|
151 |
bfs_number = locations[town]
|
152 |
df = df_bfs_data[df_bfs_data['bfs_number']==bfs_number].copy()
|
153 |
df.reset_index(inplace=True)
|
154 |
df.loc[0, 'rooms'] = rooms
|
155 |
df.loc[0, 'area'] = area
|
156 |
+
df.loc[0, 'proximity_to_public_transportation'] = proximity # Use user input instead of default
|
157 |
|
158 |
if len(df) != 1:
|
159 |
return -1
|
160 |
|
161 |
features = ['rooms', 'area', 'pop', 'pop_dens', 'frg_pct', 'emp', 'tax_income', 'proximity_to_public_transportation']
|
162 |
+
X = df[features].values
|
163 |
prediction = random_forest_model.predict(X)
|
164 |
return np.round(prediction[0], 0)
|
165 |
|
166 |
# Create the Gradio interface
|
167 |
iface = gr.Interface(
|
168 |
fn=predict_apartment,
|
169 |
+
inputs=[
|
170 |
+
gr.Number(label="Number of Rooms"),
|
171 |
+
gr.Number(label="Area (m²)"),
|
172 |
+
gr.Slider(minimum=0, maximum=2000, value=500, step=50,
|
173 |
+
label="Distance to Public Transportation (meters)"),
|
174 |
+
gr.Dropdown(choices=locations.keys(), label="Town", type="value")
|
175 |
+
],
|
176 |
+
outputs=[gr.Number(label="Predicted Price (CHF)")],
|
177 |
+
examples=[
|
178 |
+
[4.5, 120, 500, "Dietlikon"],
|
179 |
+
[3.5, 60, 250, "Winterthur"]
|
180 |
+
],
|
181 |
+
description="Predict apartment prices in Zürich based on rooms, area, proximity to public transportation, and location."
|
182 |
)
|
|
|
183 |
iface.launch()
|