Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -106,6 +106,27 @@ def update_assignments(assignments_df, creators_df):
|
|
106 |
return "Assignments and Creator File updated successfully!", ZIP_FILE
|
107 |
except Exception as e:
|
108 |
return f"Error updating assignments: {e}", None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
def generate_full_schedule(creators_file_path, overnight_file_path, day_file_path, prime_file_path):
|
111 |
try:
|
@@ -203,15 +224,27 @@ def app():
|
|
203 |
prime_file = gr.File(label="Prime File", type="binary")
|
204 |
|
205 |
generate_schedule_btn = gr.Button("Generate Full Schedule")
|
206 |
-
overnight_schedule_output = gr.Dataframe(label="Overnight Schedule", interactive=
|
207 |
-
day_schedule_output = gr.Dataframe(label="Day Schedule", interactive=
|
208 |
-
prime_schedule_output = gr.Dataframe(label="Prime Schedule", interactive=
|
|
|
|
|
|
|
|
|
209 |
|
|
|
210 |
generate_schedule_btn.click(
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
|
216 |
return interface
|
217 |
|
@@ -224,3 +257,4 @@ if __name__ == "__main__":
|
|
224 |
|
225 |
|
226 |
|
|
|
|
106 |
return "Assignments and Creator File updated successfully!", ZIP_FILE
|
107 |
except Exception as e:
|
108 |
return f"Error updating assignments: {e}", None
|
109 |
+
|
110 |
+
def update_and_download_schedule(overnight_df, day_df, prime_df):
|
111 |
+
try:
|
112 |
+
# Save updated schedules to the processed folder
|
113 |
+
overnight_path = os.path.join(PROCESSED_FOLDER, "Updated_Overnight_Schedule.xlsx")
|
114 |
+
day_path = os.path.join(PROCESSED_FOLDER, "Updated_Day_Schedule.xlsx")
|
115 |
+
prime_path = os.path.join(PROCESSED_FOLDER, "Updated_Prime_Schedule.xlsx")
|
116 |
+
|
117 |
+
overnight_df.to_excel(overnight_path, index=False)
|
118 |
+
day_df.to_excel(day_path, index=False)
|
119 |
+
prime_df.to_excel(prime_path, index=False)
|
120 |
+
|
121 |
+
# Zip the updated files for download
|
122 |
+
with zipfile.ZipFile(ZIP_FILE, "w") as zipf:
|
123 |
+
zipf.write(overnight_path, arcname="Updated_Overnight_Schedule.xlsx")
|
124 |
+
zipf.write(day_path, arcname="Updated_Day_Schedule.xlsx")
|
125 |
+
zipf.write(prime_path, arcname="Updated_Prime_Schedule.xlsx")
|
126 |
+
|
127 |
+
return "Schedules updated and saved successfully!", ZIP_FILE
|
128 |
+
except Exception as e:
|
129 |
+
return f"Error updating schedules: {e}", None
|
130 |
|
131 |
def generate_full_schedule(creators_file_path, overnight_file_path, day_file_path, prime_file_path):
|
132 |
try:
|
|
|
224 |
prime_file = gr.File(label="Prime File", type="binary")
|
225 |
|
226 |
generate_schedule_btn = gr.Button("Generate Full Schedule")
|
227 |
+
overnight_schedule_output = gr.Dataframe(label="Overnight Schedule", interactive=True)
|
228 |
+
day_schedule_output = gr.Dataframe(label="Day Schedule", interactive=True)
|
229 |
+
prime_schedule_output = gr.Dataframe(label="Prime Schedule", interactive=True)
|
230 |
+
|
231 |
+
update_schedule_btn = gr.Button("Update and Download Schedule")
|
232 |
+
download_schedule_btn = gr.File(label="Download Updated Schedules", value=ZIP_FILE)
|
233 |
+
update_status = gr.Textbox(label="Update Status", interactive=False)
|
234 |
|
235 |
+
# Generate Schedule
|
236 |
generate_schedule_btn.click(
|
237 |
+
generate_full_schedule,
|
238 |
+
inputs=[creators_file, overnight_file, day_file, prime_file],
|
239 |
+
outputs=[overnight_schedule_output, day_schedule_output, prime_schedule_output]
|
240 |
+
)
|
241 |
+
|
242 |
+
# Update and Download Schedule
|
243 |
+
update_schedule_btn.click(
|
244 |
+
update_and_download_schedule,
|
245 |
+
inputs=[overnight_schedule_output, day_schedule_output, prime_schedule_output],
|
246 |
+
outputs=[update_status, download_schedule_btn]
|
247 |
+
)
|
248 |
|
249 |
return interface
|
250 |
|
|
|
257 |
|
258 |
|
259 |
|
260 |
+
|