Upload 2 files
Browse files- HousePricePredictorPipeline.pkl +3 -0
- gradio_app.py +83 -0
HousePricePredictorPipeline.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f84bad5df668049fd601b7efef1786230661028df5dfe6a7788c35569fad5b75
|
| 3 |
+
size 144002
|
gradio_app.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import joblib as jb
|
| 4 |
+
|
| 5 |
+
# Load the trained pipeline
|
| 6 |
+
# Make sure HousePricePredictorPipeline.pkl is in the same directory as this script
|
| 7 |
+
MODEL_PATH = "HousePricePredictorPipeline.pkl"
|
| 8 |
+
pipe = jb.load(MODEL_PATH)
|
| 9 |
+
|
| 10 |
+
# Expected feature schema
|
| 11 |
+
NUM_FEATURES = ["area","parking","bedrooms","bathrooms","stories"]
|
| 12 |
+
CAT_FEATURES = ["furnishingstatus","mainroad","guestroom","basement",
|
| 13 |
+
"hotwaterheating","airconditioning","prefarea"]
|
| 14 |
+
|
| 15 |
+
ALL_COLUMNS = NUM_FEATURES + CAT_FEATURES
|
| 16 |
+
|
| 17 |
+
YES_NO = ["yes","no"]
|
| 18 |
+
FURNISHING = ["unfurnished","semi-furnished","furnished"]
|
| 19 |
+
|
| 20 |
+
def predict_price(area, parking, bedrooms, bathrooms, stories,
|
| 21 |
+
furnishingstatus, mainroad, guestroom, basement,
|
| 22 |
+
hotwaterheating, airconditioning, prefarea):
|
| 23 |
+
# Build a single-row DataFrame that matches the training-time schema
|
| 24 |
+
row = {
|
| 25 |
+
"area": area,
|
| 26 |
+
"parking": int(parking),
|
| 27 |
+
"bedrooms": int(bedrooms),
|
| 28 |
+
"bathrooms": int(bathrooms),
|
| 29 |
+
"stories": int(stories),
|
| 30 |
+
"furnishingstatus": furnishingstatus,
|
| 31 |
+
"mainroad": mainroad,
|
| 32 |
+
"guestroom": guestroom,
|
| 33 |
+
"basement": basement,
|
| 34 |
+
"hotwaterheating": hotwaterheating,
|
| 35 |
+
"airconditioning": airconditioning,
|
| 36 |
+
"prefarea": prefarea
|
| 37 |
+
}
|
| 38 |
+
X = pd.DataFrame([row], columns=ALL_COLUMNS)
|
| 39 |
+
pred = pipe.predict(X)[0]
|
| 40 |
+
return float(pred)
|
| 41 |
+
|
| 42 |
+
with gr.Blocks(title="House Price Predictor") as demo:
|
| 43 |
+
gr.Markdown("# 🏠 House Price Predictor")
|
| 44 |
+
gr.Markdown(
|
| 45 |
+
"Provide home features and get an estimated price. "
|
| 46 |
+
"This app uses your trained scikit-learn pipeline."
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
with gr.Row():
|
| 50 |
+
with gr.Column():
|
| 51 |
+
area = gr.Number(label="Area (sq ft)", value=2000, precision=0)
|
| 52 |
+
parking = gr.Slider(label="Parking Spots", value=1, minimum=0, maximum=5, step=1)
|
| 53 |
+
bedrooms = gr.Slider(label="Bedrooms", value=3, minimum=0, maximum=10, step=1)
|
| 54 |
+
bathrooms = gr.Slider(label="Bathrooms", value=2, minimum=0, maximum=10, step=1)
|
| 55 |
+
stories = gr.Slider(label="Stories", value=2, minimum=0, maximum=10, step=1)
|
| 56 |
+
|
| 57 |
+
with gr.Column():
|
| 58 |
+
furnishingstatus = gr.Dropdown(FURNISHING, value="semi-furnished", label="Furnishing Status")
|
| 59 |
+
mainroad = gr.Dropdown(YES_NO, value="yes", label="On Main Road?")
|
| 60 |
+
guestroom = gr.Dropdown(YES_NO, value="no", label="Guest Room?")
|
| 61 |
+
basement = gr.Dropdown(YES_NO, value="no", label="Basement?")
|
| 62 |
+
hotwaterheating = gr.Dropdown(YES_NO, value="no", label="Hot Water Heating?")
|
| 63 |
+
airconditioning = gr.Dropdown(YES_NO, value="yes", label="Air Conditioning?")
|
| 64 |
+
prefarea = gr.Dropdown(YES_NO, value="no", label="Preferred Area?")
|
| 65 |
+
|
| 66 |
+
btn = gr.Button("Predict Price")
|
| 67 |
+
output = gr.Number(label="Predicted Price (same units as your training data)")
|
| 68 |
+
|
| 69 |
+
btn.click(
|
| 70 |
+
fn=predict_price,
|
| 71 |
+
inputs=[area, parking, bedrooms, bathrooms, stories,
|
| 72 |
+
furnishingstatus, mainroad, guestroom, basement,
|
| 73 |
+
hotwaterheating, airconditioning, prefarea],
|
| 74 |
+
outputs=output
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
gr.Markdown(
|
| 78 |
+
"Tip: Ensure **HousePricePredictorPipeline.pkl** is in the same folder.\n"
|
| 79 |
+
"Run with: `python gradio_app.py` and open the link in your browser."
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
if __name__ == "__main__":
|
| 83 |
+
demo.launch()
|