rajeevseetha commited on
Commit
02e5334
·
verified ·
1 Parent(s): 91ca73d

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. Dockerfile +20 -0
  2. SuperKartRFRegressor.joblib +3 -0
  3. app.py +52 -0
  4. requirements.txt +13 -0
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use a minimal base image with Python 3.9 installed
2
+ FROM python:3.9-slim
3
+
4
+ # Set the working directory inside the container to /app
5
+ WORKDIR /app
6
+
7
+ # Copy all files from the current directory on the host to the container's /app directory
8
+ COPY . .
9
+
10
+ # Install Python dependencies listed in requirements.txt
11
+ RUN pip3 install --no-cache-dir --upgrade -r requirements.txt
12
+
13
+ # Define the command to run the Streamlit app on port 8501 and make it accessible externally
14
+ #CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
15
+
16
+ # Define the command to start the application using Gunicorn with 4 worker processes
17
+ # - `-w 4`: Uses 4 worker processes for handling requests
18
+ # - `-b 0.0.0.0:7860`: Binds the server to port 7860 on all network interfaces
19
+ # - `app:app`: Runs the Flask app (assuming `app.py` contains the Flask instance named `app`)
20
+ CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:superkart_api"]
SuperKartRFRegressor.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:16b37f399a47786c478f62c0fbc4bf730599e62d369bf89c5f9e31e85e9a4f2e
3
+ size 72643
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Import necessary libraries
3
+ import numpy as np
4
+ import joblib # For loading the serialized model
5
+ import pandas as pd # For data manipulation
6
+ from flask import Flask, request, jsonify # For creating the Flask API
7
+
8
+ # Initialize Flask app with a name
9
+ superkart_api = Flask("SuperKart Saler Predictor")
10
+
11
+ # Load the trained churn prediction model
12
+ model = joblib.load("SuperKartRFRegressor.joblib")
13
+
14
+ # Define a route for the home page
15
+ @superkart_api.get('/')
16
+ def home():
17
+ """ This function returns a welcome message when the user visits the home page. """
18
+ return "Welcome to the SuperKart Sales Predictor Model Application."
19
+
20
+ # Define an endpoint to predict churn for a single customer
21
+ @superkart_api.post('/v1/superkart')
22
+ def predict_sales():
23
+ Get JSON data from the request
24
+ data = request.get_json()
25
+
26
+ # Extract relevant customer features from the input data. The order of the column names matters.
27
+ sample = {
28
+ 'Product_Weight': data['Product_Weight'],
29
+ 'Product_Sugar_Content': data['Product_Sugar_Content'],
30
+ 'Product_Allocated_Area': data['Product_Allocated_Area'],
31
+ 'Product_MRP': data['Product_MRP'],
32
+ 'Store_Size': data['Store_Size'],
33
+ 'Store_Location_City_Type': data['Store_Location_City_Type'],
34
+ 'Store_Type': data['Store_Type'],
35
+ 'Product_Id_char': data['Product_Id_char'],
36
+ 'Store_Age_Years': data['Store_Age_Years'],
37
+ 'Product_Type_Category': data['Product_Type_Category']
38
+ }
39
+
40
+ # Convert the extracted data into a DataFrame
41
+ input_data = pd.DataFrame([sample])
42
+
43
+ # Make a churn prediction using the trained model
44
+ prediction = model.predict(input_data).tolist()[0]
45
+
46
+ # Return the prediction as a JSON response
47
+ return jsonify({'Sales': prediction})
48
+
49
+
50
+ # Run the Flask app in debug mode
51
+ if __name__ == '__main__':
52
+ superkart_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