singhina commited on
Commit
c29a8e4
·
1 Parent(s): e4711e0

fix: correct Flask deployment with docker SDK

Browse files
.huggingface.yaml ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ app_port: 7860
2
+ sdk: docker
Dockerfile ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+ WORKDIR /app
3
+ COPY requirements.txt .
4
+ RUN pip install --no-cache-dir -r requirements.txt
5
+ COPY app.py .
6
+ COPY final_random_forest_model.pkl .
7
+ EXPOSE 7860
8
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ from flask_cors import CORS
3
+ import pandas as pd, joblib, os
4
+
5
+ app = Flask(__name__)
6
+ CORS(app)
7
+
8
+ model = joblib.load("final_random_forest_model.pkl")
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("/", methods=["GET"])
17
+ def home():
18
+ return "✅ SuperKart Forecast API is running"
19
+
20
+ @app.route("/predict", methods=["POST"])
21
+ def predict():
22
+ data = request.get_json(force=True)["data"]
23
+ df = pd.DataFrame(data)[FEATURE_COLUMNS]
24
+ preds = model.predict(df)
25
+ return jsonify({"predictions": preds.tolist()})
26
+
27
+ if __name__ == "__main__":
28
+ port = int(os.environ.get("PORT", 7860))
29
+ app.run(host="0.0.0.0", port=port)
final_random_forest_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7bbd80f25f24f85f9461b8ed48e52593e1916c60d892034781d145819376e721
3
+ size 49995363
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ flask==2.2.5
2
+ flask-cors==3.0.10
3
+ pandas==2.1.1
4
+ scikit-learn==1.6.1
5
+ joblib==1.3.2
6
+ numpy==1.24.4