Nicolas Wagner commited on
Commit
8782314
·
1 Parent(s): e627987

add more defensive

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. app.py +31 -12
.gitignore CHANGED
@@ -1,5 +1,6 @@
1
  auto_evals/
2
  venv/
 
3
  __pycache__/
4
  .env
5
  .ipynb_checkpoints
 
1
  auto_evals/
2
  venv/
3
+ .venv/
4
  __pycache__/
5
  .env
6
  .ipynb_checkpoints
app.py CHANGED
@@ -48,8 +48,8 @@ try:
48
  etag_timeout=30,
49
  token=TOKEN,
50
  )
51
- except Exception:
52
- print(f"Warning: Could not download teams dataset from {TEAMS_REPO}")
53
 
54
  try:
55
  snapshot_download(
@@ -60,10 +60,13 @@ try:
60
  etag_timeout=30,
61
  token=TOKEN,
62
  )
63
- except Exception:
64
- print(f"Warning: Could not download submissions dataset from {SUBMISSIONS_REPO}")
65
 
66
- load_true_labels()
 
 
 
67
 
68
  LEADERBOARD_DF = get_leaderboard_df(SUBMISSIONS_PATH, COLS)
69
 
@@ -75,22 +78,38 @@ LEADERBOARD_DF = get_leaderboard_df(SUBMISSIONS_PATH, COLS)
75
 
76
 
77
  def init_leaderboard(dataframe):
 
 
78
  if dataframe is None or dataframe.empty:
 
 
 
79
  return Leaderboard(
80
- value=pd.DataFrame(columns=COLS),
81
- datatype=[c.type for c in fields(TeamColumn)],
82
  interactive=False,
83
  )
 
 
 
 
 
 
 
 
 
 
 
84
  return Leaderboard(
85
  value=dataframe,
86
- datatype=[c.type for c in fields(TeamColumn)],
87
  select_columns=SelectColumns(
88
- default_selection=[c.name for c in fields(TeamColumn) if c.displayed_by_default],
89
- cant_deselect=[c.name for c in fields(TeamColumn) if c.never_hidden],
90
  label="Select Columns to Display:",
91
  ),
92
- search_columns=[TeamColumn.team_name.name],
93
- hide_columns=[c.name for c in fields(TeamColumn) if c.hidden],
94
  filter_columns=[],
95
  interactive=False,
96
  )
 
48
  etag_timeout=30,
49
  token=TOKEN,
50
  )
51
+ except Exception as e:
52
+ print(f"Warning: Could not download teams dataset from {TEAMS_REPO}: {e}")
53
 
54
  try:
55
  snapshot_download(
 
60
  etag_timeout=30,
61
  token=TOKEN,
62
  )
63
+ except Exception as e:
64
+ print(f"Warning: Could not download submissions dataset from {SUBMISSIONS_REPO}: {e}")
65
 
66
+ try:
67
+ load_true_labels()
68
+ except Exception as e:
69
+ print(f"Warning: Could not load true labels: {e}")
70
 
71
  LEADERBOARD_DF = get_leaderboard_df(SUBMISSIONS_PATH, COLS)
72
 
 
78
 
79
 
80
  def init_leaderboard(dataframe):
81
+ team_columns = [c for c in fields(TeamColumn) if c is not None and hasattr(c, "name") and c.name is not None]
82
+
83
  if dataframe is None or dataframe.empty:
84
+ empty_df = pd.DataFrame(columns=COLS)
85
+ column_to_type = {c.name: c.type for c in team_columns}
86
+ datatypes = [column_to_type.get(col, "str") for col in COLS]
87
  return Leaderboard(
88
+ value=empty_df,
89
+ datatype=datatypes,
90
  interactive=False,
91
  )
92
+
93
+ column_to_type = {c.name: c.type for c in team_columns}
94
+ datatypes = [column_to_type.get(col, "str") for col in dataframe.columns]
95
+
96
+ default_selection = [c.name for c in team_columns if getattr(c, "displayed_by_default", False) and c.name]
97
+ cant_deselect = [c.name for c in team_columns if getattr(c, "never_hidden", False) and c.name]
98
+ hide_cols = [c.name for c in team_columns if getattr(c, "hidden", False) and c.name]
99
+ search_cols = (
100
+ [TeamColumn.team_name.name] if hasattr(TeamColumn.team_name, "name") and TeamColumn.team_name.name else []
101
+ )
102
+
103
  return Leaderboard(
104
  value=dataframe,
105
+ datatype=datatypes,
106
  select_columns=SelectColumns(
107
+ default_selection=default_selection,
108
+ cant_deselect=cant_deselect,
109
  label="Select Columns to Display:",
110
  ),
111
+ search_columns=search_cols,
112
+ hide_columns=hide_cols,
113
  filter_columns=[],
114
  interactive=False,
115
  )