Hugo014 commited on
Commit
27dd8c0
·
verified ·
1 Parent(s): fbde73a

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +30 -30
app.py CHANGED
@@ -73,41 +73,41 @@ def predict_sales():
73
  return jsonify({'Predicted Sales Total (in dollars)': predicted_sales})
74
 
75
 
76
- @super_kart_api.post('/v1/salesbatch')
77
- def predict_sales_batch():
78
- """
79
- This function handles POST requests to the '/v1/salesbatch' endpoint.
80
- It expects a CSV file containing product details for multiple products
81
- and returns the predicted sales totals as a dictionary in the JSON response.
82
- """
83
- if 'file' not in request.files:
84
- return jsonify({'error': 'No file part in the request'}), 400
85
- file = request.files['file']
86
- try:
87
- data = pd.read_csv(file)
88
- except Exception as e:
89
- return jsonify({'error': f'Failed to read CSV: {str(e)}'}), 400
90
 
91
- # Apply one-hot encoding
92
- data = pd.get_dummies(data, columns=['Product_Type', 'Store_Type'], drop_first=True)
93
 
94
- # Apply ordinal encoding
95
- sugar_mapping = {'No Sugar': 0, 'Low Sugar': 1, 'Regular': 2}
96
- size_mapping = {'Small': 0, 'Medium': 1, 'High': 2}
97
- city_mapping = {'Tier 3': 0, 'Tier 2': 1, 'Tier 1': 2}
98
- data['Product_Sugar_Content'] = data['Product_Sugar_Content'].map(sugar_mapping)
99
- data['Store_Size'] = data['Store_Size'].map(size_mapping)
100
- data['Store_Location_City_Type'] = data['Store_Location_City_Type'].map(city_mapping)
101
 
102
- # Align with expected columns
103
- data = data.reindex(columns=EXPECTED_COLUMNS, fill_value=0)
104
 
105
- # Make predictions
106
- preds = model.predict(data)
107
- results = preds.round(2).tolist()
108
- response = {str(i): float(val) for i, val in enumerate(results)}
109
 
110
- return jsonify(response)
111
 
112
 
113
  if __name__ == '__main__':
 
73
  return jsonify({'Predicted Sales Total (in dollars)': predicted_sales})
74
 
75
 
76
+ # @super_kart_api.post('/v1/salesbatch')
77
+ # def predict_sales_batch():
78
+ # """
79
+ # This function handles POST requests to the '/v1/salesbatch' endpoint.
80
+ # It expects a CSV file containing product details for multiple products
81
+ # and returns the predicted sales totals as a dictionary in the JSON response.
82
+ # """
83
+ # if 'file' not in request.files:
84
+ # return jsonify({'error': 'No file part in the request'}), 400
85
+ # file = request.files['file']
86
+ # try:
87
+ # data = pd.read_csv(file)
88
+ # except Exception as e:
89
+ # return jsonify({'error': f'Failed to read CSV: {str(e)}'}), 400
90
 
91
+ # # Apply one-hot encoding
92
+ # data = pd.get_dummies(data, columns=['Product_Type', 'Store_Type'], drop_first=True)
93
 
94
+ # # Apply ordinal encoding
95
+ # sugar_mapping = {'No Sugar': 0, 'Low Sugar': 1, 'Regular': 2}
96
+ # size_mapping = {'Small': 0, 'Medium': 1, 'High': 2}
97
+ # city_mapping = {'Tier 3': 0, 'Tier 2': 1, 'Tier 1': 2}
98
+ # data['Product_Sugar_Content'] = data['Product_Sugar_Content'].map(sugar_mapping)
99
+ # data['Store_Size'] = data['Store_Size'].map(size_mapping)
100
+ # data['Store_Location_City_Type'] = data['Store_Location_City_Type'].map(city_mapping)
101
 
102
+ # # Align with expected columns
103
+ # data = data.reindex(columns=EXPECTED_COLUMNS, fill_value=0)
104
 
105
+ # # Make predictions
106
+ # preds = model.predict(data)
107
+ # results = preds.round(2).tolist()
108
+ # response = {str(i): float(val) for i, val in enumerate(results)}
109
 
110
+ # return jsonify(response)
111
 
112
 
113
  if __name__ == '__main__':