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