righthook75 commited on
Commit
d63b444
·
verified ·
1 Parent(s): 2a453cd

Upload folder using huggingface_hub

Browse files
Files changed (6) hide show
  1. Dockerfile +16 -0
  2. X_test.csv +5 -0
  3. X_test.json +0 -0
  4. app.py +59 -0
  5. requirements.txt +11 -0
  6. superkart.joblib +3 -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 --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:superkart_api"]
X_test.csv ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ Product_Weight,Product_Allocated_Area,Product_MRP,Store_Establishment_Year,Product_Sugar_Content_No Sugar,Product_Sugar_Content_Regular,Product_Type_Breads,Product_Type_Breakfast,Product_Type_Canned,Product_Type_Dairy,Product_Type_Frozen Foods,Product_Type_Fruits and Vegetables,Product_Type_Hard Drinks,Product_Type_Health and Hygiene,Product_Type_Household,Product_Type_Meat,Product_Type_Others,Product_Type_Seafood,Product_Type_Snack Foods,Product_Type_Soft Drinks,Product_Type_Starchy Foods,Store_Id_OUT002,Store_Id_OUT003,Store_Id_OUT004,Store_Size_Medium,Store_Size_Small,Store_Location_City_Type_Tier 2,Store_Location_City_Type_Tier 3,Store_Type_Food Mart,Store_Type_Supermarket Type1,Store_Type_Supermarket Type2
2
+ 12.53,0.066,145.62,2009,False,True,False,False,False,False,False,False,False,False,False,False,False,False,True,False,False,False,False,True,True,False,True,False,False,False,True
3
+ 13.29,0.086,135.99,2009,False,False,False,False,True,False,False,False,False,False,False,False,False,False,False,False,False,False,False,True,True,False,True,False,False,False,True
4
+ 9.99,0.09,125.79,1987,False,True,False,False,False,False,False,True,False,False,False,False,False,False,False,False,False,False,False,False,False,False,True,False,False,True,False
5
+ 10.72,0.049,92.94,1998,True,False,False,False,False,False,False,False,False,True,False,False,False,False,False,False,False,True,False,False,False,True,False,True,True,False,False
X_test.json ADDED
The diff for this file is too large to render. See raw diff
 
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Import necessary libraries
2
+ import numpy as np
3
+ import joblib # For loading the serialized model
4
+ import pandas as pd # For data manipulation
5
+ from flask import Flask, request, jsonify # For creating the Flask API
6
+
7
+ superkart_api = Flask(__name__)
8
+
9
+ model = joblib.load('superkart.joblib')
10
+
11
+ @superkart_api.get('/')
12
+ def home():
13
+ return "Welcome to the SuperKart Sales Prediction API!"
14
+
15
+ @superkart_api.post('/predict')
16
+ def predict():
17
+ """
18
+ API endpoint to predict sales using the trained model.
19
+ Expects a JSON payload with the features required by the model.
20
+ """
21
+ try:
22
+ # Get JSON data from request
23
+ data = request.get_json()
24
+
25
+ # Convert JSON data to DataFrame
26
+ input_data = pd.DataFrame([data])
27
+
28
+ # Make prediction using the loaded model
29
+ prediction = model.predict(input_data)
30
+
31
+ # Return the prediction as JSON
32
+ return jsonify({'predicted_sales': prediction[0]})
33
+
34
+ except Exception as e:
35
+ return jsonify({'error': str(e)}), 400
36
+
37
+ @superkart_api.post('/predict/batch')
38
+ def predict_batch():
39
+ """
40
+ API endpoint to predict sales for a batch of inputs using the trained model.
41
+ Expects a JSON payload with a list of feature dictionaries.
42
+ """
43
+ try:
44
+ file = request.files['file']
45
+
46
+ # Read the CSV file into a Pandas DataFrame
47
+ input_data = pd.read_csv(file)
48
+
49
+ # Make predictions using the loaded model
50
+ predictions = model.predict(input_data)
51
+
52
+ # Return the predictions as JSON
53
+ return jsonify({'predicted_sales': predictions.tolist()})
54
+
55
+ except Exception as e:
56
+ return jsonify({'error': str(e)}), 400
57
+
58
+ if __name__ == '__main__':
59
+ superkart_api.run(host='0.0.0.0', port=5001, debug=True)
requirements.txt ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
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]
11
+ streamlit==1.43.2
superkart.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eab8a459bddc5a7f7ef4714723816c9b493fc79be50361b9ce8bf474a93f3374
3
+ size 2772361