Spaces:
Configuration error
Configuration error
Upload folder using huggingface_hub
Browse files- Dockerfile +10 -0
- app.py +28 -0
- requirements.txt +8 -0
Dockerfile
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use a minimal base image with Python 3.11 installed
|
| 2 |
+
FROM python:3.11
|
| 3 |
+
#Set working directory inside container
|
| 4 |
+
WORKDIR /app
|
| 5 |
+
#Copy all files from the current directory on the host to the container's /app directory
|
| 6 |
+
COPY . .
|
| 7 |
+
#Install Python dependencies listed in requirements.txt
|
| 8 |
+
RUN pip install -r requirements.txt
|
| 9 |
+
#Define the command to run the Flask app
|
| 10 |
+
CMD ["python","-w","4", "-b", "0.0.0.0:7860", "app:Sales_forecasting_api"]
|
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
from flask import Flask, request, jsonify
|
| 3 |
+
import joblib
|
| 4 |
+
|
| 5 |
+
#Initialize Flask app with a name
|
| 6 |
+
Sales_forecasting_api = Flask("Sales Forecasting API")
|
| 7 |
+
|
| 8 |
+
#Load of the Saved Mpdel Pipeline
|
| 9 |
+
pipeline = joblib.load("superkart_pipeline.pkl")
|
| 10 |
+
|
| 11 |
+
#Home Route
|
| 12 |
+
@Sales_forecasting_api.route("/")
|
| 13 |
+
def home():
|
| 14 |
+
return"Welcome to the SuperKart Sales Prediction API!"
|
| 15 |
+
# Define an endpoint to predict Sales
|
| 16 |
+
@Sales_forecasting_api.route("/predict", methods=["POST"])
|
| 17 |
+
def predict():
|
| 18 |
+
try:
|
| 19 |
+
# Get JSON data from the request
|
| 20 |
+
data = request.get_json()
|
| 21 |
+
# Convert JSON to DataFrame
|
| 22 |
+
input_df = pd.DataFrame([data])
|
| 23 |
+
# Make predictions
|
| 24 |
+
predictions = pipeline.predict(input_df)
|
| 25 |
+
# Return predictions as JSON
|
| 26 |
+
return jsonify({"predictions": predictions.tolist()})
|
| 27 |
+
except Exception as e:
|
| 28 |
+
return jsonify({"error": str(e)})
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask==3.0.3
|
| 2 |
+
pandas==2.2.2
|
| 3 |
+
numpy==1.26.4
|
| 4 |
+
scikit-learn==1.5.1
|
| 5 |
+
joblib==1.4.2
|
| 6 |
+
gunicorn==22.0.0
|
| 7 |
+
flask-cors==4.0.1
|
| 8 |
+
python-dotenv==1.0.1
|