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