DOMMETI commited on
Commit
eb0c6cc
Β·
verified Β·
1 Parent(s): 8ff2368

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -26
app.py CHANGED
@@ -1,32 +1,17 @@
 
1
  import streamlit as st
2
  import numpy as np
3
  import pickle
4
- from sklearn.compose import ColumnTransformer
5
- from sklearn.pipeline import Pipeline
6
- from sklearn.preprocessing import OneHotEncoder, OrdinalEncoder, RobustScaler
7
 
8
- # Load Model
9
  try:
10
- with open("final_model_2.pkl", "rb") as f:
11
  model = pickle.load(f)
12
  st.success("βœ… Model loaded successfully!")
13
  except FileNotFoundError:
14
  st.error("❌ Model file not found! Please upload `final_model.pkl`.")
15
  model = None
16
 
17
- # Define your preprocessing pipeline (assuming it's already defined in your model)
18
- # Example preprocessing pipeline
19
- nom_pl = Pipeline(steps=[('Encoding', OneHotEncoder(sparse_output=False, handle_unknown='ignore'))])
20
- ord_pl = Pipeline(steps=[('Encoding', OrdinalEncoder())])
21
- scale_pl = Pipeline(steps=[('Scaling', RobustScaler())])
22
-
23
- ct = ColumnTransformer(
24
- transformers=[
25
- ('nom_pl', nom_pl, [0, 4]), # Example for categorical columns
26
- ('ord_pl', ord_pl, [1, 2, 3, 6, 7]), # Example for ordinal columns
27
- ('scale_pl', scale_pl, [5, 8, 9]) # Example for numerical columns
28
- ])
29
-
30
  # Title of the application
31
  st.markdown("<h1 class='title'>🏑 House Price Predictor</h1>", unsafe_allow_html=True)
32
 
@@ -44,16 +29,14 @@ with st.expander("πŸ”Ή **Property Details**", expanded=True):
44
  LATITUDE = st.number_input("LATITUDE", min_value=-121.761248, max_value=152.962676, value=77.324137)
45
 
46
  if st.button("πŸ” Predict Price"):
47
- # Create input data for prediction
48
- input_data = [[POSTED_BY, UNDER_CONSTRUCTION, RERA, BHK_NO_, BHK_OR_RK, SQUARE_FT,
49
- READY_TO_MOVE, RESALE, LONGITUDE, LATITUDE]]
50
-
51
- # Transform input data using the ColumnTransformer (fit before prediction)
52
- # You need to transform the input data before prediction
53
- input_data_transformed = ct.transform(input_data)
54
 
55
  # Make prediction using the model
56
- predicted_price = model.predict(input_data_transformed)[0]
57
 
58
  # Display predicted price
59
  st.markdown(f"<div class='result-box'>🏠 Predicted Price: β‚Ή {predicted_price:.2f} Lakhs</div>", unsafe_allow_html=True)
 
1
+ import pandas as pd
2
  import streamlit as st
3
  import numpy as np
4
  import pickle
 
 
 
5
 
6
+ # Load model
7
  try:
8
+ with open("final_model_3.pkl", "rb") as f:
9
  model = pickle.load(f)
10
  st.success("βœ… Model loaded successfully!")
11
  except FileNotFoundError:
12
  st.error("❌ Model file not found! Please upload `final_model.pkl`.")
13
  model = None
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  # Title of the application
16
  st.markdown("<h1 class='title'>🏑 House Price Predictor</h1>", unsafe_allow_html=True)
17
 
 
29
  LATITUDE = st.number_input("LATITUDE", min_value=-121.761248, max_value=152.962676, value=77.324137)
30
 
31
  if st.button("πŸ” Predict Price"):
32
+ # Create input data for prediction, using pandas DataFrame with proper column names
33
+ input_data = pd.DataFrame([[POSTED_BY, UNDER_CONSTRUCTION, RERA, BHK_NO_, BHK_OR_RK, SQUARE_FT,
34
+ READY_TO_MOVE, RESALE, LONGITUDE, LATITUDE]],
35
+ columns=["POSTED_BY", "UNDER_CONSTRUCTION", "RERA", "BHK_NO_", "BHK_OR_RK", "SQUARE_FT",
36
+ "READY_TO_MOVE", "RESALE", "LONGITUDE", "LATITUDE"])
 
 
37
 
38
  # Make prediction using the model
39
+ predicted_price = model.predict(input_data)[0]
40
 
41
  # Display predicted price
42
  st.markdown(f"<div class='result-box'>🏠 Predicted Price: β‚Ή {predicted_price:.2f} Lakhs</div>", unsafe_allow_html=True)