Quantum9999 commited on
Commit
7b066a8
·
verified ·
1 Parent(s): 9ddf179

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +16 -16
app.py CHANGED
@@ -38,9 +38,9 @@ def predict_sales():
38
  Returns predicted sales value.
39
  """
40
  data = request.get_json()
41
-
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,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
- 'Product_id': data['Product_id'],
54
  'Store_Type': data['Store_Type'],
55
  # Add or remove features per your model input
56
- }
57
-
58
- # Convert to DataFrame for model input
59
- input_df = pd.DataFrame([features])
60
-
61
- # Predict sales
62
- predicted_sales = model.predict(input_df)[0]
63
-
64
- # Convert to float and round for JSON serialization
65
- predicted_sales = round(float(predicted_sales), 2)
66
-
67
- return jsonify({'Predicted_Sales': predicted_sales})
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)