Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,41 +9,12 @@ from sklearn.pipeline import Pipeline
|
|
| 9 |
# Load Model
|
| 10 |
try:
|
| 11 |
with open("final_model_1.pkl", "rb") as f:
|
| 12 |
-
model
|
| 13 |
st.success("✅ Model loaded successfully!")
|
| 14 |
except FileNotFoundError:
|
| 15 |
st.error("❌ Model file not found! Please upload `final_model.pkl`.")
|
| 16 |
model = None
|
| 17 |
-
ct = None
|
| 18 |
|
| 19 |
-
# Define your preprocessing pipeline (to match the one used during training)
|
| 20 |
-
if model and ct is None:
|
| 21 |
-
nom_pl = Pipeline(steps=[('Encoding', OneHotEncoder(drop='first', sparse_output=False, handle_unknown='ignore'))])
|
| 22 |
-
|
| 23 |
-
# Create a ColumnTransformer for the preprocessing steps
|
| 24 |
-
ct = ColumnTransformer(
|
| 25 |
-
transformers=[
|
| 26 |
-
('nom_pl', nom_pl, [0, 4]), # Apply OneHotEncoder on 'POSTED_BY' and 'BHK_OR_RK'
|
| 27 |
-
],
|
| 28 |
-
remainder='passthrough' # Leave other columns as they are
|
| 29 |
-
)
|
| 30 |
-
|
| 31 |
-
# Here we simulate fitting the transformer on a sample of data
|
| 32 |
-
train_data = pd.DataFrame({
|
| 33 |
-
'POSTED_BY': ['Owner', 'Dealer', 'Builder'],
|
| 34 |
-
'UNDER_CONSTRUCTION': [1, 0, 1],
|
| 35 |
-
'RERA': [1, 0, 1],
|
| 36 |
-
'BHK_NO_': [2, 3, 2],
|
| 37 |
-
'BHK_OR_RK': ['BHK', 'RK', 'BHK'],
|
| 38 |
-
'SQUARE_FT': [1200, 1500, 1300],
|
| 39 |
-
'READY_TO_MOVE': [1, 0, 1],
|
| 40 |
-
'RESALE': [1, 0, 1],
|
| 41 |
-
'LONGITUDE': [20.75, 21.00, 19.80],
|
| 42 |
-
'LATITUDE': [77.32, 78.00, 76.50]
|
| 43 |
-
})
|
| 44 |
-
|
| 45 |
-
# Fit the transformer on sample data
|
| 46 |
-
ct.fit(train_data)
|
| 47 |
|
| 48 |
# Title of the application
|
| 49 |
st.markdown("<h1 class='title'>🏡 House Price Predictor</h1>", unsafe_allow_html=True)
|
|
@@ -65,12 +36,10 @@ if st.button("🔍 Predict Price"):
|
|
| 65 |
# Create input data for prediction
|
| 66 |
input_data = [[POSTED_BY, UNDER_CONSTRUCTION, RERA, BHK_NO_, BHK_OR_RK, SQUARE_FT,
|
| 67 |
READY_TO_MOVE, RESALE, LONGITUDE, LATITUDE]]
|
| 68 |
-
|
| 69 |
-
# Preprocess the input data using the same transformer pipeline used during training
|
| 70 |
-
input_data_transformed = ct.transform(input_data)
|
| 71 |
|
| 72 |
# Make prediction using the model
|
| 73 |
-
predicted_price = model.predict(
|
| 74 |
|
| 75 |
# Display predicted price
|
| 76 |
st.markdown(f"<div class='result-box'>🏠 Predicted Price: ₹ {predicted_price:.2f} Lakhs</div>", unsafe_allow_html=True)
|
|
|
|
| 9 |
# Load Model
|
| 10 |
try:
|
| 11 |
with open("final_model_1.pkl", "rb") as f:
|
| 12 |
+
model = pickle.load(f)
|
| 13 |
st.success("✅ Model loaded successfully!")
|
| 14 |
except FileNotFoundError:
|
| 15 |
st.error("❌ Model file not found! Please upload `final_model.pkl`.")
|
| 16 |
model = None
|
|
|
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
# Title of the application
|
| 20 |
st.markdown("<h1 class='title'>🏡 House Price Predictor</h1>", unsafe_allow_html=True)
|
|
|
|
| 36 |
# Create input data for prediction
|
| 37 |
input_data = [[POSTED_BY, UNDER_CONSTRUCTION, RERA, BHK_NO_, BHK_OR_RK, SQUARE_FT,
|
| 38 |
READY_TO_MOVE, RESALE, LONGITUDE, LATITUDE]]
|
| 39 |
+
|
|
|
|
|
|
|
| 40 |
|
| 41 |
# Make prediction using the model
|
| 42 |
+
predicted_price = model.predict(input_data)[0]
|
| 43 |
|
| 44 |
# Display predicted price
|
| 45 |
st.markdown(f"<div class='result-box'>🏠 Predicted Price: ₹ {predicted_price:.2f} Lakhs</div>", unsafe_allow_html=True)
|