anchit48 commited on
Commit
61dc5a9
·
verified ·
1 Parent(s): 1537c51

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. app.py +51 -0
  2. requirements.txt +13 -0
  3. superkart_model.joblib +3 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Import necessary libraries
3
+ import numpy as np
4
+ import joblib # For loading the serialized model
5
+ import pandas as pd # For data manipulation
6
+ from flask import Flask, request, jsonify # For creating the Flask API
7
+
8
+ # Initialize Flask app with a name
9
+ superkart_api = Flask("SuperKart")
10
+
11
+ # Load the trained churn prediction model
12
+ model = joblib.load("superkart_model.joblib")
13
+
14
+ # Define a route for the home page
15
+ @superkart_api.get('/')
16
+ def home():
17
+ return "Welcome to the SuperKart System"
18
+
19
+ # Define an endpoint to predict churn for a single customer
20
+ @superkart_api.post('/v1/predict')
21
+ def predict_sales():
22
+ # Get JSON data from the request
23
+ data = request.get_json()
24
+
25
+ # Extract relevant customer features from the input data
26
+ sample = {
27
+ 'Product_Weight': data['Product_Weight'],
28
+ 'Product_Sugar_Content': data['Product_Sugar_Content'],
29
+ 'Product_Allocated_Area': data['Product_Allocated_Area'],
30
+ 'Product_MRP': data['Product_MRP'],
31
+ 'Store_Size': data['Store_Size'],
32
+ 'Store_Location_City_Type': data['Store_Location_City_Type'],
33
+ 'Store_Type': data['Store_Type'],
34
+ 'Product_Id_char': data['Product_Id_char'],
35
+ 'Store_Age_Years': data['Store_Age_Years'],
36
+ 'Product_Type_Category': data['Product_Type_Category']
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)
requirements.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pandas==2.2.2
2
+ numpy==2.0.2
3
+ scikit-learn==1.6.1
4
+ seaborn==0.13.2
5
+ joblib==1.4.2
6
+ xgboost==2.1.4
7
+ joblib==1.4.2
8
+ Werkzeug==2.2.2
9
+ flask==2.2.2
10
+ gunicorn==20.1.0
11
+ requests==2.32.3
12
+ uvicorn[standard]
13
+ streamlit==1.43.2
superkart_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5a78753daf8cc0618eca8cd3b2182f198dcaabf148fd760d7c872aa08468b529
3
+ size 162278