prashant91 commited on
Commit
ec3f08a
·
verified ·
1 Parent(s): cf6f2dc

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. app.py +51 -0
  2. best_sales_model.pkl +3 -0
  3. requirements.txt +11 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Flask app with a name
8
+ superkart_api = Flask("SuperKart Sales Predictor")
9
+
10
+ # Load the trained churn prediction model
11
+ model = joblib.load("best_sales_model.pkl")
12
+
13
+ # Define a route for the home page
14
+ @superkart_api.get('/')
15
+ def home():
16
+ return "Welcome to the SuperKart System"
17
+
18
+ # Define an endpoint to predict churn for a single customer
19
+ @superkart_api.post('/v1/sales')
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
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_MRP': data['Product_MRP'],
30
+ 'Store_Size': data['Store_Size'],
31
+ 'Store_Location_City_Type': data['Store_Location_City_Type'],
32
+ 'Store_Type': data['Store_Type'],
33
+ 'Product_Id_char': data['Product_Id_char'],
34
+ 'Store_Age': data['Store_Age'],
35
+ 'Product_Type_Category': data['Product_Type_Category'],
36
+ 'Store_Id': data['Store_Id']
37
+ }
38
+
39
+ # Convert the extracted data into a DataFrame
40
+ input_data = pd.DataFrame([sample])
41
+
42
+ # Make a churn prediction using the trained model
43
+ prediction = model.predict(input_data).tolist()[0]
44
+
45
+ # Return the prediction as a JSON response
46
+ return jsonify({'Sales': prediction})
47
+
48
+
49
+ # Run the Flask app in debug mode
50
+ if __name__ == '__main__':
51
+ superkart_api.run(debug=True)
best_sales_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1e54bbb34d2ac12b359137b917fbcf267b4c191d7b05304baf174c7cf2b9eb25
3
+ size 63810675
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