Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import gradio as gr
|
| 4 |
from helper import assign_main_accounts, generate_schedule, save_processed_files
|
|
@@ -6,6 +7,7 @@ from helper import assign_main_accounts, generate_schedule, save_processed_files
|
|
| 6 |
# Global Constants
|
| 7 |
UPLOAD_FOLDER = "uploads"
|
| 8 |
PROCESSED_FOLDER = "processed"
|
|
|
|
| 9 |
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
| 10 |
os.makedirs(PROCESSED_FOLDER, exist_ok=True)
|
| 11 |
|
|
@@ -67,6 +69,12 @@ def generate_main_accounts():
|
|
| 67 |
os.path.join(PROCESSED_FOLDER, "creators_file.xlsx"), index=False
|
| 68 |
)
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
return "Main accounts generated successfully!", combined_assignments, processed_creator_file
|
| 71 |
except Exception as e:
|
| 72 |
return f"Error during main account generation: {e}", None, None
|
|
@@ -84,7 +92,13 @@ def update_assignments(assignments_df, creators_df):
|
|
| 84 |
creators_file_path = os.path.join(PROCESSED_FOLDER, "creators_file.xlsx")
|
| 85 |
creators_df.to_excel(creators_file_path, index=False)
|
| 86 |
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
except Exception as e:
|
| 89 |
return f"Error updating assignments: {e}", None
|
| 90 |
|
|
@@ -147,7 +161,7 @@ def app():
|
|
| 147 |
|
| 148 |
generate_main_btn = gr.Button("Generate Main Accounts")
|
| 149 |
update_btn = gr.Button("Update and Download Files")
|
| 150 |
-
download_zip_btn = gr.File(label="Download
|
| 151 |
|
| 152 |
generate_main_btn.click(
|
| 153 |
generate_main_accounts,
|
|
@@ -177,3 +191,4 @@ if __name__ == "__main__":
|
|
| 177 |
|
| 178 |
|
| 179 |
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import zipfile
|
| 3 |
import pandas as pd
|
| 4 |
import gradio as gr
|
| 5 |
from helper import assign_main_accounts, generate_schedule, save_processed_files
|
|
|
|
| 7 |
# Global Constants
|
| 8 |
UPLOAD_FOLDER = "uploads"
|
| 9 |
PROCESSED_FOLDER = "processed"
|
| 10 |
+
ZIP_FILE = "processed_files.zip"
|
| 11 |
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
| 12 |
os.makedirs(PROCESSED_FOLDER, exist_ok=True)
|
| 13 |
|
|
|
|
| 69 |
os.path.join(PROCESSED_FOLDER, "creators_file.xlsx"), index=False
|
| 70 |
)
|
| 71 |
|
| 72 |
+
# Create a zip file containing all processed files
|
| 73 |
+
with zipfile.ZipFile(ZIP_FILE, "w") as zipf:
|
| 74 |
+
for root, _, files in os.walk(PROCESSED_FOLDER):
|
| 75 |
+
for file in files:
|
| 76 |
+
zipf.write(os.path.join(root, file), arcname=file)
|
| 77 |
+
|
| 78 |
return "Main accounts generated successfully!", combined_assignments, processed_creator_file
|
| 79 |
except Exception as e:
|
| 80 |
return f"Error during main account generation: {e}", None, None
|
|
|
|
| 92 |
creators_file_path = os.path.join(PROCESSED_FOLDER, "creators_file.xlsx")
|
| 93 |
creators_df.to_excel(creators_file_path, index=False)
|
| 94 |
|
| 95 |
+
# Update the ZIP file with the latest files
|
| 96 |
+
with zipfile.ZipFile(ZIP_FILE, "w") as zipf:
|
| 97 |
+
for root, _, files in os.walk(PROCESSED_FOLDER):
|
| 98 |
+
for file in files:
|
| 99 |
+
zipf.write(os.path.join(root, file), arcname=file)
|
| 100 |
+
|
| 101 |
+
return "Assignments and Creator File updated successfully!", ZIP_FILE
|
| 102 |
except Exception as e:
|
| 103 |
return f"Error updating assignments: {e}", None
|
| 104 |
|
|
|
|
| 161 |
|
| 162 |
generate_main_btn = gr.Button("Generate Main Accounts")
|
| 163 |
update_btn = gr.Button("Update and Download Files")
|
| 164 |
+
download_zip_btn = gr.File(label="Download Processed Files", value=ZIP_FILE)
|
| 165 |
|
| 166 |
generate_main_btn.click(
|
| 167 |
generate_main_accounts,
|
|
|
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
+
|