File size: 1,018 Bytes
6b368d7
b86469d
284b571
 
 
 
b86469d
284b571
 
6b368d7
284b571
 
6b368d7
284b571
28a4036
284b571
b86469d
284b571
 
b86469d
284b571
 
 
fc9ef74
284b571
 
fc9ef74
6b368d7
284b571
 
6b368d7
b86469d
284b571
 
 
 
b86469d
284b571
 
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# app.py — SuperKart Sales Forecaster Backend

from flask import Flask, request, jsonify
import joblib
import numpy as np
import pandas as pd

# Initialize Flask app
app = Flask(__name__)

# === Load model ===
model = joblib.load("tuned_xgb_sales_forecaster.pkl")

@app.route("/")
def home():
    return jsonify({"message": "SuperKart Sales Forecasting API is running!"})

@app.route("/predict", methods=["POST"])
def predict():
    try:
        # Expecting JSON input with "features" list
        data = request.get_json()
        features = np.array(data["features"]).reshape(1, -1)

        prediction_log = model.predict(features)[0]
        prediction_original = float(np.expm1(prediction_log))

        return jsonify({
            "predicted_sales": prediction_original,
            "status": "success"
        })
    except Exception as e:
        return jsonify({
            "error": str(e),
            "status": "failed"
        }), 400

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=7860)