Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +58 -30
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,68 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
| 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 |
-
st.
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import joblib
|
| 4 |
+
import os
|
| 5 |
|
| 6 |
+
# ======================
|
| 7 |
+
# LOAD MODEL
|
| 8 |
+
# ======================
|
| 9 |
+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 10 |
+
model = joblib.load(os.path.join(BASE_DIR, "house_price_model.pkl"))
|
| 11 |
|
| 12 |
+
# ======================
|
| 13 |
+
# PAGE CONFIG
|
| 14 |
+
# ======================
|
| 15 |
+
st.set_page_config(
|
| 16 |
+
page_title="House Price Prediction",
|
| 17 |
+
page_icon="🏡",
|
| 18 |
+
layout="centered"
|
| 19 |
+
)
|
| 20 |
|
| 21 |
+
st.title("🏡 House Price Prediction")
|
| 22 |
+
st.write("Predict the house price based on key features")
|
| 23 |
|
| 24 |
+
# ======================
|
| 25 |
+
# SIDEBAR INPUTS
|
| 26 |
+
# ======================
|
| 27 |
+
st.sidebar.header("House Features")
|
| 28 |
|
| 29 |
+
OverallQual = st.sidebar.slider("Overall Quality", 1, 10, 5)
|
| 30 |
+
GrLivArea = st.sidebar.number_input("Above Ground Living Area (sq ft)", 300, 5000, 1500)
|
| 31 |
+
GarageCars = st.sidebar.slider("Garage Capacity (cars)", 0, 4, 2)
|
| 32 |
+
TotalBsmtSF = st.sidebar.number_input("Total Basement Area (sq ft)", 0, 3000, 800)
|
| 33 |
+
FullBath = st.sidebar.slider("Full Bathrooms", 0, 4, 2)
|
| 34 |
+
YearBuilt = st.sidebar.slider("Year Built", 1900, 2024, 2000)
|
| 35 |
|
| 36 |
+
Neighborhood = st.sidebar.selectbox(
|
| 37 |
+
"Neighborhood",
|
| 38 |
+
[
|
| 39 |
+
"NAmes", "CollgCr", "OldTown", "Edwards", "Somerst",
|
| 40 |
+
"Gilbert", "NridgHt", "Sawyer", "NWAmes", "SawyerW"
|
| 41 |
+
]
|
| 42 |
+
)
|
| 43 |
|
| 44 |
+
# ======================
|
| 45 |
+
# DATAFRAME
|
| 46 |
+
# ======================
|
| 47 |
+
input_df = pd.DataFrame({
|
| 48 |
+
"OverallQual": [OverallQual],
|
| 49 |
+
"GrLivArea": [GrLivArea],
|
| 50 |
+
"GarageCars": [GarageCars],
|
| 51 |
+
"TotalBsmtSF": [TotalBsmtSF],
|
| 52 |
+
"FullBath": [FullBath],
|
| 53 |
+
"YearBuilt": [YearBuilt],
|
| 54 |
+
"Neighborhood": [Neighborhood]
|
| 55 |
})
|
| 56 |
|
| 57 |
+
st.subheader("Input Data")
|
| 58 |
+
st.write(input_df)
|
| 59 |
+
|
| 60 |
+
# ======================
|
| 61 |
+
# PREDICTION
|
| 62 |
+
# ======================
|
| 63 |
+
if st.button("Predict Price"):
|
| 64 |
+
|
| 65 |
+
prediction = model.predict(input_df)[0]
|
| 66 |
+
|
| 67 |
+
st.subheader("Estimated House Price 💰")
|
| 68 |
+
st.success(f"${prediction:,.0f}")
|