|
import joblib
|
|
import pandas as pd
|
|
from flask import Flask, request, jsonify
|
|
|
|
|
|
app = Flask("SuperKart product sales revenue Prediction")
|
|
|
|
|
|
model_superkart = joblib.load("superkart_revenue_prediction_model_v1_0.joblib")
|
|
|
|
|
|
@app.get('/')
|
|
def home():
|
|
return "Welcome to the SuperKart Revenue Prediction API, created by Vrundav Gamit"
|
|
|
|
|
|
|
|
|
|
|
|
@app.post('/v1/predictrevenue')
|
|
|
|
def predict_revenue():
|
|
|
|
sales_data = request.get_json()
|
|
|
|
|
|
payload = {
|
|
'Product_Weight': sales_data['Product_Weight'],
|
|
'Product_Allocated_Area': sales_data['Product_Allocated_Area'],
|
|
'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'],
|
|
'Product_Sugar_Content': sales_data['Product_Sugar_Content'],
|
|
'Product_Type': sales_data['Product_Type']
|
|
}
|
|
|
|
|
|
input_data = pd.DataFrame([payload])
|
|
|
|
|
|
prediction = model_superkart.predict(input_data).tolist()[0]
|
|
|
|
|
|
return jsonify({'Prediction': prediction})
|
|
|
|
|
|
@app.post('/v1/predictrevenuebatch')
|
|
def predict_revenue_batch():
|
|
|
|
file = request.files['file']
|
|
|
|
|
|
input_data = pd.read_csv(file)
|
|
|
|
|
|
|
|
predictions = model_superkart.predict(input_data.drop("Product_Id",axis=1)).tolist()
|
|
|
|
product_id_list = input_data.product_Id.values.tolist()
|
|
output_dict = dict(zip(product_id_list, predictions))
|
|
|
|
return output_dict
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug=True)
|
|
|