Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
5 |
+
|
6 |
+
UPLOAD_FOLDER = "uploads"
|
7 |
+
PROCESSED_FOLDER = "processed"
|
8 |
+
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
9 |
+
os.makedirs(PROCESSED_FOLDER, exist_ok=True)
|
10 |
+
|
11 |
+
USERNAME = "admin"
|
12 |
+
PASSWORD = "password123"
|
13 |
+
|
14 |
+
|
15 |
+
# Helper Functions
|
16 |
+
def login(username, password):
|
17 |
+
if username == USERNAME and password == PASSWORD:
|
18 |
+
return "Login Successful!", True
|
19 |
+
else:
|
20 |
+
return "Invalid credentials. Try again.", False
|
21 |
+
|
22 |
+
|
23 |
+
def upload_files(creators_file, overnight_file, day_file, prime_file):
|
24 |
+
try:
|
25 |
+
creators_file.save(os.path.join(UPLOAD_FOLDER, "creators_file.xlsx"))
|
26 |
+
overnight_file.save(os.path.join(UPLOAD_FOLDER, "overnight_file.xlsx"))
|
27 |
+
day_file.save(os.path.join(UPLOAD_FOLDER, "day_file.xlsx"))
|
28 |
+
prime_file.save(os.path.join(UPLOAD_FOLDER, "prime_file.xlsx"))
|
29 |
+
return "Files uploaded successfully!"
|
30 |
+
except Exception as e:
|
31 |
+
return f"Error uploading files: {e}"
|
32 |
+
|
33 |
+
|
34 |
+
def generate_main_accounts():
|
35 |
+
creators_file = os.path.join(UPLOAD_FOLDER, "creators_file.xlsx")
|
36 |
+
chatter_files = [
|
37 |
+
os.path.join(UPLOAD_FOLDER, "overnight_file.xlsx"),
|
38 |
+
os.path.join(UPLOAD_FOLDER, "day_file.xlsx"),
|
39 |
+
os.path.join(UPLOAD_FOLDER, "prime_file.xlsx"),
|
40 |
+
]
|
41 |
+
|
42 |
+
if not all(os.path.exists(path) for path in [creators_file] + chatter_files):
|
43 |
+
return "Missing required files. Please upload all necessary files."
|
44 |
+
|
45 |
+
try:
|
46 |
+
main_assignments = assign_main_accounts(creators_file, chatter_files)
|
47 |
+
save_processed_files(main_assignments, PROCESSED_FOLDER)
|
48 |
+
return "Main accounts generated successfully!"
|
49 |
+
except Exception as e:
|
50 |
+
return f"Error during main account generation: {e}"
|
51 |
+
|
52 |
+
|
53 |
+
def generate_full_schedule():
|
54 |
+
chatter_files = [
|
55 |
+
os.path.join(PROCESSED_FOLDER, "Updated_overnight_file.xlsx"),
|
56 |
+
os.path.join(PROCESSED_FOLDER, "Updated_day_file.xlsx"),
|
57 |
+
os.path.join(PROCESSED_FOLDER, "Updated_prime_file.xlsx"),
|
58 |
+
]
|
59 |
+
creators_file = os.path.join(PROCESSED_FOLDER, "creators_file.xlsx")
|
60 |
+
|
61 |
+
if not all(os.path.exists(path) for path in chatter_files + [creators_file]):
|
62 |
+
return "Files are missing. Please generate main accounts first."
|
63 |
+
|
64 |
+
try:
|
65 |
+
full_schedules = generate_schedule(chatter_files, creators_file)
|
66 |
+
return full_schedules
|
67 |
+
except Exception as e:
|
68 |
+
return f"Error generating full schedule: {e}"
|
69 |
+
|
70 |
+
|
71 |
+
# Gradio Interface
|
72 |
+
def app():
|
73 |
+
with gr.Blocks() as interface:
|
74 |
+
with gr.Tab("Login"):
|
75 |
+
username = gr.Textbox(label="Username")
|
76 |
+
password = gr.Textbox(label="Password", type="password")
|
77 |
+
login_btn = gr.Button("Login")
|
78 |
+
login_status = gr.Textbox(label="Login Status", interactive=False)
|
79 |
+
|
80 |
+
login_btn.click(login, inputs=[username, password], outputs=[login_status])
|
81 |
+
|
82 |
+
with gr.Tab("Upload Files"):
|
83 |
+
creators_file = gr.File(label="Creators File")
|
84 |
+
overnight_file = gr.File(label="Overnight File")
|
85 |
+
day_file = gr.File(label="Day File")
|
86 |
+
prime_file = gr.File(label="Prime File")
|
87 |
+
upload_btn = gr.Button("Upload Files")
|
88 |
+
upload_status = gr.Textbox(label="Upload Status", interactive=False)
|
89 |
+
|
90 |
+
upload_btn.click(
|
91 |
+
upload_files,
|
92 |
+
inputs=[creators_file, overnight_file, day_file, prime_file],
|
93 |
+
outputs=[upload_status],
|
94 |
+
)
|
95 |
+
|
96 |
+
with gr.Tab("Generate Main Accounts"):
|
97 |
+
generate_main_btn = gr.Button("Generate Main Accounts")
|
98 |
+
generate_main_status = gr.Textbox(label="Status", interactive=False)
|
99 |
+
|
100 |
+
generate_main_btn.click(generate_main_accounts, outputs=[generate_main_status])
|
101 |
+
|
102 |
+
with gr.Tab("Generate Full Schedule"):
|
103 |
+
generate_full_btn = gr.Button("Generate Full Schedule")
|
104 |
+
full_schedule_output = gr.Textbox(label="Full Schedule", interactive=False)
|
105 |
+
|
106 |
+
generate_full_btn.click(generate_full_schedule, outputs=[full_schedule_output])
|
107 |
+
|
108 |
+
return interface
|
109 |
+
|
110 |
+
|
111 |
+
# Launch Gradio App
|
112 |
+
if __name__ == "__main__":
|
113 |
+
app().launch()
|