RPeltier commited on
Commit
421e0cf
·
verified ·
1 Parent(s): d4e7008

Upload folder using huggingface_hub

Browse files
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10.11-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 -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:app"]
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Import necessary libraries
2
+ import numpy as np
3
+ import joblib
4
+ import pandas as pd
5
+ from flask import Flask, request, jsonify
6
+
7
+ # Initialize Flask app with a name
8
+ app = Flask("Super Kart Product Pricing Predictor")
9
+
10
+ # Load the trained churn prediction model
11
+ saved_model_path = "backend_files/super_kart_product_pricing_model.joblib" model = joblib.load(saved_model_path)
12
+
13
+ # Define a route for the home page, used to validate backend is functional and accessible
14
+ @app.get('/')
15
+ def home():
16
+ return "Welcome to the Super Kart Product Pricing Predictor API!"
17
+
18
+ # Define an endpoint to predict churn for a single customer
19
+ @app.post('/v1/predict')
20
+ def predict_sales():
21
+ # Get JSON data from the request
22
+ data = request.get_json()
23
+
24
+ # Extract relevant customer features from the input data. The order of the column names matters.
25
+ sample = {
26
+ 'Product_Weight': data['Product_Weight'],
27
+ 'Product_Sugar_Content': data['Product_Sugar_Content'],
28
+ 'Product_Allocated_Area': data['Product_Allocated_Area'],
29
+ 'Product_Type_Category': data['Product_Type_Category'],
30
+ 'Product_MRP': data['Product_MRP'],
31
+ 'Store_Size': data['Store_Size'],
32
+ 'Store_Location_City_Type': data['Store_Location_City_Type'],
33
+ 'Store_Type': data['Store_Type'],
34
+ 'Product_Id_char': data['Product_Id_char'],
35
+ 'Store_Age_Years': data['Store_Age_Years'],
36
+ }
37
+
38
+ # Convert the extracted data into a DataFrame and preprocess it
39
+ input_data = pd.DataFrame([sample])
40
+ prediction = model.predict(input_data).tolist()[0]
41
+
42
+ # Return the prediction as a JSON response
43
+ return jsonify({'Predicted Product Price': prediction})
44
+
45
+ # Run the Flask app in debug mode
46
+ if __name__ == '__main__':
47
+ app.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
super_kart_product_pricing_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:75710a0fcb8560098f5f2a96c6b2f6bd8806dc39230e1858879c45df9ed9a58e
3
+ size 358226