Coots commited on
Commit
5633152
Β·
verified Β·
1 Parent(s): 1d78c23

Update tile_api.py

Browse files
Files changed (1) hide show
  1. tile_api.py +39 -39
tile_api.py CHANGED
@@ -1,39 +1,39 @@
1
- from flask import Flask, request, jsonify
2
- import joblib
3
- import numpy as np
4
-
5
- app = Flask(__name__)
6
-
7
- # Load models (make sure these files exist)
8
- xgb = joblib.load("xgb_model.pkl")
9
- rf = joblib.load("rf_model.pkl")
10
-
11
- @app.route("/recommend", methods=["POST"])
12
- def recommend():
13
- data = request.get_json()
14
-
15
- # Extract input features
16
- length = float(data["length"])
17
- width = float(data["width"])
18
- price = float(data["price"])
19
- coverage = float(data["coverage"])
20
- area_range = float(data["area_range"])
21
- tile_type = data["tile_type"].lower()
22
-
23
- # Feature engineering
24
- tile_type_num = 0 if tile_type == "floor" else 1
25
- tile_area = length * width
26
- price_per_sqft = price / coverage
27
- budget_eff = coverage / price
28
-
29
- features = np.array([[tile_type_num, length, width, price, coverage,
30
- area_range, tile_area, price_per_sqft, budget_eff]])
31
-
32
- # Predict using both models and average
33
- prob = (xgb.predict_proba(features)[0][1] + rf.predict_proba(features)[0][1]) / 2
34
- result = "βœ… Recommended" if prob >= 0.5 else "❌ Not Recommended"
35
-
36
- return jsonify({"result": result, "score": round(float(prob), 3)})
37
-
38
- if __name__ == "__main__":
39
- app.run(debug=True)
 
1
+ from flask import Flask, request, jsonify
2
+ import joblib
3
+ import numpy as np
4
+
5
+ app = Flask(__name__)
6
+
7
+ # Load models (make sure these files exist)
8
+ xgb = joblib.load("xgb_model.json")
9
+ rf = joblib.load("rf_model.pkl")
10
+
11
+ @app.route("/recommend", methods=["POST"])
12
+ def recommend():
13
+ data = request.get_json()
14
+
15
+ # Extract input features
16
+ length = float(data["length"])
17
+ width = float(data["width"])
18
+ price = float(data["price"])
19
+ coverage = float(data["coverage"])
20
+ area_range = float(data["area_range"])
21
+ tile_type = data["tile_type"].lower()
22
+
23
+ # Feature engineering
24
+ tile_type_num = 0 if tile_type == "floor" else 1
25
+ tile_area = length * width
26
+ price_per_sqft = price / coverage
27
+ budget_eff = coverage / price
28
+
29
+ features = np.array([[tile_type_num, length, width, price, coverage,
30
+ area_range, tile_area, price_per_sqft, budget_eff]])
31
+
32
+ # Predict using both models and average
33
+ prob = (xgb.predict_proba(features)[0][1] + rf.predict_proba(features)[0][1]) / 2
34
+ result = "βœ… Recommended" if prob >= 0.5 else "❌ Not Recommended"
35
+
36
+ return jsonify({"result": result, "score": round(float(prob), 3)})
37
+
38
+ if __name__ == "__main__":
39
+ app.run(debug=True)