|
|
|
|
|
import numpy as np |
|
|
import pandas as pd |
|
|
import joblib |
|
|
from flask import Flask, request, jsonify |
|
|
|
|
|
|
|
|
superkart_revenue_predictor_api = Flask("SuperKart Sales Forecast API") |
|
|
|
|
|
|
|
|
model = joblib.load("superkart_prediction_model_v1_0.joblib") |
|
|
|
|
|
|
|
|
@superkart_revenue_predictor_api.get('/') |
|
|
def home(): |
|
|
""" |
|
|
Handles GET requests to the root URL. |
|
|
Returns a welcome message. |
|
|
""" |
|
|
return "Welcome to the SuperKart Sales Forecast API!" |
|
|
|
|
|
|
|
|
@superkart_revenue_predictor_api.post('/v1/forecast') |
|
|
def predict_sales(): |
|
|
""" |
|
|
Handles POST requests to the '/v1/forecast' endpoint. |
|
|
Accepts product and store details in JSON format and returns the predicted sales revenue. |
|
|
""" |
|
|
|
|
|
data = request.get_json() |
|
|
|
|
|
|
|
|
sample = { |
|
|
|
|
|
'Product_Weight': data['Product_Weight'], |
|
|
'Product_Sugar_Content': data['Product_Sugar_Content'], |
|
|
'Product_Allocated_Area': data['Product_Allocated_Area'], |
|
|
'Product_Type': data['Product_Type'], |
|
|
'Product_MRP': data['Product_MRP'], |
|
|
|
|
|
'Store_Establishment_Year': data['Store_Establishment_Year'], |
|
|
'Store_Size': data['Store_Size'], |
|
|
'Store_Location_City_Type': data['Store_Location_City_Type'], |
|
|
'Store_Type': data['Store_Type'] |
|
|
} |
|
|
|
|
|
|
|
|
input_df = pd.DataFrame([sample]) |
|
|
|
|
|
|
|
|
predicted_sales = model.predict(input_df)[0] |
|
|
|
|
|
|
|
|
predicted_sales = round(float(predicted_sales), 2) |
|
|
|
|
|
|
|
|
return jsonify({'Predicted_Sales_Revenue': predicted_sales}) |
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
superkart_revenue_predictor_api.run(debug=True) |
|
|
|