Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -28,11 +28,13 @@ def predict_sales():
|
|
| 28 |
It expects a JSON payload containing store details and returns
|
| 29 |
the predicted sales as a JSON response.
|
| 30 |
"""
|
| 31 |
-
# Get the JSON data from the request body
|
| 32 |
-
data = request.get_json()
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
'Product_Weight': data['Product_Weight'],
|
| 37 |
'Product_Sugar_Content': data['Product_Sugar_Content'],
|
| 38 |
'Product_Allocated_Area': data['Product_Allocated_Area'],
|
|
@@ -40,19 +42,24 @@ def predict_sales():
|
|
| 40 |
'Store_Size': data['Store_Size'],
|
| 41 |
'Store_Location_City_Type': data['Store_Location_City_Type'],
|
| 42 |
'Store_Type': data['Store_Type'],
|
| 43 |
-
'
|
| 44 |
-
'
|
| 45 |
'Product_Category': data['Product_Category']
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
# Return the prediction
|
| 55 |
-
return jsonify({'Predicted Sales': predicted_sales})
|
| 56 |
|
| 57 |
|
| 58 |
# Run the Flask application in debug mode if this script is executed directly
|
|
|
|
| 28 |
It expects a JSON payload containing store details and returns
|
| 29 |
the predicted sales as a JSON response.
|
| 30 |
"""
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
try:
|
| 33 |
+
# Get the JSON data from the request body
|
| 34 |
+
data = request.get_json()
|
| 35 |
+
|
| 36 |
+
# Extract relevant features from the JSON data
|
| 37 |
+
sample = {
|
| 38 |
'Product_Weight': data['Product_Weight'],
|
| 39 |
'Product_Sugar_Content': data['Product_Sugar_Content'],
|
| 40 |
'Product_Allocated_Area': data['Product_Allocated_Area'],
|
|
|
|
| 42 |
'Store_Size': data['Store_Size'],
|
| 43 |
'Store_Location_City_Type': data['Store_Location_City_Type'],
|
| 44 |
'Store_Type': data['Store_Type'],
|
| 45 |
+
'Product_Code': data['Product_Code'],
|
| 46 |
+
'Store_Age': data['Store_Age'],
|
| 47 |
'Product_Category': data['Product_Category']
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
# Convert the extracted data into a Pandas DataFrame
|
| 52 |
+
input_data = pd.DataFrame([sample])
|
| 53 |
|
| 54 |
+
# Make prediction (get log_price)
|
| 55 |
+
sales_prediction = xgb_model.predict(input_data)[0]
|
| 56 |
|
| 57 |
+
# Return the prediction
|
| 58 |
+
return jsonify({'Sales': sales_prediction.tolist()})
|
| 59 |
+
except Exception as e:
|
| 60 |
+
print(f"Error in prediction: {e}")
|
| 61 |
+
return jsonify({'error': str(e)})
|
| 62 |
|
|
|
|
|
|
|
| 63 |
|
| 64 |
|
| 65 |
# Run the Flask application in debug mode if this script is executed directly
|