File size: 1,116 Bytes
ffadcda
 
bb92a61
ffadcda
 
 
 
 
 
bb92a61
 
8a836d9
bf05af0
8a836d9
ffadcda
 
 
 
 
 
8a836d9
ffadcda
 
 
 
 
 
 
87b47e1
ffadcda
 
 
 
8a836d9
ffadcda
 
8a836d9
ffadcda
 
8a836d9
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
41

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

app = Flask(__name__)
CORS(app)

# Load model on startup
deployment_package = joblib.load('models/superkart_deployment_package_20250809_122306.pkl')
model = deployment_package['model']

@app.route('/', methods=['GET'])
def home():
    return jsonify({
        'status': 'healthy',
        'message': 'SuperKart Sales Forecasting API',
        'model_loaded': True
    })

@app.route('/predict', methods=['POST'])
def predict_sales():
    try:
        data = request.get_json()
        input_df = pd.DataFrame([data])
        prediction = model.predict(input_df)
        
        return jsonify({
            'prediction': float(prediction[0]),
            'prediction_formatted': f"${prediction[0]:.2f}",
            'status': 'success'
        })
    except Exception as e:
        return jsonify({'error': str(e), 'status': 'failed'}), 500

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True)