singhina commited on
Commit
0a5c0c9
·
1 Parent(s): 202f1ca

Add deployment files

Browse files
Files changed (4) hide show
  1. Dockerfile +13 -0
  2. app.py +31 -0
  3. best_sales_forecast_model.pkl +3 -0
  4. requirements.txt +4 -0
Dockerfile ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use a lightweight Python base image
2
+ FROM python:3.11-slim
3
+
4
+ WORKDIR /app
5
+
6
+ COPY requirements.txt .
7
+ RUN pip install --no-cache-dir -r requirements.txt
8
+
9
+ COPY app.py .
10
+ COPY best_sales_forecast_model.pkl .
11
+
12
+ EXPOSE 5000
13
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ import pandas as pd
3
+ import joblib
4
+
5
+ app = Flask(__name__)
6
+
7
+ MODEL_PATH = "best_sales_forecast_model.pkl"
8
+ model = joblib.load(MODEL_PATH)
9
+
10
+ FEATURE_COLUMNS = [
11
+ "Product_Weight","Product_Allocated_Area","Product_MRP",
12
+ "Store_Establishment_Year","Store_Size","Store_Location_City_Type",
13
+ "Store_Type","Product_Prefix","Product_Num","Store_Age"
14
+ ]
15
+
16
+ @app.route("/")
17
+ def home():
18
+ return "SuperKart Sales Forecast API is up."
19
+
20
+ @app.route("/predict", methods=["POST"])
21
+ def predict():
22
+ payload = request.get_json(force=True)
23
+ df = pd.DataFrame(payload["data"])
24
+ X = df[FEATURE_COLUMNS]
25
+ preds = model.predict(X)
26
+ return jsonify({"predictions": preds.tolist()})
27
+
28
+ if __name__ == "__main__":
29
+ import os
30
+ port = int(os.environ.get("PORT", 5000))
31
+ app.run(host="0.0.0.0", port=port)
best_sales_forecast_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6f13226779001590e025ef62b31e40021305709d38a5ab555e18bc1611208c97
3
+ size 49997859
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ flask==2.2.5
2
+ pandas==2.1.1
3
+ scikit-learn==1.4.0
4
+ joblib==1.3.2