SandeepMM commited on
Commit
38eed5f
·
verified ·
1 Parent(s): d0b13da

Update app.py

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