tamizh1296 commited on
Commit
e96cd3d
·
verified ·
1 Parent(s): f21a0e8

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:superkart_sales_predictor_api"]
SuperKart_sales_prediction_model_v1_0.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:304efbec744043097c7349a7ea25cf13aa75b0592a670f9bcda49209efbf25d1
3
+ size 18545843
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Initialize the Flask application
8
+ superkart_sales_predictor_api = Flask("SuperKart Sales Predictor")
9
+
10
+ # Load the trained machine learning model
11
+ model = joblib.load("SuperKart_sales_prediction_model_v1_0.joblib")
12
+
13
+ # Define a route for the home page (GET request)
14
+ @superkart_sales_predictor_api.post('/v1/sales')
15
+ def predict_total_sales():
16
+ data = request.get_json()
17
+
18
+ # Check if batch or single
19
+ if isinstance(data, dict):
20
+ data = [data] # convert single input to list for consistency
21
+
22
+ samples = []
23
+ for property_data in data:
24
+ sample = {
25
+ 'product_weight': property_data['Product_Weight'],
26
+ 'product_sugar_content': property_data['Product_Sugar_Content'],
27
+ 'product_type': property_data['Product_Type'],
28
+ 'store_size': property_data['Store_Size'],
29
+ 'store_location_city_type': property_data['Store_Location_City_Type'],
30
+ 'store_type': property_data['Store_Type'],
31
+ 'store_establishment_year': property_data['Store_Establishment_Year'],
32
+ 'product_allocated_area': property_data['Product_Allocated_Area'],
33
+ 'product_mrp': property_data['Product_MRP']
34
+ }
35
+ samples.append(sample)
36
+
37
+ input_df = pd.DataFrame(samples)
38
+
39
+ # Predict log sales total
40
+ log_predictions = model.predict(input_df)
41
+
42
+ # Convert log-predicted values to actual sales
43
+ actual_predictions = [round(float(np.exp(pred)), 2) for pred in log_predictions]
44
+
45
+ return jsonify({'Predicted Product Store Sales Totals': actual_predictions})
46
+
47
+ if __name__ == '__main__':
48
+ app.run(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