|
|
import joblib |
|
|
import pandas as pd |
|
|
from flask import Flask, request, jsonify |
|
|
|
|
|
|
|
|
sales_predictor_api = Flask("SuperKart Sales Predictor") |
|
|
|
|
|
|
|
|
model = joblib.load("superkart_model_v1_0.joblib") |
|
|
|
|
|
|
|
|
@sales_predictor_api.get('/') |
|
|
def home(): |
|
|
return "Welcome to the SuperKart Sales Predictor API!" |
|
|
|
|
|
|
|
|
@sales_predictor_api.post('/v1/productstore') |
|
|
def predict_sales(): |
|
|
|
|
|
Prodstore_data = request.get_json() |
|
|
|
|
|
|
|
|
sample = { |
|
|
'Product_Weight': Prodstore_data['Product_Weight'], |
|
|
'Product_Allocated_Area': Prodstore_data['Product_Allocated_Area'], |
|
|
'Product_MRP': Prodstore_data['Product_MRP'], |
|
|
'Store_Establishment_Year': Prodstore_data['Store_Establishment_Year'], |
|
|
'Product_Sugar_Content': Prodstore_data['Product_Sugar_Content'], |
|
|
'Product_Type': Prodstore_data['Product_Type'], |
|
|
'Store_Size': Prodstore_data['Store_Size'], |
|
|
'Store_Location_City_Type': Prodstore_data['Store_Location_City_Type'], |
|
|
'Store_Type': Prodstore_data['Store_Type'] |
|
|
} |
|
|
|
|
|
|
|
|
input_data = pd.DataFrame([sample]) |
|
|
|
|
|
|
|
|
prediction = model.predict(input_data).tolist()[0] |
|
|
|
|
|
|
|
|
return jsonify({'Prediction': prediction}) |
|
|
|
|
|
|
|
|
app = Flask(__name__) |
|
|
if __name__ == '__main__': |
|
|
app.run(debug=True) |
|
|
|