Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -2,46 +2,44 @@ import joblib
|
|
| 2 |
import pandas as pd
|
| 3 |
from flask import Flask, request, jsonify
|
| 4 |
|
| 5 |
-
# Initialize Flask app
|
| 6 |
sales_predictor_api = Flask("Product_Store_Total_Sales_Predictor")
|
| 7 |
|
| 8 |
-
# Load the trained
|
| 9 |
model = joblib.load("product_sales_total_prediction_v1_0.joblib")
|
| 10 |
|
| 11 |
-
#
|
| 12 |
@sales_predictor_api.get('/')
|
| 13 |
def home():
|
| 14 |
return "Welcome to the Product Store Total Sales Prediction API!"
|
| 15 |
|
| 16 |
-
#
|
| 17 |
@sales_predictor_api.post('/v1/product')
|
| 18 |
def predict_product_sales():
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
# Run the Flask app in debug mode
|
| 46 |
if __name__ == '__main__':
|
| 47 |
-
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
from flask import Flask, request, jsonify
|
| 4 |
|
| 5 |
+
# Initialize Flask app
|
| 6 |
sales_predictor_api = Flask("Product_Store_Total_Sales_Predictor")
|
| 7 |
|
| 8 |
+
# Load the trained model
|
| 9 |
model = joblib.load("product_sales_total_prediction_v1_0.joblib")
|
| 10 |
|
| 11 |
+
# Home endpoint
|
| 12 |
@sales_predictor_api.get('/')
|
| 13 |
def home():
|
| 14 |
return "Welcome to the Product Store Total Sales Prediction API!"
|
| 15 |
|
| 16 |
+
# Prediction endpoint
|
| 17 |
@sales_predictor_api.post('/v1/product')
|
| 18 |
def predict_product_sales():
|
| 19 |
+
try:
|
| 20 |
+
product_data = request.get_json()
|
| 21 |
+
|
| 22 |
+
# Construct input DataFrame
|
| 23 |
+
input_data = pd.DataFrame([{
|
| 24 |
+
'Product_Weight': product_data['Product_Weight'],
|
| 25 |
+
'Product_Sugar_Content': product_data['Product_Sugar_Content'],
|
| 26 |
+
'Product_Allocated_Area': product_data['Product_Allocated_Area'],
|
| 27 |
+
'Product_Type': product_data['Product_Type'],
|
| 28 |
+
'Product_MRP': product_data['Product_MRP'],
|
| 29 |
+
'Store_Establishment_Year': product_data['Store_Establishment_Year'],
|
| 30 |
+
'Store_Size': product_data['Store_Size'],
|
| 31 |
+
'Store_Location_City_Type': product_data['Store_Location_City_Type'],
|
| 32 |
+
'Store_Type': product_data['Store_Type'],
|
| 33 |
+
'Store_Age': 2025 - product_data['Store_Establishment_Year']
|
| 34 |
+
}])
|
| 35 |
+
|
| 36 |
+
# Predict
|
| 37 |
+
prediction = model.predict(input_data).tolist()[0]
|
| 38 |
+
return jsonify({'Product Store Sales Total': prediction})
|
| 39 |
+
|
| 40 |
+
except Exception as e:
|
| 41 |
+
return jsonify({'error': str(e)}), 500
|
| 42 |
+
|
| 43 |
+
# Run the app
|
|
|
|
|
|
|
| 44 |
if __name__ == '__main__':
|
| 45 |
+
sales_predictor_api.run(debug=True)
|