affanthinks commited on
Commit
2b97390
·
verified ·
1 Parent(s): a4ea853

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +20 -0
  2. app.py +42 -0
  3. requirements.txt +5 -0
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Base image with Python
2
+ FROM python:3.10-slim
3
+
4
+ # Set working directory inside container
5
+ WORKDIR /app
6
+
7
+ # Copy requirements first (for caching)
8
+ COPY requirements.txt .
9
+
10
+ # Install dependencies
11
+ RUN pip install --no-cache-dir -r requirements.txt
12
+
13
+ # Copy all project files (API + model)
14
+ COPY . .
15
+
16
+ # Expose port for Flask
17
+ EXPOSE 7860
18
+
19
+ # Run the Flask app
20
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from flask import Flask, request, jsonify
3
+ import joblib
4
+ import numpy as np
5
+
6
+
7
+ from huggingface_hub import hf_hub_download
8
+ import joblib
9
+
10
+ # download from model repo
11
+ model_path = hf_hub_download(
12
+ repo_id="affanthinks/superkart",
13
+ filename="tuned_bagging_model.pkl"
14
+ )
15
+
16
+ model = joblib.load(model_path)
17
+
18
+
19
+ # Initialize app
20
+ app = Flask("predict_revenue")
21
+
22
+ @app.route("/")
23
+ def home():
24
+ return jsonify({"message": "Supermarket Revenue Prediction API is running!"})
25
+
26
+ @app.route("/predict", methods=["POST"])
27
+ def predict():
28
+ try:
29
+ # Get JSON input
30
+ data = request.get_json(force=True)
31
+ features = np.array(data["features"]).reshape(1, -1)
32
+
33
+ # Predict
34
+ prediction = model.predict(features)[0]
35
+
36
+ return jsonify({"predicted_revenue": float(prediction)})
37
+
38
+ except Exception as e:
39
+ return jsonify({"error": str(e)})
40
+
41
+ if "predict_revenue" == "__main__":
42
+ app.run(host="0.0.0.0", port=7860, debug=True)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ flask
2
+ numpy==1.26.4
3
+ pandas==2.2.2
4
+ scikit-learn==1.5.1
5
+ joblib==1.4.2