Spaces:
Sleeping
Sleeping
Download app.py from gigcode/SuperKartBackend: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/spaces/gigcode/SuperKartBackend/resolve/main/app.py
- Command line
-
hf download hf://spaces/gigcode/SuperKartBackend/app.py
-
curl -L -o app.py https://huggingface.co/spaces/gigcode/SuperKartBackend/resolve/main/app.py
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") | |
| def home(): | |
| return "SuperKart Sales Forecasting API is alive" | |
| # API endpoint to match the frontend call | |
| 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) | |