Pushpak21 commited on
Commit
eb8e0f6
·
verified ·
1 Parent(s): 70d620a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  # Backend_files/app.y
2
  import joblib
3
  import pandas as pd
@@ -79,15 +80,18 @@ def predict_batch():
79
  'Store_Size', 'Store_Location_City_Type', 'Store_Type'
80
  ]
81
 
82
- # Check each record
83
  for i, record in enumerate(batch_data):
84
- missing = [f for f in required_fields if f not in record]
85
- if missing:
86
- return jsonify({"error": f"Missing fields in record {i}: {missing}"}), 400
87
 
88
  # Convert list of dicts to DataFrame
89
  df = pd.DataFrame(batch_data)
90
 
 
 
 
91
  # Predict
92
  predictions = Random_Forest_Loaded_Model.predict(df)
93
 
@@ -99,4 +103,4 @@ def predict_batch():
99
 
100
  # Run flask in debug mode
101
  if __name__ == '__main__':
102
- Superkart_Sales_Predictor_API.run(debug=False, host='0.0.0.0', port=7860)
 
1
+ %%writefile backend_files/app.py
2
  # Backend_files/app.y
3
  import joblib
4
  import pandas as pd
 
80
  'Store_Size', 'Store_Location_City_Type', 'Store_Type'
81
  ]
82
 
83
+ # Check each record for required fields
84
  for i, record in enumerate(batch_data):
85
+ missing = [f for f in required_fields if f not in record]
86
+ if missing:
87
+ return jsonify({"error": f"Missing fields in record {i}: {missing}"}), 400
88
 
89
  # Convert list of dicts to DataFrame
90
  df = pd.DataFrame(batch_data)
91
 
92
+ # Remove Product_Id and target column if present
93
+ columns_to_remove = ['Product_Id', 'Product_Store_Sales_Total']
94
+ df = df.drop(columns=[col for col in columns_to_remove if col in df.columns])
95
  # Predict
96
  predictions = Random_Forest_Loaded_Model.predict(df)
97
 
 
103
 
104
  # Run flask in debug mode
105
  if __name__ == '__main__':
106
+ Superkart_Sales_Predictor_API.run(debug=False, host='0.0.0.0', port=7860)