Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +17 -0
- app.py +33 -0
- requirements.txt +7 -0
Dockerfile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9-slim
|
| 2 |
+
|
| 3 |
+
# Set the working directory inside the container
|
| 4 |
+
WORKDIR /app
|
| 5 |
+
|
| 6 |
+
# Copy all files from the current directory to the container's working directory
|
| 7 |
+
# (Ensure the serialized model file is present in this directory before building)
|
| 8 |
+
COPY . .
|
| 9 |
+
|
| 10 |
+
# Install dependencies from the requirements file without using cache to reduce image size
|
| 11 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 12 |
+
|
| 13 |
+
# Define the command to start the application using Gunicorn with 4 worker processes
|
| 14 |
+
# - `-w 4`: Uses 4 worker processes for handling requests
|
| 15 |
+
# - `-b 0.0.0.0:7860`: Binds the server to port 7860 on all network interfaces
|
| 16 |
+
# - `app:superkart_sales_api`: Runs the Flask app (Flask instance in app.py is named `superkart_sales_api`)
|
| 17 |
+
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:superkart_sales_api"]
|
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import joblib
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from flask import Flask, request, jsonify
|
| 5 |
+
|
| 6 |
+
superkart_sales_api = Flask("superkart_sales_api")
|
| 7 |
+
model = joblib.load("deployment_files/superkart_sales_forecast_model_v1_0.joblib")
|
| 8 |
+
|
| 9 |
+
@superkart_sales_api.get("/")
|
| 10 |
+
def home():
|
| 11 |
+
return "SuperKart Sales Forecasting API is alive"
|
| 12 |
+
|
| 13 |
+
@superkart_sales_api.post("/v1/predict")
|
| 14 |
+
def predict_sales():
|
| 15 |
+
data = request.get_json()
|
| 16 |
+
sample = {
|
| 17 |
+
"Product_Weight": data["Product_Weight"],
|
| 18 |
+
"Product_Sugar_Content": data["Product_Sugar_Content"],
|
| 19 |
+
"Product_Allocated_Area": data["Product_Allocated_Area"],
|
| 20 |
+
"Product_MRP": data["Product_MRP"],
|
| 21 |
+
"Store_Size": data["Store_Size"],
|
| 22 |
+
"Store_Location_City_Type": data["Store_Location_City_Type"],
|
| 23 |
+
"Store_Type": data["Store_Type"],
|
| 24 |
+
"Product_Id": data["Product_Id"],
|
| 25 |
+
"Store_Establishment_Year": data["Store_Establishment_Year"],
|
| 26 |
+
"Product_Type": data["Product_Type"],
|
| 27 |
+
}
|
| 28 |
+
pred = model.predict(pd.DataFrame([sample])).tolist()[0]
|
| 29 |
+
return jsonify({"Predicted Product_Store_Sales_Total": pred})
|
| 30 |
+
|
| 31 |
+
if __name__ == "__main__":
|
| 32 |
+
superkart_sales_api.run(debug=True)
|
| 33 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
numpy==2.0.2
|
| 3 |
+
scikit-learn==1.6.1
|
| 4 |
+
joblib==1.4.2
|
| 5 |
+
Werkzeug==2.2.2
|
| 6 |
+
flask==2.2.2
|
| 7 |
+
gunicorn==20.1.0
|