gigcode's picture
Upload folder using huggingface_hub
744d721 verified
Raw History Blame Contribute Delete
1.26 kB
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)