SandeepMM commited on
Commit
a9f037e
·
verified ·
1 Parent(s): 0a39ced

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +50 -50
app.py CHANGED
@@ -1,50 +1,50 @@
1
-
2
- import joblib
3
- import pandas as pd
4
- from flask import Flask, request, jsonify
5
-
6
- # Initialize Flask app with a name
7
- app = Flask("SuperKart Sales Predictor")
8
-
9
- # Load the trained churn prediction model
10
- model = joblib.load("XGBoostRegressor_BEST_Pipeline.joblib")
11
-
12
- # Define a route for the home page
13
- @app.get('/')
14
- def home():
15
- return "Welcome to the SuperKart Sales Prediction API"
16
-
17
- # Define an endpoint to predict churn for a single customer
18
- @app.post('/v1/product')
19
- def predict_churn():
20
- # Get JSON data from the request
21
- customer_data = request.get_json()
22
-
23
- # Extract relevant customer features from the input data
24
- sample = {
25
- 'Product_Id': customer_data['Product_Id'],
26
- 'Product_Weight': customer_data['Product_Weight'],
27
- 'Product_Sugar_Content': customer_data['Product_Sugar_Content'],
28
- 'Product_Allocated_Area': customer_data['Product_Allocated_Area'],
29
- 'Product_Type': customer_data['Product_Type'],
30
- 'Product_MRP': customer_data['Product_MRP'],
31
- 'Store_Id': customer_data['Store_Id'],
32
- 'Store_Establishment_Year': customer_data['Store_Establishment_Year'],
33
- 'Store_Size': customer_data['Store_Size'],
34
- 'Store_Location_City_Type': customer_data['Store_Location_City_Type'],
35
- 'Store_Type': customer_data['Store_Type']
36
- }
37
-
38
- # Convert the extracted data into a DataFrame
39
- input_data = pd.DataFrame([sample])
40
-
41
- # Make a Sales prediction using the trained model
42
- prediction = model.predict(input_data).tolist()[0]
43
-
44
- # Return the prediction as a JSON response
45
- return jsonify({'Prediction': prediction})
46
-
47
-
48
- # Run the Flask app in debug mode
49
- if __name__ == '__main__':
50
- app.run(debug=True)
 
1
+
2
+ import joblib
3
+ import pandas as pd
4
+ from flask import Flask, request, jsonify
5
+
6
+ # Initialize Flask app with a name
7
+ app = Flask("SuperKart Sales Predictor")
8
+
9
+ # Load the trained churn prediction model
10
+ model = joblib.load("XGBoostRegressor_BEST_Pipeline.joblib")
11
+
12
+ # Define a route for the home page
13
+ @app.get('/')
14
+ def home():
15
+ return "Welcome to the SuperKart Sales Prediction API"
16
+
17
+ # Define an endpoint to predict churn for a single customer
18
+ @app.post('/v1/product')
19
+ def predict_churn():
20
+ # Get JSON data from the request
21
+ customer_data = request.get_json()
22
+
23
+ # Extract relevant customer features from the input data
24
+ sample = {
25
+ 'Product_Id': customer_data['Product_Id'],
26
+ 'Product_Weight': customer_data['Product_Weight'],
27
+ 'Product_Sugar_Content': customer_data['Product_Sugar_Content'],
28
+ 'Product_Allocated_Area': customer_data['Product_Allocated_Area'],
29
+ 'Product_Type': customer_data['Product_Type'],
30
+ 'Product_MRP': customer_data['Product_MRP'],
31
+ 'Store_Id': customer_data['Store_Id'],
32
+ 'Store_Establishment_Year': customer_data['Store_Establishment_Year'],
33
+ 'Store_Size': customer_data['Store_Size'],
34
+ 'Store_Location_City_Type': customer_data['Store_Location_City_Type'],
35
+ 'Store_Type': customer_data['Store_Type']
36
+ }
37
+
38
+ # Convert the extracted data into a DataFrame
39
+ input_data = pd.DataFrame([sample])
40
+
41
+ # Make a Sales prediction using the trained model
42
+ prediction = model.predict(input_data).tolist()[0]
43
+
44
+ # Return the prediction as a JSON response
45
+ return jsonify({'Prediction': prediction})
46
+
47
+
48
+ # Run the Flask app in debug mode
49
+ if __name__ == '__main__':
50
+ app.run(debug=True)