w4backend / app.py
omm7's picture
Update app.py
61fffb7 verified
raw
history blame contribute delete
675 Bytes
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)