Upload folder using huggingface_hub
Browse files- Dockerfile +3 -4
- SuperKart_Sales_Prediction_Model.joblib +2 -2
- app.py +18 -9
- requirements.txt +2 -2
Dockerfile
CHANGED
|
@@ -2,13 +2,12 @@ FROM python:3.9-slim
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
COPY requirements.txt
|
| 6 |
|
| 7 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 8 |
|
| 9 |
-
COPY
|
| 10 |
-
COPY SuperKart_Sales_Prediction_Model.joblib ./
|
| 11 |
|
| 12 |
EXPOSE 5000
|
| 13 |
|
| 14 |
-
CMD ["gunicorn", "-w", "4", "--bind", "0.0.0.0:
|
|
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
+
COPY requirements.txt .
|
| 6 |
|
| 7 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 8 |
|
| 9 |
+
COPY . .
|
|
|
|
| 10 |
|
| 11 |
EXPOSE 5000
|
| 12 |
|
| 13 |
+
CMD ["gunicorn", "-w", "4", "--bind", "0.0.0.0:7860", "app:app"]
|
SuperKart_Sales_Prediction_Model.joblib
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7c672355b08b885f21ebed6ecbcc2b7cb1e8855e24d7f491803c5444d6c56fd7
|
| 3 |
+
size 473398
|
app.py
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
|
|
| 1 |
import os
|
| 2 |
import joblib
|
| 3 |
from flask import Flask, request, jsonify
|
| 4 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
|
| 9 |
# Load the trained model pipeline
|
| 10 |
-
model_path = "SuperKart_Sales_Prediction_Model.joblib"
|
| 11 |
try:
|
| 12 |
-
|
|
|
|
| 13 |
except Exception as e:
|
| 14 |
-
|
| 15 |
print(f"Error loading model: {e}")
|
| 16 |
|
|
|
|
|
|
|
|
|
|
| 17 |
# Define a route for the home page
|
| 18 |
@app.route("/")
|
| 19 |
def home():
|
|
@@ -21,8 +28,8 @@ def home():
|
|
| 21 |
|
| 22 |
# Define an endpoint for making predictions
|
| 23 |
@app.route("/predict", methods=["POST"])
|
| 24 |
-
def
|
| 25 |
-
if
|
| 26 |
return jsonify({"error": "Model not loaded"}), 500
|
| 27 |
|
| 28 |
try:
|
|
@@ -34,10 +41,12 @@ def predict_sales():
|
|
| 34 |
# Extract features from the JSON data
|
| 35 |
input_df = pd.DataFrame([data])
|
| 36 |
|
| 37 |
-
|
|
|
|
| 38 |
|
| 39 |
except Exception as e:
|
| 40 |
-
return jsonify({"error":
|
| 41 |
|
| 42 |
if __name__ == "__main__": # Correct indentation
|
|
|
|
| 43 |
app.run(host="0.0.0.0", port=5000, debug=True)
|
|
|
|
| 1 |
+
|
| 2 |
import os
|
| 3 |
import joblib
|
| 4 |
from flask import Flask, request, jsonify
|
| 5 |
import pandas as pd
|
| 6 |
+
import numpy as np
|
| 7 |
+
import warnings
|
| 8 |
+
warnings.filterwarnings("ignore")
|
| 9 |
|
| 10 |
+
# Define the path to the serialised model
|
| 11 |
+
MODEL_PATH = "/content/deployment_files/SuperKart_Sales_Prediction_Model.joblib"
|
| 12 |
|
| 13 |
# Load the trained model pipeline
|
|
|
|
| 14 |
try:
|
| 15 |
+
model_pipeline = joblib.load(MODEL_PATH)
|
| 16 |
+
print(f"Model loaded successfully from {MODEL_PATH}")
|
| 17 |
except Exception as e:
|
| 18 |
+
model_pipeline = None
|
| 19 |
print(f"Error loading model: {e}")
|
| 20 |
|
| 21 |
+
# Initialize the Flask application
|
| 22 |
+
app = Flask(__name__)
|
| 23 |
+
|
| 24 |
# Define a route for the home page
|
| 25 |
@app.route("/")
|
| 26 |
def home():
|
|
|
|
| 28 |
|
| 29 |
# Define an endpoint for making predictions
|
| 30 |
@app.route("/predict", methods=["POST"])
|
| 31 |
+
def predict():
|
| 32 |
+
if model_pipeline is None:
|
| 33 |
return jsonify({"error": "Model not loaded"}), 500
|
| 34 |
|
| 35 |
try:
|
|
|
|
| 41 |
# Extract features from the JSON data
|
| 42 |
input_df = pd.DataFrame([data])
|
| 43 |
|
| 44 |
+
prediction = model_pipeline.predict(input_df)
|
| 45 |
+
return jsonify({"prediction": prediction.tolist()})
|
| 46 |
|
| 47 |
except Exception as e:
|
| 48 |
+
return jsonify({"error": f'Error during prediction: {e}'}), 500
|
| 49 |
|
| 50 |
if __name__ == "__main__": # Correct indentation
|
| 51 |
+
port = int(os.environ.get("PORT", 5000))
|
| 52 |
app.run(host="0.0.0.0", port=5000, debug=True)
|
requirements.txt
CHANGED
|
@@ -4,6 +4,6 @@ scikit-learn==1.6.1
|
|
| 4 |
joblib==1.4.2
|
| 5 |
requests==2.32.3
|
| 6 |
huggingface_hub==0.30.1
|
| 7 |
-
flask==3.
|
| 8 |
-
gunicorn==
|
| 9 |
Werkzeug==3.0.1
|
|
|
|
| 4 |
joblib==1.4.2
|
| 5 |
requests==2.32.3
|
| 6 |
huggingface_hub==0.30.1
|
| 7 |
+
flask==3.1.0
|
| 8 |
+
gunicorn==23.0.0
|
| 9 |
Werkzeug==3.0.1
|