|
|
import joblib |
|
|
import pandas as pd |
|
|
from flask import Flask, request, jsonify |
|
|
|
|
|
|
|
|
sales_revenue_predictor_api = Flask("Product Sales Revenue Predictor") |
|
|
|
|
|
|
|
|
model = joblib.load("product_sales_revenue_prediction_model_v1_0.joblib") |
|
|
|
|
|
|
|
|
@sales_revenue_predictor_api.get('/') |
|
|
def home(): |
|
|
return "Welcome to the Product Sales Revenue Prediction API" |
|
|
|
|
|
|
|
|
@sales_revenue_predictor_api.post('/v1/product_sales_revenue') |
|
|
def predict_churn(): |
|
|
|
|
|
product_data = request.get_json() |
|
|
|
|
|
|
|
|
sample = { |
|
|
'Product_Weight': product_data.get('Product_Weight'), |
|
|
'Product_Sugar_Content': product_data.get('Product_Sugar_Content'), |
|
|
'Product_Allocated_Area': product_data.get('Product_Allocated_Area'), |
|
|
'Product_Type': product_data.get('Product_Type'), |
|
|
'Product_MRP': product_data.get('Product_MRP'), |
|
|
'Store_Id': product_data.get('Store_Id'), |
|
|
'Store_Establishment_Year': product_data.get('Store_Establishment_Year'), |
|
|
'Store_Size': product_data.get('Store_Size'), |
|
|
'Store_Location_City_Type': product_data.get('Store_Location_City_Type'), |
|
|
'Store_Type': product_data.get('Store_Type') |
|
|
} |
|
|
|
|
|
|
|
|
input_data = pd.DataFrame([sample]) |
|
|
|
|
|
|
|
|
predicted_sales = model.predict(input_data).tolist()[0] |
|
|
|
|
|
|
|
|
predicted_sales = round(float(predicted_sales), 2) |
|
|
|
|
|
|
|
|
|
|
|
return jsonify({'Prediction': predicted_sales}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
app.run(debug=True) |
|
|
|