omm7 commited on
Commit
b713665
·
verified ·
1 Parent(s): 1f5490b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -19
app.py CHANGED
@@ -1,19 +1,20 @@
1
- from flask import Flask, request, jsonify
2
- import pickle
3
- import numpy as np
4
-
5
- app = Flask(__name__)
6
-
7
- # Load model
8
- with open("xgb_superkart_model.pkl", "rb") as f:
9
- model = pickle.load(f)
10
-
11
- @app.route("/predict", methods=["POST"])
12
- def predict():
13
- data = request.get_json(force=True)
14
- features = np.array(data["features"]).reshape(1, -1)
15
- prediction = model.predict(features)
16
- return jsonify({"prediction": float(prediction[0])})
17
-
18
- if __name__ == "__main__":
19
- app.run(host="0.0.0.0", port=7860)
 
 
1
+ from flask import Flask, request, jsonify
2
+ import numpy as np
3
+ import xgboost as xgb
4
+
5
+ app = Flask(__name__)
6
+
7
+ # Load model from JSON (instead of pickle)
8
+ model = xgb.Booster()
9
+ model.load_model("model/xgb_superkart_model.json")
10
+
11
+ @app.route("/predict", methods=["POST"])
12
+ def predict():
13
+ data = request.get_json(force=True)
14
+ features = np.array(data["features"]).reshape(1, -1)
15
+ dmatrix = xgb.DMatrix(features)
16
+ prediction = model.predict(dmatrix)
17
+ return jsonify({"prediction": float(prediction[0])})
18
+
19
+ if __name__ == "__main__":
20
+ app.run(host="0.0.0.0", port=7860)