File size: 1,381 Bytes
f011e7f 6962abb f011e7f |
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 |
import gradio as gr
import joblib
import numpy as np
import pandas as pd
# Load the model
model = joblib.load("house_price_model.joblib") # or use linear_regression_model.pkl if preferred
# Define input columns (must match training data!)
input_cols = ['OverallQual', 'GrLivArea', 'GarageCars', 'TotalBsmtSF', '1stFlrSF', 'FullBath', 'YearBuilt']
def predict_price(OverallQual, GrLivArea, GarageCars, TotalBsmtSF, FirstFlrSF, FullBath, YearBuilt):
data = pd.DataFrame([[OverallQual, GrLivArea, GarageCars, TotalBsmtSF, FirstFlrSF, FullBath, YearBuilt]],
columns=input_cols)
prediction = model.predict(data)[0]
return f"Estimated House Price: ${prediction:,.2f}"
# Gradio Interface
demo = gr.Interface(
fn=predict_price,
inputs=[
gr.Slider(1, 10, value=5, label="Overall Quality"),
gr.Number(label="Above Ground Living Area (GrLivArea)"),
gr.Slider(0, 4, step=1, label="Garage Cars"),
gr.Number(label="Total Basement Area (TotalBsmtSF)"),
gr.Number(label="First Floor Area (1stFlrSF)"),
gr.Slider(0, 3, step=1, label="Full Bathrooms"),
gr.Number(label="Year Built"),
],
outputs="text",
title="🏡 House Price Predictor",
description="Enter the house details and get an estimated price using a trained ML model."
)
if __name__ == "__main__":
demo.launch()
|