3morrrrr commited on
Commit
be64d63
·
verified ·
1 Parent(s): 25c6fdf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -17
app.py CHANGED
@@ -107,29 +107,33 @@ def update_assignments(assignments_df, creators_df):
107
  except Exception as e:
108
  return f"Error updating assignments: {e}", None
109
 
110
- def generate_full_schedule():
111
  try:
 
112
  chatter_files = [
113
- os.path.join(PROCESSED_FOLDER, "Updated_overnight_file.xlsx"),
114
- os.path.join(PROCESSED_FOLDER, "Updated_day_file.xlsx"),
115
- os.path.join(PROCESSED_FOLDER, "Updated_prime_file.xlsx"),
116
  ]
117
- creators_file = os.path.join(PROCESSED_FOLDER, "creators_file.xlsx")
118
 
119
- # Debugging: Log file paths and existence
120
- for f in chatter_files + [creators_file]:
121
- print(f"DEBUG: File path: {f}")
122
- print(f"DEBUG: File exists: {os.path.exists(f)}")
123
 
124
- if not all(os.path.exists(f) for f in chatter_files + [creators_file]):
125
- return "Missing required files. Please complete the 'Generate Main Accounts' step first."
 
 
126
 
127
  # Generate schedule
128
- full_schedule = generate_schedule(chatter_files, pd.read_excel(creators_file))
129
  return full_schedule
130
  except Exception as e:
131
  return f"Error generating schedule: {e}"
132
 
 
133
  # Gradio Interface
134
  def app():
135
  with gr.Blocks() as interface:
@@ -181,12 +185,20 @@ def app():
181
  )
182
 
183
  with gr.Tab("Generate Full Schedule"):
184
- generate_schedule_btn = gr.Button("Generate Full Schedule")
185
- full_schedule_output = gr.Textbox(label="Full Schedule", interactive=False)
 
 
 
 
 
 
 
 
 
 
 
186
 
187
- generate_schedule_btn.click(
188
- generate_full_schedule, inputs=[], outputs=[full_schedule_output]
189
- )
190
 
191
  return interface
192
 
 
107
  except Exception as e:
108
  return f"Error updating assignments: {e}", None
109
 
110
+ def generate_full_schedule(creators_file, overnight_file, day_file, prime_file):
111
  try:
112
+ # Read uploaded files directly
113
  chatter_files = [
114
+ pd.read_excel(overnight_file),
115
+ pd.read_excel(day_file),
116
+ pd.read_excel(prime_file),
117
  ]
118
+ creators_data = pd.read_excel(creators_file)
119
 
120
+ # Debugging: Log the columns of the files
121
+ print("DEBUG: Creators File Columns:", creators_data.columns)
122
+ for idx, chatter_df in enumerate(chatter_files):
123
+ print(f"DEBUG: Chatter File {idx + 1} Columns:", chatter_df.columns)
124
 
125
+ # Validate data structure
126
+ required_creator_columns = {"Creator", "ActiveFans"}
127
+ if not required_creator_columns.issubset(creators_data.columns):
128
+ return f"Error: Creators file must contain the columns {required_creator_columns}."
129
 
130
  # Generate schedule
131
+ full_schedule = generate_schedule(chatter_files, creators_data)
132
  return full_schedule
133
  except Exception as e:
134
  return f"Error generating schedule: {e}"
135
 
136
+
137
  # Gradio Interface
138
  def app():
139
  with gr.Blocks() as interface:
 
185
  )
186
 
187
  with gr.Tab("Generate Full Schedule"):
188
+ creators_file = gr.File(label="Creators File", type="binary")
189
+ overnight_file = gr.File(label="Overnight File", type="binary")
190
+ day_file = gr.File(label="Day File", type="binary")
191
+ prime_file = gr.File(label="Prime File", type="binary")
192
+
193
+ generate_schedule_btn = gr.Button("Generate Full Schedule")
194
+ full_schedule_output = gr.Textbox(label="Full Schedule", interactive=False)
195
+
196
+ generate_schedule_btn.click(
197
+ generate_full_schedule,
198
+ inputs=[creators_file, overnight_file, day_file, prime_file],
199
+ outputs=[full_schedule_output]
200
+ )
201
 
 
 
 
202
 
203
  return interface
204