DOMMETI commited on
Commit
651cb82
·
verified ·
1 Parent(s): db630a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -10
app.py CHANGED
@@ -9,22 +9,41 @@ from sklearn.pipeline import Pipeline
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
  # Define your preprocessing pipeline (to match the one used during training)
19
- nom_pl = Pipeline(steps=[('Encoding', OneHotEncoder(drop='first', sparse_output=False, handle_unknown='ignore'))])
20
-
21
- # Create a ColumnTransformer for the preprocessing steps
22
- ct = ColumnTransformer(
23
- transformers=[
24
- ('nom_pl', nom_pl, [0, 4]), # Apply OneHotEncoder on 'POSTED_BY' and 'BHK_OR_RK'
25
- ],
26
- remainder='passthrough' # Leave other columns as they are
27
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  # Title of the application
30
  st.markdown("<h1 class='title'>🏡 House Price Predictor</h1>", unsafe_allow_html=True)
 
9
  # Load Model
10
  try:
11
  with open("final_model_1.pkl", "rb") as f:
12
+ model, ct = pickle.load(f) # Load both the model and the fitted transformer
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)