hsaluja431 commited on
Commit
4fd7ca0
·
verified ·
1 Parent(s): fd5d75f

Upload folder using huggingface_hub

Browse files
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 . .
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:sales_predictor_api"]
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import joblib
2
+ import pandas as pd
3
+ from flask import Flask, request, jsonify
4
+
5
+ # Initialize Flask app with a name
6
+ sales_predictor_api = Flask("Product_Store_Total_Sales_Predictor")
7
+
8
+ # Load the trained Product Store Total Sales prediction model
9
+ model = saved_model
10
+
11
+ # Define a route for the home page
12
+ @sales_predictor_api.get('/')
13
+ def home():
14
+ return "Welcome to the Product Store Total Sales Prediction API!"
15
+
16
+ # Define an endpoint to predict product sales for a specific store
17
+ @sales_predictor_api.post('/v1/product')
18
+ def predict_product_sales():
19
+ # Get JSON data from the request
20
+ product_data = request.get_json()
21
+
22
+ # Extract relevant product features from the input data
23
+ sample = {
24
+ 'Product_Weight': product_data['Product_Weight'],
25
+ 'Product_Sugar_Content': product_data['Product_Sugar_Content'],
26
+ 'Product_Allocated_Area': product_data['Product_Allocated_Area'],
27
+ 'Product_Type': product_data['Product_Type'],
28
+ 'Product_MRP': product_data['Product_MRP'],
29
+ 'Store_Establishment_Year': product_data['Store_Establishment_Year'],
30
+ 'Store_Size': product_data['Store_Size'].map(size_map),
31
+ 'Store_Location_City_Type': product_data['Store_Location_City_Type'],
32
+ 'Store_Type': product_data['Store_Type'],
33
+ 'Store_Age': 2025 - product_data['Store_Establishment_Year']
34
+ }
35
+
36
+ # Convert the extracted data into a DataFrame
37
+ input_data = pd.DataFrame([sample])
38
+
39
+ # Make a churn prediction using the trained model
40
+ prediction = model.predict(input_data).tolist()[0]
41
+
42
+ # Return the prediction as a JSON response
43
+ return jsonify({'Product Store Sales Total': prediction})
44
+
45
+ # Run the Flask app in debug mode
46
+ if __name__ == '__main__':
47
+ app.run(debug=True)
product_sales_total_prediction_v1_0.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f943dd8c0455f29391c420fcda63861f855f3d4bf3e1539ff6ea80c5a205bfef
3
+ size 45040883
requirements.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pandas==2.2.2
2
+ numpy==2.0.2
3
+ scikit-learn==1.6.1
4
+ xgboost==2.1.4
5
+ joblib==1.4.2
6
+ Werkzeug==2.2.2
7
+ flask==2.2.2
8
+ gunicorn==20.1.0
9
+ requests==2.32.3
10
+ uvicorn[standard]
11
+ streamlit==1.43.2
12
+ huggingface_hub==0.30.1