Upload folder using huggingface_hub
Browse files- Dockerfile +14 -0
- app.py +38 -0
- requirements.txt +12 -0
- sales_prediction_model.joblib +3 -0
Dockerfile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11-slim-buster # Uses a minimal Python 3.11 image as the base environment for deployment.
|
| 2 |
+
|
| 3 |
+
WORKDIR /app # Sets the working directory within the container to /app.
|
| 4 |
+
|
| 5 |
+
COPY requirements.txt ./ # Copies the requirements.txt file to the container's current working directory.
|
| 6 |
+
|
| 7 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt # Installs the required Python packages listed in requirements.txt without caching to reduce image size.
|
| 8 |
+
|
| 9 |
+
COPY app.py ./ # Copies the application script app.py into the container.
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
EXPOSE 5000 # Opens port 5000 so that the application can be accessed externally.
|
| 13 |
+
|
| 14 |
+
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "app:app"] # Starts the app using Gunicorn, binding it to port 5000 for web requests.
|
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import joblib
|
| 3 |
+
from flask import Flask, request, jsonify
|
| 4 |
+
|
| 5 |
+
# Initialize flask app with a name
|
| 6 |
+
app = Flask("SuperKart Sales Prediction App")
|
| 7 |
+
|
| 8 |
+
# Load the trained model pipeline
|
| 9 |
+
model_path = "/content/deployment_files/SuperKart_Sales_Prediction_Model.joblib"
|
| 10 |
+
model = joblib.load(model_path)
|
| 11 |
+
|
| 12 |
+
# Define a route for the home page
|
| 13 |
+
@app.route("/")
|
| 14 |
+
def home():
|
| 15 |
+
return "Welcome to the SuperKart Sales Prediction App!"
|
| 16 |
+
|
| 17 |
+
# Define an endpoint for making predictions
|
| 18 |
+
@app.route("/predict", methods=["POST"])
|
| 19 |
+
def predict_sales():
|
| 20 |
+
if rf_pipeline is None:
|
| 21 |
+
return jsonify({"error": "Model not loaded"}), 500
|
| 22 |
+
|
| 23 |
+
try:
|
| 24 |
+
# Get JSON data from the request
|
| 25 |
+
data = request.get_json()
|
| 26 |
+
if not data:
|
| 27 |
+
return jsonify({"error": "No data provided"}), 400
|
| 28 |
+
|
| 29 |
+
# Extract features from the JSON data
|
| 30 |
+
input_df = pd.DataFrame([data])
|
| 31 |
+
|
| 32 |
+
return jsonify({"prediction": model.predict(input_df).tolist()})
|
| 33 |
+
|
| 34 |
+
except Exception as e:
|
| 35 |
+
return jsonify({"error": str(e)}), 500
|
| 36 |
+
|
| 37 |
+
if __name__ == "__main__":
|
| 38 |
+
app.run(host="0.0.0.0", port=5000,debug=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy==2.0.2
|
| 2 |
+
pandas==2.2.2
|
| 3 |
+
scikit-learn==1.6.1
|
| 4 |
+
matplotlib==3.10.0
|
| 5 |
+
seaborn==0.13.2
|
| 6 |
+
joblib==1.4.2
|
| 7 |
+
xgboost==2.1.4
|
| 8 |
+
requests==2.32.3
|
| 9 |
+
huggingface_hub==0.30.1
|
| 10 |
+
flask==3.0.0
|
| 11 |
+
gunicorn==21.2.0
|
| 12 |
+
|
sales_prediction_model.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0f612465edf4838d6867ea8d66915d4f18bf9e845e7991124a54e3513dcece86
|
| 3 |
+
size 1401539
|