import streamlit as st import pandas as pd import joblib import os # ====================== # LOAD MODEL # ====================== BASE_DIR = os.path.dirname(os.path.abspath(__file__)) model = joblib.load(os.path.join(BASE_DIR, "house_price_model.pkl")) # ====================== # PAGE CONFIG # ====================== st.set_page_config( page_title="House Price Prediction", page_icon="🏡", layout="centered" ) st.title("🏡 House Price Prediction") st.write("Predict the house price based on key features") # ====================== # SIDEBAR INPUTS # ====================== st.sidebar.header("House Features") OverallQual = st.sidebar.slider("Overall Quality", 1, 10, 5) GrLivArea = st.sidebar.number_input("Above Ground Living Area (sq ft)", 300, 5000, 1500) GarageCars = st.sidebar.slider("Garage Capacity (cars)", 0, 4, 2) TotalBsmtSF = st.sidebar.number_input("Total Basement Area (sq ft)", 0, 3000, 800) FullBath = st.sidebar.slider("Full Bathrooms", 0, 4, 2) YearBuilt = st.sidebar.slider("Year Built", 1900, 2024, 2000) Neighborhood = st.sidebar.selectbox( "Neighborhood", [ "NAmes", "CollgCr", "OldTown", "Edwards", "Somerst", "Gilbert", "NridgHt", "Sawyer", "NWAmes", "SawyerW" ] ) # ====================== # DATAFRAME # ====================== input_df = pd.DataFrame({ "OverallQual": [OverallQual], "GrLivArea": [GrLivArea], "GarageCars": [GarageCars], "TotalBsmtSF": [TotalBsmtSF], "FullBath": [FullBath], "YearBuilt": [YearBuilt], "Neighborhood": [Neighborhood] }) st.subheader("Input Data") st.write(input_df) # ====================== # PREDICTION # ====================== if st.button("Predict Price"): prediction = model.predict(input_df)[0] st.subheader("Estimated House Price 💰") st.success(f"${prediction:,.0f}")