Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,16 +1,12 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
| 3 |
-
import
|
| 4 |
-
from flask import Flask, request, jsonify # For creating the Flask API
|
| 5 |
|
| 6 |
# Initialize the Flask application
|
| 7 |
superkart_sales_api = Flask("SuperKart Sales Forecast API")
|
| 8 |
|
| 9 |
-
# Load the trained machine learning pipeline (preprocessor + model)
|
| 10 |
-
# Make sure this file is present next to app.py in your backend folder
|
| 11 |
model = joblib.load("sales_forecast_model_v1_0.joblib")
|
| 12 |
|
| 13 |
-
# Expected feature names (order doesn't matter for DataFrame, kept for clarity)
|
| 14 |
EXPECTED_FEATURES = [
|
| 15 |
"Product_Weight",
|
| 16 |
"Product_Allocated_Area",
|
|
@@ -31,21 +27,6 @@ def home():
|
|
| 31 |
Returns a simple welcome message and the expected schema.
|
| 32 |
"""
|
| 33 |
return "Welcome to the SuperKart Sales Forecast API!"
|
| 34 |
-
|
| 35 |
-
# jsonify({
|
| 36 |
-
# "message": ,
|
| 37 |
-
# "expected_payload": {
|
| 38 |
-
# "Product_Weight": "float",
|
| 39 |
-
# "Product_Allocated_Area": "float (0-1)",
|
| 40 |
-
# "Product_MRP": "float",
|
| 41 |
-
# "Store_Age": "int",
|
| 42 |
-
# "Product_Sugar_Content": "str (e.g., 'Regular', 'Low Sugar', 'No Sugar')",
|
| 43 |
-
# "Product_Type": "str (e.g., 'Snack Foods', 'Dairy', ...)",
|
| 44 |
-
# "Store_Size": "str (e.g., 'Small', 'Medium', 'High')",
|
| 45 |
-
#"Store_Location_City_Type": "str (e.g., 'Tier 1', 'Tier 2', 'Tier 3')",
|
| 46 |
-
#"Store_Type": "str (e.g., 'Supermarket Type 2', 'Departmental Store', ...)"
|
| 47 |
-
#}
|
| 48 |
-
#})
|
| 49 |
|
| 50 |
# Define an endpoint for single sales prediction (POST request)
|
| 51 |
@superkart_sales_api.post("/v1/sales")
|
|
@@ -86,7 +67,7 @@ def predict_sales():
|
|
| 86 |
|
| 87 |
# Predict sales (model outputs actual sales; no log transform)
|
| 88 |
pred = model.predict(input_df)[0]
|
| 89 |
-
pred = round(float(pred), 2)
|
| 90 |
|
| 91 |
return jsonify({"Predicted Product_Store_Sales_Total": pred})
|
| 92 |
|
|
|
|
| 1 |
+
import joblib
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from flask import Flask, request, jsonify
|
|
|
|
| 4 |
|
| 5 |
# Initialize the Flask application
|
| 6 |
superkart_sales_api = Flask("SuperKart Sales Forecast API")
|
| 7 |
|
|
|
|
|
|
|
| 8 |
model = joblib.load("sales_forecast_model_v1_0.joblib")
|
| 9 |
|
|
|
|
| 10 |
EXPECTED_FEATURES = [
|
| 11 |
"Product_Weight",
|
| 12 |
"Product_Allocated_Area",
|
|
|
|
| 27 |
Returns a simple welcome message and the expected schema.
|
| 28 |
"""
|
| 29 |
return "Welcome to the SuperKart Sales Forecast API!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# Define an endpoint for single sales prediction (POST request)
|
| 32 |
@superkart_sales_api.post("/v1/sales")
|
|
|
|
| 67 |
|
| 68 |
# Predict sales (model outputs actual sales; no log transform)
|
| 69 |
pred = model.predict(input_df)[0]
|
| 70 |
+
pred = round(float(pred), 2)
|
| 71 |
|
| 72 |
return jsonify({"Predicted Product_Store_Sales_Total": pred})
|
| 73 |
|