IAMTFRMZA commited on
Commit
0b4d4e7
·
verified ·
1 Parent(s): 5db7057

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -165,17 +165,16 @@ def quote_year_choices():
165
 
166
  def quote_month_choices(year=None):
167
  df = get_quotes_df()
168
- # Always return a list (possibly empty)
169
  if (
170
- year
171
- and "Year" in df.columns
172
  and "Month" in df.columns
173
  and not df.empty
174
  ):
175
  subset = df[df["Year"].astype(str) == str(year)]
176
- months = pd.to_numeric(subset["Month"], errors="coerce").dropna().astype(int).unique()
177
- # Keep months only 1-12
178
- months = sorted(set(str(m) for m in months if 1 <= m <= 12))
179
  return months
180
  return []
181
 
@@ -265,8 +264,11 @@ with gr.Blocks(title="Graffiti Admin Dashboard") as app:
265
 
266
  # Dynamic month options for summary
267
  def update_month_choices_summary(year):
268
- months = quote_month_choices(year) if year else []
269
- return gr.Dropdown.update(choices=[""] + months, value="")
 
 
 
270
  year_qs.change(update_month_choices_summary, year_qs, month_qs)
271
 
272
  def quotes_summary_wrapper(year, month):
@@ -282,8 +284,11 @@ with gr.Blocks(title="Graffiti Admin Dashboard") as app:
282
 
283
  # Dynamic month options for rep quotes
284
  def update_month_choices(year):
285
- months = quote_month_choices(year) if year else []
286
- return gr.Dropdown.update(choices=[""] + months, value="")
 
 
 
287
  year_q.change(update_month_choices, year_q, month_q)
288
 
289
  def get_rep_quotes_filtered_wrapper(rep, year, month):
 
165
 
166
  def quote_month_choices(year=None):
167
  df = get_quotes_df()
 
168
  if (
169
+ year
170
+ and "Year" in df.columns
171
  and "Month" in df.columns
172
  and not df.empty
173
  ):
174
  subset = df[df["Year"].astype(str) == str(year)]
175
+ # Only keep valid 1-12 integer months, as strings
176
+ months = pd.to_numeric(subset["Month"], errors="coerce").dropna().astype(int)
177
+ months = sorted({str(m) for m in months if 1 <= m <= 12})
178
  return months
179
  return []
180
 
 
264
 
265
  # Dynamic month options for summary
266
  def update_month_choices_summary(year):
267
+ try:
268
+ months = quote_month_choices(year) if year else []
269
+ return gr.Dropdown.update(choices=[""] + months, value="")
270
+ except:
271
+ return gr.Dropdown.update(choices=[""], value="")
272
  year_qs.change(update_month_choices_summary, year_qs, month_qs)
273
 
274
  def quotes_summary_wrapper(year, month):
 
284
 
285
  # Dynamic month options for rep quotes
286
  def update_month_choices(year):
287
+ try:
288
+ months = quote_month_choices(year) if year else []
289
+ return gr.Dropdown.update(choices=[""] + months, value="")
290
+ except:
291
+ return gr.Dropdown.update(choices=[""], value="")
292
  year_q.change(update_month_choices, year_q, month_q)
293
 
294
  def get_rep_quotes_filtered_wrapper(rep, year, month):