Upload folder using huggingface_hub
Browse files- Dockerfile +16 -0
- app.py +56 -0
- requirements.txt +12 -0
- smartkart_model_v1_0.joblib +3 -0
Dockerfile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9-slim
|
| 2 |
+
|
| 3 |
+
# Set working directory
|
| 4 |
+
WORKDIR /app
|
| 5 |
+
|
| 6 |
+
# Copy backend files into container
|
| 7 |
+
COPY . .
|
| 8 |
+
|
| 9 |
+
# Install dependencies
|
| 10 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 11 |
+
|
| 12 |
+
# Start the SmartKart API using Gunicorn
|
| 13 |
+
# -w 4 → 4 worker processes
|
| 14 |
+
# -b 0.0.0.0:7860 → required port for Hugging Face Spaces
|
| 15 |
+
# app:smartkart_api → Flask instance name inside app.py
|
| 16 |
+
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:app"]
|
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# Import necessary libraries
|
| 3 |
+
import numpy as np
|
| 4 |
+
import joblib
|
| 5 |
+
import pandas as pd
|
| 6 |
+
from flask import Flask, request, jsonify
|
| 7 |
+
app = Flask(__name__) # ← THIS MUST EXIST
|
| 8 |
+
|
| 9 |
+
# Initialize the Flask application
|
| 10 |
+
smartkart_api = Flask("SmartKart Total Sales Predictor")
|
| 11 |
+
|
| 12 |
+
# Load the trained SmartKart model
|
| 13 |
+
model = joblib.load("smartkart_model_v1_0.joblib")
|
| 14 |
+
|
| 15 |
+
# Home route
|
| 16 |
+
@smartkart_api.get('/')
|
| 17 |
+
def home():
|
| 18 |
+
return "Welcome to the SmartKart Total Sales Prediction API!"
|
| 19 |
+
|
| 20 |
+
# Endpoint for single prediction
|
| 21 |
+
@smartkart_api.post('/v1/predict')
|
| 22 |
+
def predict_total_sales():
|
| 23 |
+
"""
|
| 24 |
+
Handles POST requests to /v1/predict.
|
| 25 |
+
Expects JSON with SmartKart product/store features.
|
| 26 |
+
Returns predicted total sales.
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
data = request.get_json()
|
| 30 |
+
|
| 31 |
+
# Extract the SmartKart model features from the JSON payload
|
| 32 |
+
sample = {
|
| 33 |
+
'Product_Weight': data['Product_Weight'],
|
| 34 |
+
'Product_Allocated_Area': data['Product_Allocated_Area'],
|
| 35 |
+
'Product_MRP': data['Product_MRP'],
|
| 36 |
+
'Store_Age': data['Store_Age'],
|
| 37 |
+
'Product_Sugar_Content_Ord': data['Product_Sugar_Content_Ord'],
|
| 38 |
+
'Store_Size_Ord': data['Store_Size_Ord'],
|
| 39 |
+
'Store_Location_City_Type_Ord': data['Store_Location_City_Type_Ord'],
|
| 40 |
+
# One-hot encoded or target-encoded fields:
|
| 41 |
+
'Store_Type': data['Store_Type'],
|
| 42 |
+
'Product_Type': data['Product_Type']
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
# Convert to DataFrame
|
| 46 |
+
input_df = pd.DataFrame([sample])
|
| 47 |
+
|
| 48 |
+
# Predict total sales
|
| 49 |
+
predicted_sales = model.predict(input_df)[0]
|
| 50 |
+
|
| 51 |
+
# Convert to Python float
|
| 52 |
+
predicted_sales = round(float(predicted_sales), 2)
|
| 53 |
+
|
| 54 |
+
return jsonify({'Predicted_Total_Sales': predicted_sales})
|
| 55 |
+
|
| 56 |
+
app.run(host="0.0.0.0", port=7860)
|
requirements.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
joblib
|
| 2 |
+
pandas==2.2.2
|
| 3 |
+
numpy==1.26.4
|
| 4 |
+
scikit-learn==1.6.1
|
| 5 |
+
xgboost==2.1.4
|
| 6 |
+
joblib==1.4.2
|
| 7 |
+
Werkzeug==2.2.2
|
| 8 |
+
flask==2.2.2
|
| 9 |
+
gunicorn==20.1.0
|
| 10 |
+
requests>=2.31
|
| 11 |
+
uvicorn[standard]
|
| 12 |
+
streamlit==1.43.2
|
smartkart_model_v1_0.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dcf37fa829ad125ae78dbae40f3715715c6e960fbe1cdaa415047a07a3c80cc0
|
| 3 |
+
size 645339
|