cheeka84 commited on
Commit
20b2fdd
·
verified ·
1 Parent(s): d718c46

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +20 -15
app.py CHANGED
@@ -73,27 +73,32 @@ def sales_price_batch():
73
  file = request.files['file']
74
 
75
  # Read the CSV file into a Pandas DataFrame
76
- input_data = pd.read_csv(file)
77
- input_data['Store_Age'] = 2025 - input_data['Store_Establishment_Year']
78
 
79
- product_ids = input_data['Product_Id'].tolist() # Assuming 'Id' is the product ID column
80
- store_ids = input_data['Store_Id'].tolist() # Assuming 'Id' is the store ID column
81
- input_data = input_data.drop(['Product_Id', 'Store_Id', 'Store_Establishment_Year'], axis=1)
82
 
83
  # Apply same transformations
84
  #input_transformed = preprocessor.transform(input_data)
85
 
86
  # Make predictions for all properties in the DataFrame (get log_prices)
87
- predicted_sales = model.predict(input_data).tolist()
88
-
89
- # Calculate sales
90
- predicted_sales = round(float(predicted_sales), 2)
91
-
92
- # Create a dictionary of predictions with property IDs as keys
93
- output_dict = dict(zip(product_ids, store_ids, predicted_sales)) # Use actual prices
94
-
95
- # Return the predictions dictionary as a JSON response
96
- return output_dict
 
 
 
 
 
97
 
98
  # Run the Flask application in debug mode if this script is executed directly
99
  if __name__ == '__main__':
 
73
  file = request.files['file']
74
 
75
  # Read the CSV file into a Pandas DataFrame
76
+ input_data_batch = pd.read_csv(file)
77
+ input_data_batch['Store_Age'] = 2025 - input_data_batch['Store_Establishment_Year']
78
 
79
+ product_ids = input_data_batch['Product_Id'].tolist() # Assuming 'Id' is the product ID column
80
+ store_ids = input_data_batch['Store_Id'].tolist() # Assuming 'Id' is the store ID column
81
+ input_data_batch = input_data_batch.drop(['Product_Id', 'Store_Id', 'Store_Establishment_Year'], axis=1)
82
 
83
  # Apply same transformations
84
  #input_transformed = preprocessor.transform(input_data)
85
 
86
  # Make predictions for all properties in the DataFrame (get log_prices)
87
+ predictions = model.predict(input_data_batch).tolist()
88
+
89
+ # Round predictions
90
+ predicted_sales = [round(float(x), 2) for x in predictions]
91
+
92
+ # Structure output as a list of dicts
93
+ output_dict = [
94
+ {
95
+ "Product_Id": pid,
96
+ "Store_Id": sid,
97
+ "Predicted_Sales": psale
98
+ }
99
+ for pid, sid, psale in zip(product_ids, store_ids, predicted_sales)
100
+ ]
101
+ return jsonify({"predictions": output_dict})
102
 
103
  # Run the Flask application in debug mode if this script is executed directly
104
  if __name__ == '__main__':