Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -38,9 +38,9 @@ def predict_sales():
|
|
| 38 |
Returns predicted sales value.
|
| 39 |
"""
|
| 40 |
data = request.get_json()
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
'Store_Establishment_Year': data['Store_Establishment_Year'],
|
| 45 |
'Product_MRP': data['Product_MRP'],
|
| 46 |
'Product_Weight': data['Product_Weight'],
|
|
@@ -50,21 +50,21 @@ def predict_sales():
|
|
| 50 |
'Store_Location_City_Type': data['Store_Location_City_Type'],
|
| 51 |
'Store_Size': data['Store_Size'],
|
| 52 |
'Product_Allocated_Area': data['Product_Allocated_Area'],
|
| 53 |
-
'
|
| 54 |
'Store_Type': data['Store_Type'],
|
| 55 |
# Add or remove features per your model input
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
|
| 69 |
|
| 70 |
# Batch prediction endpoint (POST)
|
|
|
|
| 38 |
Returns predicted sales value.
|
| 39 |
"""
|
| 40 |
data = request.get_json()
|
| 41 |
+
try:
|
| 42 |
+
# Extract features for prediction (replace keys with your exact feature names)
|
| 43 |
+
features = {
|
| 44 |
'Store_Establishment_Year': data['Store_Establishment_Year'],
|
| 45 |
'Product_MRP': data['Product_MRP'],
|
| 46 |
'Product_Weight': data['Product_Weight'],
|
|
|
|
| 50 |
'Store_Location_City_Type': data['Store_Location_City_Type'],
|
| 51 |
'Store_Size': data['Store_Size'],
|
| 52 |
'Product_Allocated_Area': data['Product_Allocated_Area'],
|
| 53 |
+
'Product_Id': data['Product_Id'],
|
| 54 |
'Store_Type': data['Store_Type'],
|
| 55 |
# Add or remove features per your model input
|
| 56 |
+
}
|
| 57 |
+
# Convert to DataFrame for model input
|
| 58 |
+
input_df = pd.DataFrame([features])
|
| 59 |
+
# Predict sales
|
| 60 |
+
predicted_sales = model.predict(input_df)[0]
|
| 61 |
+
# Convert to float and round for JSON serialization
|
| 62 |
+
predicted_sales = round(float(predicted_sales), 2)
|
| 63 |
+
|
| 64 |
+
return jsonify({'Predicted_Sales': predicted_sales})
|
| 65 |
+
except Exception as e:
|
| 66 |
+
return jsonify({'error': str(e)}), 400
|
| 67 |
+
|
| 68 |
|
| 69 |
|
| 70 |
# Batch prediction endpoint (POST)
|