DontPlanToEnd commited on
Commit
90bf7b7
1 Parent(s): eee2dcf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -22
app.py CHANGED
@@ -20,28 +20,27 @@ def load_leaderboard_data(csv_file_path):
20
  return pd.DataFrame(columns=UGI_COLS) # Return an empty dataframe with the correct columns
21
 
22
  # Update the leaderboard table based on the search query and parameter range filters
23
- def update_table(df: pd.DataFrame, query: str, param_ranges: dict) -> pd.DataFrame:
24
  filtered_df = df
25
- if any(param_ranges.values()):
26
  conditions = []
27
- for param_range, checked in param_ranges.items():
28
- if checked:
29
- if param_range == '~1.5':
30
- conditions.append((filtered_df['Params'] < 2.5))
31
- elif param_range == '~3':
32
- conditions.append(((filtered_df['Params'] >= 2.5) & (filtered_df['Params'] < 6)))
33
- elif param_range == '~7':
34
- conditions.append(((filtered_df['Params'] >= 6) & (filtered_df['Params'] < 9.5)))
35
- elif param_range == '~13':
36
- conditions.append(((filtered_df['Params'] >= 9.5) & (filtered_df['Params'] < 16)))
37
- elif param_range == '~20':
38
- conditions.append(((filtered_df['Params'] >= 16) & (filtered_df['Params'] < 28)))
39
- elif param_range == '~34':
40
- conditions.append(((filtered_df['Params'] >= 28) & (filtered_df['Params'] < 40)))
41
- elif param_range == '~50':
42
- conditions.append(((filtered_df['Params'] >= 40) & (filtered_df['Params'] < 60)))
43
- elif param_range == '~70+':
44
- conditions.append((filtered_df['Params'] >= 60))
45
 
46
  if conditions:
47
  filtered_df = filtered_df[pd.concat(conditions, axis=1).any(axis=1)]
@@ -110,13 +109,13 @@ with GraInter:
110
  outputs = leaderboard_table
111
 
112
  search_bar.change(
113
- fn=lambda query, param_ranges: update_table(leaderboard_df, query, dict(zip(['~1.5', '~3', '~7', '~13', '~20', '~34', '~50', '~70+'], param_ranges))),
114
  inputs=inputs,
115
  outputs=outputs
116
  )
117
 
118
  filter_columns_size.change(
119
- fn=lambda query, param_ranges: update_table(leaderboard_df, query, dict(zip(['~1.5', '~3', '~7', '~13', '~20', '~34', '~50', '~70+'], param_ranges))),
120
  inputs=inputs,
121
  outputs=outputs
122
  )
 
20
  return pd.DataFrame(columns=UGI_COLS) # Return an empty dataframe with the correct columns
21
 
22
  # Update the leaderboard table based on the search query and parameter range filters
23
+ def update_table(df: pd.DataFrame, query: str, param_ranges: list) -> pd.DataFrame:
24
  filtered_df = df
25
+ if any(param_ranges):
26
  conditions = []
27
+ for param_range in param_ranges:
28
+ if param_range == '~1.5':
29
+ conditions.append((filtered_df['Params'] < 2.5))
30
+ elif param_range == '~3':
31
+ conditions.append(((filtered_df['Params'] >= 2.5) & (filtered_df['Params'] < 6)))
32
+ elif param_range == '~7':
33
+ conditions.append(((filtered_df['Params'] >= 6) & (filtered_df['Params'] < 9.5)))
34
+ elif param_range == '~13':
35
+ conditions.append(((filtered_df['Params'] >= 9.5) & (filtered_df['Params'] < 16)))
36
+ elif param_range == '~20':
37
+ conditions.append(((filtered_df['Params'] >= 16) & (filtered_df['Params'] < 28)))
38
+ elif param_range == '~34':
39
+ conditions.append(((filtered_df['Params'] >= 28) & (filtered_df['Params'] < 40)))
40
+ elif param_range == '~50':
41
+ conditions.append(((filtered_df['Params'] >= 40) & (filtered_df['Params'] < 60)))
42
+ elif param_range == '~70+':
43
+ conditions.append((filtered_df['Params'] >= 60))
 
44
 
45
  if conditions:
46
  filtered_df = filtered_df[pd.concat(conditions, axis=1).any(axis=1)]
 
109
  outputs = leaderboard_table
110
 
111
  search_bar.change(
112
+ fn=lambda query, param_ranges: update_table(leaderboard_df, query, param_ranges),
113
  inputs=inputs,
114
  outputs=outputs
115
  )
116
 
117
  filter_columns_size.change(
118
+ fn=lambda query, param_ranges: update_table(leaderboard_df, query, param_ranges),
119
  inputs=inputs,
120
  outputs=outputs
121
  )