krishpvg commited on
Commit
4f7c7c5
·
verified ·
1 Parent(s): d25d6ca

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +16 -0
  2. app.py +35 -0
  3. requirements.txt +10 -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 . .
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,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import joblib
2
+ import pandas as pd
3
+ from flask import Flask, request, jsonify
4
+
5
+ app = Flask("Superkart Sales Predictor")
6
+ model = joblib.load("superkart.joblib")
7
+
8
+ @app.get('/')
9
+ def home():
10
+ return "Welcome to the Superkart Sales Predictor API"
11
+
12
+ @app.post('/v1/sales')
13
+ def predict_sales():
14
+ product_data = request.get_json()
15
+
16
+ sample = {
17
+ 'Product_Type': product_data['Product_Type'],
18
+ 'Product_Sugar_Content': product_data['Product_Sugar_Content'],
19
+ 'Product_Weight': product_data['Product_Weight'],
20
+ 'Product_Allocated_Area': product_data['Product_Allocated_Area'],
21
+ 'Product_MRP': product_data['Product_MRP'],
22
+ 'Store_Id': product_data['Store_Id'],
23
+ 'Store_Size': product_data['Store_Size'],
24
+ 'Store_Type': product_data['Store_Type'],
25
+ 'Store_Location_City_Type': product_data['Store_Location_City_Type'],
26
+ 'Store_Establishment_Year': product_data['Store_Establishment_Year']
27
+ }
28
+ input_data = pd.DataFrame([sample])
29
+ input_data
30
+
31
+ prediction = model.predict(input_data).tolist()[0]
32
+ return jsonify({'prediction': prediction})
33
+
34
+ if __name__ == '__main__':
35
+ app.run(debug=True)
requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
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.28.1
10
+ uvicorn[standard]