3morrrrr commited on
Commit
da15a76
·
verified ·
1 Parent(s): 4d3ac9f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -8
app.py CHANGED
@@ -92,21 +92,37 @@ def update_assignments(assignments_df, creators_df):
92
 
93
  def generate_full_schedule():
94
  try:
 
95
  chatter_files = [
96
- os.path.join(PROCESSED_FOLDER, "Updated_overnight_file.xlsx"),
97
- os.path.join(PROCESSED_FOLDER, "Updated_day_file.xlsx"),
98
- os.path.join(PROCESSED_FOLDER, "Updated_prime_file.xlsx"),
99
  ]
100
- creators_file = os.path.join(PROCESSED_FOLDER, "creators_file.xlsx")
101
 
102
- if not all(os.path.exists(f) for f in chatter_files + [creators_file]):
103
- return "Missing required files. Please complete the 'Generate Main Accounts' step first."
 
 
 
 
 
 
 
 
104
 
105
- full_schedule = generate_schedule(chatter_files, creators_file)
106
- return full_schedule
 
 
 
 
 
 
 
107
  except Exception as e:
108
  return f"Error generating schedule: {e}"
109
 
 
110
  # Gradio Interface
111
  def app():
112
  with gr.Blocks() as interface:
 
92
 
93
  def generate_full_schedule():
94
  try:
95
+ # Load chatter files as DataFrames
96
  chatter_files = [
97
+ pd.read_excel(os.path.join(PROCESSED_FOLDER, "Updated_overnight_file.xlsx")),
98
+ pd.read_excel(os.path.join(PROCESSED_FOLDER, "Updated_day_file.xlsx")),
99
+ pd.read_excel(os.path.join(PROCESSED_FOLDER, "Updated_prime_file.xlsx")),
100
  ]
 
101
 
102
+ # Load processed creators file as a DataFrame
103
+ creators_file_path = os.path.join(PROCESSED_FOLDER, "creators_file.xlsx")
104
+ if not os.path.exists(creators_file_path):
105
+ return "Processed creator file is missing. Please complete the 'Generate Main Accounts' step first."
106
+
107
+ account_data = pd.read_excel(creators_file_path)
108
+
109
+ # Validate the required columns in creators file
110
+ if not {"Creator", "ActiveFans"}.issubset(account_data.columns):
111
+ raise KeyError("The processed creators file must contain 'Creator' and 'ActiveFans' columns.")
112
 
113
+ # Generate the schedule
114
+ full_schedule = generate_schedule(chatter_files, account_data)
115
+
116
+ # Optionally save the generated schedules for each shift
117
+ for shift_name, schedule_data in full_schedule.items():
118
+ shift_file = os.path.join(PROCESSED_FOLDER, f"Final_Schedule_{shift_name}.xlsx")
119
+ pd.DataFrame(schedule_data).to_excel(shift_file, index=False)
120
+
121
+ return "Full schedules generated successfully!"
122
  except Exception as e:
123
  return f"Error generating schedule: {e}"
124
 
125
+
126
  # Gradio Interface
127
  def app():
128
  with gr.Blocks() as interface: