KavinPrasathK commited on
Commit
11bb94d
·
verified ·
1 Parent(s): 913b3bd

Upload folder using huggingface_hub

Browse files
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Base Image
3
+ FROM python:3.9-slim
4
+
5
+ # Setting the working directory inside the container
6
+ WORKDIR /app
7
+
8
+ # Copying all files from the current directory to the container's working directory
9
+ COPY . .
10
+
11
+ # Installing dependencies from the requirements file without using cache to reduce image size
12
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
13
+
14
+ # Defining the command to start the application using Gunicorn with 4 worker processes
15
+ CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:product_store_sales_predictor_api"]
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Libraries to help with reading and manipulating data
3
+ import numpy as np
4
+ import pandas as pd
5
+
6
+ # For loading the serialized model
7
+ import joblib
8
+
9
+ # For creating the Flask API
10
+ from flask import Flask, request, jsonify
11
+
12
+ # Initializing the Flask application
13
+ product_store_sales_predictor_api = Flask("Product Store Sales Predictor")
14
+
15
+ # Loading the serialised ML model (XGBRegressor Tuned)
16
+ model = joblib.load("product_store_sales_prediction_model_v1_0.joblib")
17
+
18
+ # Route for the home page (GET request)
19
+ @product_store_sales_predictor_api.get('/')
20
+ def home():
21
+ """
22
+ This function handles GET requests to the root URL ('/') of the API.
23
+ It returns a simple welcome message.
24
+ """
25
+ return "Welcome to the Product Store Sales Prediction API!"
26
+
27
+ # Endpoint for Sales prediction for a single product in a given store (POST request)
28
+ @product_store_sales_predictor_api.post('/v1/sales')
29
+ def predict_sales():
30
+ """
31
+ This function handles POST requests to the '/v1/sales' endpoint.
32
+ It expects a JSON payload containing Product and Store details and returns
33
+ the predicted sales amount as a JSON response.
34
+ """
35
+ # Retrieving the JSON data from the request body
36
+ product_store_data = request.get_json()
37
+
38
+ # Extracting the required from the JSON data
39
+ sample = {
40
+ 'Product_Weight': product_store_data['Product_Weight'],
41
+ 'Product_Allocated_Area': product_store_data['Product_Allocated_Area'],
42
+ 'Product_MRP': product_store_data['Product_MRP'],
43
+ 'Store_Establishment_Year': product_store_data['Store_Establishment_Year'],
44
+ 'Product_Sugar_Content': product_store_data['Product_Sugar_Content'],
45
+ 'Product_Type': product_store_data['Product_Type'],
46
+ 'Store_Id': product_store_data['Store_Id'],
47
+ 'Store_Size': product_store_data['Store_Size'],
48
+ 'Store_Location_City_Type': product_store_data['Store_Location_City_Type'],
49
+ 'Store_Type': product_store_data['Store_Type']
50
+ }
51
+
52
+ # Converting the extracted data into a Pandas DataFrame
53
+ input_data = pd.DataFrame([sample])
54
+
55
+ # Predicting the sales amount
56
+ predicted_sales = model.predict(input_data)[0]
57
+
58
+ # Convert predicted_sales to Python float
59
+ predicted_sales = round(float(predicted_sales), 2)
60
+
61
+ # Return the predicted sales amount
62
+ return jsonify({'Predicted Sales Amount': predicted_sales})
63
+
64
+ if __name__ == '__main__':
65
+ product_store_sales_predictor_api.run(debug=True)
product_store_sales_prediction_model_v1_0.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b18f749f9335729b14cc01661acd8d9f6ffefba9a225d3d2b5d424d6a1131980
3
+ size 208249
requirements.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ pandas==2.2.2
3
+ numpy==2.0.2
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.28.1
11
+ uvicorn[standard]
12
+ streamlit==1.43.2