Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import numpy as np | |
| import pandas as pd | |
| import joblib | |
| # Load saved files | |
| model = joblib.load("house_price_model.pkl") | |
| scaler = joblib.load("scaler.pkl") | |
| columns = joblib.load("columns.pkl") | |
| def predict_price(bedrooms, bathrooms, sqft_living, sqft_lot, floors, | |
| waterfront, view, condition, sqft_above, | |
| sqft_basement, yr_built, yr_renovated, year, month): | |
| # Create dataframe from user input | |
| input_data = pd.DataFrame([[bedrooms, bathrooms, sqft_living, sqft_lot, floors, | |
| waterfront, view, condition, sqft_above, | |
| sqft_basement, yr_built, yr_renovated, year, month]], | |
| columns=['bedrooms','bathrooms','sqft_living','sqft_lot','floors', | |
| 'waterfront','view','condition','sqft_above', | |
| 'sqft_basement','yr_built','yr_renovated','year','month']) | |
| # Match training columns | |
| input_data = input_data.reindex(columns=columns, fill_value=0) | |
| # Scale input | |
| input_scaled = scaler.transform(input_data) | |
| # Predict log price | |
| log_price = model.predict(input_scaled) | |
| # Convert back to original price | |
| price = np.exp(log_price) | |
| return f"Predicted House Price: ₹ {int(price[0])}" | |
| # Gradio Interface | |
| interface = gr.Interface( | |
| fn=predict_price, | |
| inputs=[ | |
| gr.Number(label="Bedrooms", value=3), | |
| gr.Number(label="Bathrooms", value=2), | |
| gr.Number(label="Sqft Living", value=1800), | |
| gr.Number(label="Sqft Lot", value=4000), | |
| gr.Number(label="Floors", value=1), | |
| gr.Number(label="Waterfront (0/1)", value=0), | |
| gr.Number(label="View (0-4)", value=0), | |
| gr.Number(label="Condition (1-5)", value=3), | |
| gr.Number(label="Sqft Above", value=1500), | |
| gr.Number(label="Sqft Basement", value=300), | |
| gr.Number(label="Year Built", value=2005), | |
| gr.Number(label="Year Renovated", value=0), | |
| gr.Number(label="Year Sold", value=2014), | |
| gr.Number(label="Month Sold", value=5) | |
| ], | |
| outputs="text", | |
| title="House Price Prediction App" | |
| ) | |
| interface.launch(debug = True,share = False) | |