Create main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import joblib
|
| 3 |
+
import numpy as np
|
| 4 |
+
import pandas as pd
|
| 5 |
+
|
| 6 |
+
# Load the model
|
| 7 |
+
model = joblib.load("house_price_model.pkl") # or use linear_regression_model.pkl if preferred
|
| 8 |
+
|
| 9 |
+
# Define input columns (must match training data!)
|
| 10 |
+
input_cols = ['OverallQual', 'GrLivArea', 'GarageCars', 'TotalBsmtSF', '1stFlrSF', 'FullBath', 'YearBuilt']
|
| 11 |
+
|
| 12 |
+
def predict_price(OverallQual, GrLivArea, GarageCars, TotalBsmtSF, FirstFlrSF, FullBath, YearBuilt):
|
| 13 |
+
data = pd.DataFrame([[OverallQual, GrLivArea, GarageCars, TotalBsmtSF, FirstFlrSF, FullBath, YearBuilt]],
|
| 14 |
+
columns=input_cols)
|
| 15 |
+
prediction = model.predict(data)[0]
|
| 16 |
+
return f"Estimated House Price: ${prediction:,.2f}"
|
| 17 |
+
|
| 18 |
+
# Gradio Interface
|
| 19 |
+
demo = gr.Interface(
|
| 20 |
+
fn=predict_price,
|
| 21 |
+
inputs=[
|
| 22 |
+
gr.Slider(1, 10, value=5, label="Overall Quality"),
|
| 23 |
+
gr.Number(label="Above Ground Living Area (GrLivArea)"),
|
| 24 |
+
gr.Slider(0, 4, step=1, label="Garage Cars"),
|
| 25 |
+
gr.Number(label="Total Basement Area (TotalBsmtSF)"),
|
| 26 |
+
gr.Number(label="First Floor Area (1stFlrSF)"),
|
| 27 |
+
gr.Slider(0, 3, step=1, label="Full Bathrooms"),
|
| 28 |
+
gr.Number(label="Year Built"),
|
| 29 |
+
],
|
| 30 |
+
outputs="text",
|
| 31 |
+
title="🏡 House Price Predictor",
|
| 32 |
+
description="Enter the house details and get an estimated price using a trained ML model."
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
if __name__ == "__main__":
|
| 36 |
+
demo.launch()
|