| | |
| | import numpy as np |
| | import joblib |
| | import pandas as pd |
| | from flask import Flask, request, jsonify |
| |
|
| | |
| | superkart_sales_revenue_predictor_api = Flask("Superkart Product sales revenue Predictor") |
| |
|
| | |
| | model = joblib.load("superkart_revenue_prediction_model_v1_0.joblib") |
| |
|
| | |
| | @superkart_sales_revenue_predictor_api.get('/') |
| | def home(): |
| | """ |
| | This function handles GET requests to the root URL ('/') of the API. |
| | It returns a simple welcome message. |
| | """ |
| | return "Welcome to the Superkart sale revenue Prediction API!" |
| |
|
| | |
| | @superkart_sales_revenue_predictor_api.post('/v1/salesRevenue') |
| | def predict_product_sales_revenue(): |
| | """ |
| | This function handles POST requests to the '/v1/salesRevenue' endpoint. |
| | It expects a JSON payload containing property details and returns |
| | the predicted rental price as a JSON response. |
| | """ |
| | |
| | sales_data = request.get_json() |
| |
|
| | |
| | sample = { |
| | 'Product_Weight': sales_data['Product_Weight'], |
| | 'Product_Sugar_Content': sales_data['Product_Sugar_Content'], |
| | 'Product_Allocated_Area': sales_data['Product_Allocated_Area'], |
| | 'Product_Type': sales_data['Product_Type'], |
| | 'Product_MRP': sales_data['Product_MRP'], |
| | 'Store_Size': sales_data['Store_Size'], |
| | 'Store_Location_City_Type': sales_data['Store_Location_City_Type'], |
| | 'Store_Type': sales_data['Store_Type'], |
| | 'Store_Id': sales_data['Store_Id'] |
| | } |
| |
|
| | |
| | input_data = pd.DataFrame([sample]) |
| |
|
| | |
| | predicted_price = model.predict(input_data)[0] |
| |
|
| | |
| | predicted_price = round(float(predicted_price), 2) |
| | |
| | |
| |
|
| | |
| | return jsonify({'Predicted sales': predicted_price}) |
| |
|
| | |
| | if __name__ == '__main__': |
| | superkart_sales_revenue_predictor_api.run(debug=True) |
| |
|