3morrrrr commited on
Commit
514ef0e
·
verified ·
1 Parent(s): 78977a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -4
app.py CHANGED
@@ -53,15 +53,29 @@ def generate_main_accounts(updated_data=None):
53
 
54
  try:
55
  if updated_data is not None:
56
- # If updated data is provided, save it back as the new assignments
 
 
 
 
 
 
 
 
 
57
  assignments = {
58
- shift: pd.DataFrame([record for record in updated_data if record["Shift"] == shift.capitalize()])
 
 
 
59
  for shift in ["overnight", "day", "prime"]
60
  }
 
 
61
  save_processed_files(assignments, PROCESSED_FOLDER)
62
- return "Assignments updated successfully!", pd.concat(assignments.values())
63
 
64
- # Generate assignments for preview
65
  main_assignments = assign_main_accounts(creators_file, chatter_files)
66
  save_processed_files(main_assignments, PROCESSED_FOLDER)
67
 
@@ -80,6 +94,7 @@ def generate_main_accounts(updated_data=None):
80
 
81
 
82
 
 
83
  def generate_full_schedule():
84
  chatter_files = [
85
  os.path.join(PROCESSED_FOLDER, "Updated_overnight_file.xlsx"),
@@ -153,6 +168,7 @@ def app():
153
 
154
 
155
 
 
156
  # Launch Gradio App
157
  if __name__ == "__main__":
158
  app().launch()
 
53
 
54
  try:
55
  if updated_data is not None:
56
+ # Ensure updated_data is in the correct format
57
+ if isinstance(updated_data, pd.DataFrame):
58
+ updated_data = updated_data.to_dict(orient="records")
59
+
60
+ # Validate updated data structure
61
+ for record in updated_data:
62
+ if not isinstance(record, dict):
63
+ raise ValueError(f"Invalid record in updated data: {record}")
64
+
65
+ # Group updated data by shift
66
  assignments = {
67
+ shift.lower(): [
68
+ {key: record[key] for key in record if key != "Shift"} # Remove the Shift column
69
+ for record in updated_data if record["Shift"] == shift.capitalize()
70
+ ]
71
  for shift in ["overnight", "day", "prime"]
72
  }
73
+
74
+ # Save updated assignments
75
  save_processed_files(assignments, PROCESSED_FOLDER)
76
+ return "Assignments updated successfully!", pd.DataFrame(updated_data)
77
 
78
+ # Generate new assignments if no updated data is provided
79
  main_assignments = assign_main_accounts(creators_file, chatter_files)
80
  save_processed_files(main_assignments, PROCESSED_FOLDER)
81
 
 
94
 
95
 
96
 
97
+
98
  def generate_full_schedule():
99
  chatter_files = [
100
  os.path.join(PROCESSED_FOLDER, "Updated_overnight_file.xlsx"),
 
168
 
169
 
170
 
171
+
172
  # Launch Gradio App
173
  if __name__ == "__main__":
174
  app().launch()