deepacsr commited on
Commit
03d40c5
·
verified ·
1 Parent(s): e5320ec

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +23 -8
app.py CHANGED
@@ -83,15 +83,30 @@ def predict_sales_batch():
83
  # Read the CSV file into a Pandas DataFrame
84
  input_data = pd.read_csv(file)
85
 
86
- # Make predictions for all product details in the DataFrame
87
- predicted_sales = model.predict(input_data).tolist()
88
-
89
- # Create a dictionary of predictions with product IDs as keys
90
  product_ids = input_data['Product_Id'].tolist()
91
- output_dict = dict(zip(product_ids, predicted_sales))
92
-
93
- # Return the predictions dictionary as a JSON response
94
- return jsonify(output_dict)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
 
96
  # Run the Flask application in debug mode if this script is executed directly
97
  if __name__ == '__main__':
 
83
  # Read the CSV file into a Pandas DataFrame
84
  input_data = pd.read_csv(file)
85
 
86
+ # Save Product_Id for mapping in output
 
 
 
87
  product_ids = input_data['Product_Id'].tolist()
88
+
89
+ # Columns that your model does NOT need
90
+ drop_cols = [
91
+ 'Product_Id',
92
+ 'Store_Id',
93
+ 'Store_Establishment_Year',
94
+ 'Product_Store_Sales_Total' # target column
95
+ ]
96
+
97
+ # Drop only columns that exist in the CSV
98
+ input_data = df.drop(columns=[c for c in drop_cols if c in input_data.columns])
99
+
100
+ # Now df contains ONLY the features used for training
101
+ predictions = model.predict(input_data)
102
+
103
+ # Convert NumPy types → Python float
104
+ predictions = [float(p) for p in predictions]
105
+
106
+ # Prepare output with Product_Id as keys
107
+ output = dict(zip(product_ids, predictions))
108
+
109
+ return jsonify(output)
110
 
111
  # Run the Flask application in debug mode if this script is executed directly
112
  if __name__ == '__main__':