|
|
import joblib |
|
|
import pandas as pd |
|
|
from flask import Flask, request, jsonify |
|
|
|
|
|
|
|
|
app = Flask("Product Sales Predictor") |
|
|
|
|
|
|
|
|
model = joblib.load("product_sales_predictor_v1_0.joblib") |
|
|
|
|
|
|
|
|
@app.get('/') |
|
|
def home(): |
|
|
return "Welcome to the Product Sales Prediction API" |
|
|
|
|
|
|
|
|
@app.post('/v1/product') |
|
|
def predict_sales(): |
|
|
|
|
|
product_data = request.get_json() |
|
|
|
|
|
|
|
|
sample = { |
|
|
'Product_Weight': product_data['Product_Weight'], |
|
|
'Product_Sugar_Content': product_data['Product_Sugar_Content'], |
|
|
'Product_Allocated_Area': product_data['Product_Allocated_Area'], |
|
|
'Product_Type': product_data['Product_Type'], |
|
|
'Product_MRP': product_data['Product_MRP'], |
|
|
'Store_Establishment_Year': product_data['Store_Establishment_Year'], |
|
|
'Store_Id': product_data['Store_Id'], |
|
|
'Store_Size': product_data['Store_Size'], |
|
|
'Store_Location_City_Type': product_data['Store_Location_City_Type'], |
|
|
'Store_Type': product_data['Store_Type'] |
|
|
} |
|
|
|
|
|
|
|
|
input_data = pd.DataFrame([sample]) |
|
|
|
|
|
|
|
|
prediction = model.predict(input_data).tolist()[0] |
|
|
|
|
|
|
|
|
return jsonify({'Predicted_Sales': prediction}) |
|
|
|
|
|
|
|
|
@app.post('/v1/productbatch') |
|
|
def predict_sales_batch(): |
|
|
|
|
|
file = request.files['file'] |
|
|
|
|
|
|
|
|
input_data = pd.read_csv(file) |
|
|
|
|
|
|
|
|
predictions = model.predict(input_data).tolist() |
|
|
|
|
|
|
|
|
return jsonify({'Predicted_Sales': predictions}) |
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
app.run(debug=True) |
|
|
|