|
|
from flask import Flask, request, jsonify |
|
|
import numpy as np |
|
|
import xgboost as xgb |
|
|
|
|
|
app = Flask(__name__) |
|
|
|
|
|
|
|
|
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) |
|
|
|