Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +20 -0
- app.py +49 -0
- requirements.txt +7 -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,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from flask import Flask, request, jsonify
|
| 3 |
+
import joblib
|
| 4 |
+
import numpy as np
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
from huggingface_hub import hf_hub_download
|
| 9 |
+
import joblib
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
model_path = hf_hub_download(
|
| 14 |
+
repo_id="affanthinks/superkart",
|
| 15 |
+
filename="AGreatLearning/tuned_bagging_model.pkl", # include directory
|
| 16 |
+
revision="main", # ensures correct branch
|
| 17 |
+
token=os.getenv("HF_TOKEN") # authentication
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
model = joblib.load(model_path)
|
| 21 |
+
print("✅ Model loaded successfully from", model_path)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# Initialize app
|
| 27 |
+
app = Flask("predict_revenue")
|
| 28 |
+
|
| 29 |
+
@app.route("/")
|
| 30 |
+
def home():
|
| 31 |
+
return jsonify({"message": "Supermarket Revenue Prediction API is running!"})
|
| 32 |
+
|
| 33 |
+
@app.route("/predict", methods=["POST"])
|
| 34 |
+
def predict():
|
| 35 |
+
try:
|
| 36 |
+
# Get JSON input
|
| 37 |
+
data = request.get_json(force=True)
|
| 38 |
+
features = np.array(data["features"]).reshape(1, -1)
|
| 39 |
+
|
| 40 |
+
# Predict
|
| 41 |
+
prediction = model.predict(features)[0]
|
| 42 |
+
|
| 43 |
+
return jsonify({"predicted_revenue": float(prediction)})
|
| 44 |
+
|
| 45 |
+
except Exception as e:
|
| 46 |
+
return jsonify({"error": str(e)})
|
| 47 |
+
|
| 48 |
+
if "predict_revenue" == "__main__":
|
| 49 |
+
app.run(host="0.0.0.0", port=7860, debug=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask
|
| 2 |
+
numpy==1.26.4
|
| 3 |
+
pandas==2.2.2
|
| 4 |
+
scikit-learn==1.5.1
|
| 5 |
+
joblib==1.4.2
|
| 6 |
+
huggingface_hub
|
| 7 |
+
|