| | import joblib |
| | import pandas as pd |
| | from flask import Flask, request, jsonify |
| |
|
| | |
| | app = Flask("SuperKart Sales Forecast") |
| |
|
| | |
| | model = joblib.load("deployment_files/SuperKart_Sales_prediction_model_v1_0.joblib") |
| |
|
| | |
| | @app.get('/') |
| | def home(): |
| | return "Welcome to SuperKart Sales Forecast Prediction API" |
| |
|
| | |
| | @app.post('/v1/Store') |
| | def predict_churn(): |
| | |
| | Store_data = request.get_json() |
| |
|
| | |
| | sample = { |
| | 'Store_Id': customer_data['Store_Id'], |
| | 'Store_Size': customer_data['Store_Size'], |
| | 'Store_Location_City_Type': customer_data['Store_Location_City_Type'], |
| | 'Store_Type': customer_data['Store_Type'], |
| | 'Store_Age_Years': customer_data['Store_Age_Years'], |
| | 'Product_Type_Category': customer_data['Product_Type_Category'], |
| | 'Product_Weight': customer_data['Product_Weight'], |
| | 'Product_Allocated_Area': customStore_Age_Yearser_data['Product_Allocated_Area'], |
| | 'Product_MRP': customer_data['Product_MRP'], |
| | 'Product_Sugar_Content': customer_data['Product_Sugar_Content'], |
| | } |
| |
|
| | |
| | input_data = pd.DataFrame([sample]) |
| |
|
| | |
| | prediction = model.predict(input_data).tolist()[0] |
| |
|
| | |
| | |
| |
|
| | |
| | return jsonify({'Prediction': prediction_label}) |
| |
|
| | |
| | @app.post('/v1/Store_Id') |
| | def predict_churn_batch(): |
| | |
| | file = request.files['file'] |
| |
|
| | |
| | input_data = pd.read_csv(file) |
| |
|
| | |
| | predictions = [ |
| | for x in model.predict(input_data.drop("Store_Id",axis=1)).tolist() |
| | ] |
| |
|
| | store_id_list = input_data.Store_Id.values.tolist() |
| | output_dict = dict(zip(store_id_list, predictions)) |
| |
|
| | return output_dict |
| |
|
| | |
| | if __name__ == '__main__': |
| | app.run(debug=True) |
| |
|