Coots commited on
Commit
4067998
·
verified ·
1 Parent(s): c42003e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -3,12 +3,14 @@ import joblib
3
  import numpy as np
4
  import json
5
  import math
 
6
 
7
- app = Flask(__name__) # Corrected from _name_ to __name__
8
 
9
  # Load models
10
- xgb = joblib.load("xgb_model.pkl")
11
  rf = joblib.load("rf_model.pkl")
 
 
12
 
13
  # Load tile catalog and sizes
14
  with open("tile_catalog.json", "r", encoding="utf-8") as f:
@@ -46,8 +48,8 @@ def recommend():
46
  features = prepare_features(data)
47
 
48
  # Get predictions from both models
49
- xgb_pred = xgb.predict_proba(features)[0][1]
50
- rf_pred = rf.predict_proba(features)[0][1]
51
  combined_score = (xgb_pred + rf_pred) / 2
52
 
53
  # Filter products based on criteria
@@ -170,5 +172,5 @@ def calculate_requirements(area, coverage):
170
  ]
171
  }
172
 
173
- if __name__ == '__main__': # Corrected from _name_ to __name__
174
  app.run(host='0.0.0.0', port=5000, debug=True)
 
3
  import numpy as np
4
  import json
5
  import math
6
+ import xgboost as xgb
7
 
8
+ app = Flask(__name__)
9
 
10
  # Load models
 
11
  rf = joblib.load("rf_model.pkl")
12
+ xgb_model = xgb.Booster()
13
+ xgb_model.load_model("xgb_model.json") # Load the XGBoost model from JSON
14
 
15
  # Load tile catalog and sizes
16
  with open("tile_catalog.json", "r", encoding="utf-8") as f:
 
48
  features = prepare_features(data)
49
 
50
  # Get predictions from both models
51
+ xgb_pred = xgb_model.predict(xgb.DMatrix(features))[0] # XGBoost prediction
52
+ rf_pred = rf.predict_proba(features)[0][1] # Random Forest prediction
53
  combined_score = (xgb_pred + rf_pred) / 2
54
 
55
  # Filter products based on criteria
 
172
  ]
173
  }
174
 
175
+ if __name__ == '__main__':
176
  app.run(host='0.0.0.0', port=5000, debug=True)