Disha252001 commited on
Commit
78cc03c
·
verified ·
1 Parent(s): 5ca9b6e

Upload folder using huggingface_hub

Browse files
Dockerfile ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9-slim
2
+
3
+ # Set the working directory inside the container
4
+ WORKDIR /app
5
+
6
+ # Copy all files from deployment_files into the container
7
+ COPY deployment_files/ ./
8
+
9
+ # Install dependencies
10
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
+
12
+ # Run the Flask app with Gunicorn
13
+ # Here: app.py is in deployment_files, Flask instance = store_sales_api
14
+ CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:store_sales_api"]
app.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ store_sales_api = Flask("SuperKart Store Sales Predictor")
9
+
10
+ # Load the trained machine learning model
11
+ model = joblib.load("store_sales_prediction_model_v1_0.joblib")
12
+
13
+ # Define a route for the home page (GET request)
14
+ @store_sales_api.get('/')
15
+ def home():
16
+ """
17
+ Root endpoint to check if the API is running.
18
+ """
19
+ return "Welcome to the SuperKart Store Sales Prediction API!"
20
+
21
+ # Define an endpoint for single store sales prediction (POST request)
22
+ @store_sales_api.post('/v1/sale')
23
+ def predict_store_sales():
24
+ """
25
+ Handles POST requests for predicting sales of a single store.
26
+ Expects JSON input with store details.
27
+ """
28
+ # Get JSON input
29
+ store_data = request.get_json()
30
+
31
+ # Extract relevant features (update according to your dataset)
32
+ sample = {
33
+ 'Store_Type': store_data['Store_Type'],
34
+ 'Location_Type': store_data['Location_Type'],
35
+ 'Region_Code': store_data['Region_Code'],
36
+ 'Holiday': store_data['Holiday'],
37
+ 'Discount': store_data['Discount']
38
+ # Add any other features you used during training
39
+ }
40
+
41
+ # Convert into DataFrame
42
+ input_data = pd.DataFrame([sample])
43
+
44
+ # Make prediction (direct Store_Sales prediction)
45
+ predicted_sales = model.predict(input_data)[0]
46
+
47
+ # Convert to Python float and round
48
+ predicted_sales = round(float(predicted_sales), 2)
49
+
50
+ # Return JSON response
51
+ return jsonify({'Predicted Store Sales': predicted_sales})
52
+
53
+ # Define an endpoint for batch prediction (POST request)
54
+ @store_sales_api.post('/v1/salebatch')
55
+ def predict_store_sales_batch():
56
+ """
57
+ Handles batch predictions for multiple stores.
58
+ Expects a CSV file with store details.
59
+ """
60
+ # Get uploaded CSV file
61
+ file = request.files['file']
62
+
63
+ # Read CSV into DataFrame
64
+ input_data = pd.read_csv(file)
65
+
66
+ # Make predictions
67
+ predicted_sales = model.predict(input_data).tolist()
68
+
69
+ # Convert to float and round
70
+ predicted_sales = [round(float(sale), 2) for sale in predicted_sales]
71
+
72
+ # Use Store IDs if available
73
+ if 'Store_ID' in input_data.columns:
74
+ store_ids = input_data['Store_ID'].tolist()
75
+ else:
76
+ store_ids = list(range(1, len(predicted_sales)+1)) # Fallback index
77
+
78
+ # Create dictionary of predictions
79
+ output_dict = dict(zip(store_ids, predicted_sales))
80
+
81
+ # Return JSON
82
+ return jsonify(output_dict)
83
+
84
+ # Run Flask app
85
+ if __name__ == '__main__':
86
+ store_sales_api.run(debug=True)
87
+
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_sales_prediction_model_v1_0.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b56473693f512415425d9cc2eed86e49774a1a7cd8a83a664397058963daefdc
3
+ size 63812691