| |
| import numpy as np |
| import joblib |
| import pandas as pd |
| from flask import Flask, request, jsonify |
|
|
| |
| super_kart_predictor_api = Flask("SuperKart revenue Predictor") |
|
|
| |
| model = joblib.load("super_kart_xgb_prediction_model_v1_0.joblib") |
|
|
| |
| @super_kart_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 revenue Prediction API!" |
|
|
| |
| @super_kart_predictor_api.post('/v1/revenue') |
| def predict_revenue(): |
| """ |
| This function handles POST requests to the '/v1/revenue' endpoint. |
| It expects a JSON payload containing property details and returns |
| the predicted revenue as a JSON response. |
| """ |
| |
| superkart_paramX_data = request.get_json() |
|
|
| |
| sample = { |
| 'Product_Weight': superkart_paramX_data['Product_Weight'], |
| 'Product_Allocated_Area': superkart_paramX_data['Product_Allocated_Area'], |
| 'Store_Establishment_Year': superkart_paramX_data['Store_Establishment_Year'], |
| 'Product_MRP': superkart_paramX_data['Product_MRP'], |
| 'Product_Sugar_Content': superkart_paramX_data['Product_Sugar_Content'], |
| 'Product_Type': superkart_paramX_data['Product_Type'], |
| 'Store_Size': superkart_paramX_data['Store_Size'], |
| 'Store_Location_City_Type': superkart_paramX_data['Store_Location_City_Type'], |
| 'Store_Type': superkart_paramX_data['Store_Type'] |
| } |
|
|
| |
| input_data = pd.DataFrame([sample]) |
|
|
| |
| predicted_revenue = model.predict(input_data)[0] |
|
|
| |
| predicted_revenue = round(float(predicted_revenue), 2) |
|
|
| |
| return jsonify({'Predicted revenue (in dollars)': predicted_revenue}) |
|
|
| |
| if __name__ == '__main__': |
| super_kart_predictor_api.run(debug=True) |
|
|