Spaces:
Sleeping
Sleeping
File size: 1,261 Bytes
7225de6 744d721 b06e991 7225de6 744d721 7225de6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import numpy as np
import joblib
import pandas as pd
from flask import Flask, request, jsonify
superkart_sales_api = Flask("superkart_sales_api")
model = joblib.load("deployment_files/superkart_sales_forecast_model_v1_0.joblib")
@superkart_sales_api.get("/")
def home():
return "SuperKart Sales Forecasting API is alive"
# API endpoint to match the frontend call
@superkart_sales_api.post("/v1/sales")
def predict_sales():
data = request.get_json()
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"],
"Store_Establishment_Year": data["Store_Establishment_Year"],
"Product_Type": data["Product_Type"],
}
pred = model.predict(pd.DataFrame([sample])).tolist()[0]
return jsonify({"Predicted Product_Store_Sales_Total": pred})
if __name__ == "__main__":
superkart_sales_api.run(debug=True)
|