MuthuVaidy commited on
Commit
8b0f9fd
·
verified ·
1 Parent(s): f82fe60

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +41 -0
  2. requirements.txt +9 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Initialize Flask app
3
+ sales_forecast_api = Flask("SuperKart Sales Forecast API")
4
+
5
+ # Load trained model (includes preprocessing pipeline)
6
+ model = joblib.load("model/best_random_forest.pkl")
7
+
8
+ # Home route
9
+ @sales_forecast_api.get('/')
10
+ def home():
11
+ return "Welcome to the SuperKart Sales Forecast API!"
12
+
13
+ # Predict for a single input
14
+ @sales_forecast_api.post('/v1/predict')
15
+ def predict_sales():
16
+ data = request.get_json()
17
+
18
+ # Convert JSON into DataFrame (1 row)
19
+ input_df = pd.DataFrame([data])
20
+
21
+ # Model prediction
22
+ prediction = model.predict(input_df).tolist()[0]
23
+
24
+ return jsonify({"Predicted_Sales_Total": prediction})
25
+
26
+ # Predict for a batch (CSV upload)
27
+ @sales_forecast_api.post('/v1/predict_batch')
28
+ def predict_sales_batch():
29
+ file = request.files['file']
30
+ input_data = pd.read_csv(file)
31
+
32
+ preds = model.predict(input_data).tolist()
33
+
34
+ # Map row index → prediction
35
+ results = {i: pred for i, pred in enumerate(preds)}
36
+
37
+ return jsonify(results)
38
+
39
+ # Run app
40
+ if __name__ == "__main__":
41
+ sales_forecast_api.run(debug=True)
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+
2
+ pandas==2.2.2
3
+ numpy==2.0.2
4
+ scikit-learn==1.6.1
5
+ joblib==1.4.2
6
+ flask==2.2.2
7
+ gunicorn==20.1.0
8
+ requests==2.28.1
9
+ huggingface_hub==0.24.0