Upload folder using huggingface_hub
Browse files- Dockerfile +16 -0
- app.py +54 -0
- requirements.txt +13 -0
- superkart_sales_prediction_model_v1_0.joblib +3 -0
Dockerfile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
COPY '/content/drive/MyDrive/Colab Notebooks/Module 7 - Model Deployment/Project/rf/backend_files/*' .
|
| 8 |
+
|
| 9 |
+
# Install dependencies from the requirements file without using cache to reduce image size
|
| 10 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 11 |
+
|
| 12 |
+
# Define the command to start the application using Gunicorn with 4 worker processes
|
| 13 |
+
# - `-w 4`: Uses 4 worker processes for handling requests
|
| 14 |
+
# - `-b 0.0.0.0:7860`: Binds the server to port 7860 on all network interfaces
|
| 15 |
+
# - `app:app`: Runs the Flask app (assuming `app.py` contains the Flask instance named `app`)
|
| 16 |
+
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:rf_superkart_prediction_api"]
|
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# Initialize the Flask application
|
| 3 |
+
rf_superkart_prediction_api = Flask("SuperKart Sales Prediction with Random Forest")
|
| 4 |
+
|
| 5 |
+
# Load the trained machine learning model
|
| 6 |
+
rf_model = joblib.load("/content/drive/MyDrive/Colab Notebooks/Module 7 - Model Deployment/Project/rf/backend_files/superkart_sales_prediction_model_v1_0.joblib")
|
| 7 |
+
|
| 8 |
+
# Define a route for the home page (GET request)
|
| 9 |
+
@rf_superkart_prediction_api.get('/')
|
| 10 |
+
def home():
|
| 11 |
+
"""
|
| 12 |
+
This function handles GET requests to the root URL ('/') of the API.
|
| 13 |
+
It returns a simple welcome message.
|
| 14 |
+
"""
|
| 15 |
+
return "Welcome to the SuperKart Sales Prediction API!"
|
| 16 |
+
|
| 17 |
+
# Define an endpoint for single property prediction (POST request)
|
| 18 |
+
@rf_superkart_prediction_api.post('/v1/predict')
|
| 19 |
+
def predict_sales():
|
| 20 |
+
"""
|
| 21 |
+
This function handles POST requests to the '/v1/predict' endpoint.
|
| 22 |
+
It expects a JSON payload containing store details and returns
|
| 23 |
+
the predicted sales as a JSON response.
|
| 24 |
+
"""
|
| 25 |
+
# Get the JSON data from the request body
|
| 26 |
+
store_data = request.get_json()
|
| 27 |
+
|
| 28 |
+
# Extract relevant features from the JSON data
|
| 29 |
+
sample = {
|
| 30 |
+
'Product_Weight': data['Product_Weight'],
|
| 31 |
+
'Product_Sugar_Content': data['Product_Sugar_Content'],
|
| 32 |
+
'Product_Allocated_Area': data['Product_Allocated_Area'],
|
| 33 |
+
'Product_MRP': data['Product_MRP'],
|
| 34 |
+
'Store_Size': data['Store_Size'],
|
| 35 |
+
'Store_Location_City_Type': data['Store_Location_City_Type'],
|
| 36 |
+
'Store_Type': data['Store_Type'],
|
| 37 |
+
'Product_Id_char': data['Product_Id_char'],
|
| 38 |
+
'Store_Age_Years': data['Store_Age_Years'],
|
| 39 |
+
'Product_Type_Category': data['Product_Type_Category']
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
# Convert the extracted data into a Pandas DataFrame
|
| 43 |
+
input_data = pd.DataFrame([sample])
|
| 44 |
+
|
| 45 |
+
# Make prediction (get log_price)
|
| 46 |
+
predicted_sales = rf_model.predict(input_data)[0]
|
| 47 |
+
|
| 48 |
+
# Return the prediction
|
| 49 |
+
return jsonify({'Predicted Sales': predicted_sales})
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
# Run the Flask application in debug mode if this script is executed directly
|
| 53 |
+
if __name__ == '__main__':
|
| 54 |
+
rf_superkart_prediction_api.run(debug=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
numpy==2.0.2
|
| 3 |
+
scikit-learn==1.6.1
|
| 4 |
+
seaborn==0.13.2
|
| 5 |
+
joblib==1.4.2
|
| 6 |
+
xgboost==2.1.4
|
| 7 |
+
joblib==1.4.2
|
| 8 |
+
Werkzeug==2.2.2
|
| 9 |
+
flask==2.2.2
|
| 10 |
+
gunicorn==20.1.0
|
| 11 |
+
requests==2.32.3
|
| 12 |
+
uvicorn[standard]
|
| 13 |
+
streamlit==1.43.2
|
superkart_sales_prediction_model_v1_0.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c9155b5afe619d61ca196d3c9b06aa3d345171a955358074ddca2dbb0a3e4d83
|
| 3 |
+
size 41408531
|