File size: 675 Bytes
b713665 f857dc1 b713665 61fffb7 b713665 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
from flask import Flask, request, jsonify
import numpy as np
import xgboost as xgb
app = Flask(__name__)
# Load model from JSON (instead of pickle)
model = xgb.Booster()
model.load_model("xgb_superkart_model.json")
@app.route("/", methods=["GET"])
def root():
return "SuperKart Sales Forecasting API is running."
@app.route("/predict", methods=["POST"])
def predict():
data = request.get_json(force=True)
features = np.array(data["features"]).reshape(1, -1)
dmatrix = xgb.DMatrix(features)
prediction = model.predict(dmatrix)
return jsonify({"prediction": float(prediction[0])})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=7860)
|