DontPlanToEnd commited on
Commit
2c172cf
β€’
1 Parent(s): 889773e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -26
app.py CHANGED
@@ -42,7 +42,27 @@ WRITING_STYLE_COLS = ['#P', 'Model', 'Reg+MyScore πŸ†', 'Reg+Int πŸ†', 'MyScor
42
  ANIME_RATING_COLS = ['#P', 'Model', 'Score πŸ†', 'Dif', 'Cor', 'Std']
43
 
44
  # Load the leaderboard data from a CSV file
45
- def update_table(df: pd.DataFrame, query: str, param_ranges: list, w10_range: list, columns: list) -> pd.DataFrame:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  filtered_df = df.copy()
47
  if param_ranges:
48
  param_mask = pd.Series(False, index=filtered_df.index)
@@ -65,9 +85,6 @@ def update_table(df: pd.DataFrame, query: str, param_ranges: list, w10_range: li
65
  param_mask |= (filtered_df['Params'] >= 65)
66
  filtered_df = filtered_df[param_mask]
67
 
68
- # Apply W/10 filter
69
- filtered_df = filtered_df[(filtered_df['W/10 πŸ‘'] >= w10_range[0]) & (filtered_df['W/10 πŸ‘'] <= w10_range[1])]
70
-
71
  if query:
72
  filtered_df = filtered_df[filtered_df['Model'].str.contains(query, case=False, na=False)]
73
 
@@ -103,15 +120,6 @@ with GraInter:
103
  interactive=True,
104
  elem_id="filter-columns-size",
105
  )
106
- with gr.Row():
107
- w10_slider = gr.Slider(
108
- minimum=0,
109
- maximum=10,
110
- value=[0, 10],
111
- step=0.1,
112
- label="W/10 Range",
113
- elem_id="w10-slider"
114
- )
115
 
116
  # Load the initial leaderboard data
117
  leaderboard_df = load_leaderboard_data("ugi-leaderboard-data.csv")
@@ -231,36 +239,30 @@ with GraInter:
231
  **NA:** When models either reply with one number for every anime, give ratings not between 1 and 10, or don't give every anime in the list a rating.
232
  """)
233
 
234
- def update_all_tables(query, param_ranges, w10_range):
235
- ugi_table = update_table(leaderboard_df, query, param_ranges, w10_range, UGI_COLS)
236
 
237
  ws_df = leaderboard_df.sort_values(by='Reg+MyScore πŸ†', ascending=False)
238
- ws_table = update_table(ws_df, query, param_ranges, w10_range, WRITING_STYLE_COLS)
239
 
240
  arp_df = leaderboard_df.sort_values(by='Score πŸ†', ascending=False)
241
  arp_df_na = arp_df[arp_df[['Dif', 'Cor']].isna().any(axis=1)]
242
  arp_df = arp_df[~arp_df[['Dif', 'Cor']].isna().any(axis=1)]
243
 
244
- arp_table = update_table(arp_df, query, param_ranges, w10_range, ANIME_RATING_COLS)
245
- arp_na_table = update_table(arp_df_na, query, param_ranges, w10_range, ANIME_RATING_COLS).fillna('NA')
246
 
247
  return ugi_table, ws_table, arp_table, arp_na_table
248
 
249
  search_bar.change(
250
  fn=update_all_tables,
251
- inputs=[search_bar, filter_columns_size, w10_slider],
252
  outputs=[leaderboard_table_ugi, leaderboard_table_ws, leaderboard_table_arp, leaderboard_table_arp_na]
253
  )
254
 
255
  filter_columns_size.change(
256
  fn=update_all_tables,
257
- inputs=[search_bar, filter_columns_size, w10_slider],
258
- outputs=[leaderboard_table_ugi, leaderboard_table_ws, leaderboard_table_arp, leaderboard_table_arp_na]
259
- )
260
-
261
- w10_slider.change(
262
- fn=update_all_tables,
263
- inputs=[search_bar, filter_columns_size, w10_slider],
264
  outputs=[leaderboard_table_ugi, leaderboard_table_ws, leaderboard_table_arp, leaderboard_table_arp_na]
265
  )
266
 
 
42
  ANIME_RATING_COLS = ['#P', 'Model', 'Score πŸ†', 'Dif', 'Cor', 'Std']
43
 
44
  # Load the leaderboard data from a CSV file
45
+ def load_leaderboard_data(csv_file_path):
46
+ try:
47
+ df = pd.read_csv(csv_file_path)
48
+ df['Model'] = df.apply(lambda row: f'<a href="{row["Link"]}" target="_blank" style="color: blue; text-decoration: none;">{row["Model"]}</a>' if pd.notna(row["Link"]) else row["Model"], axis=1)
49
+ df.drop(columns=['Link'], inplace=True)
50
+
51
+ # Round numeric columns to 3 decimal places
52
+ numeric_columns = df.select_dtypes(include=[np.number]).columns
53
+ df[numeric_columns] = df[numeric_columns].round(3)
54
+
55
+ # Round the W/10 column to 1 decimal place
56
+ if 'W/10 πŸ‘' in df.columns:
57
+ df['W/10 πŸ‘'] = df['W/10 πŸ‘'].round(1)
58
+
59
+ return df
60
+ except Exception as e:
61
+ print(f"Error loading CSV file: {e}")
62
+ return pd.DataFrame(columns=UGI_COLS + WRITING_STYLE_COLS + ANIME_RATING_COLS)
63
+
64
+ # Update the leaderboard table based on the search query and parameter range filters
65
+ def update_table(df: pd.DataFrame, query: str, param_ranges: list, columns: list) -> pd.DataFrame:
66
  filtered_df = df.copy()
67
  if param_ranges:
68
  param_mask = pd.Series(False, index=filtered_df.index)
 
85
  param_mask |= (filtered_df['Params'] >= 65)
86
  filtered_df = filtered_df[param_mask]
87
 
 
 
 
88
  if query:
89
  filtered_df = filtered_df[filtered_df['Model'].str.contains(query, case=False, na=False)]
90
 
 
120
  interactive=True,
121
  elem_id="filter-columns-size",
122
  )
 
 
 
 
 
 
 
 
 
123
 
124
  # Load the initial leaderboard data
125
  leaderboard_df = load_leaderboard_data("ugi-leaderboard-data.csv")
 
239
  **NA:** When models either reply with one number for every anime, give ratings not between 1 and 10, or don't give every anime in the list a rating.
240
  """)
241
 
242
+ def update_all_tables(query, param_ranges):
243
+ ugi_table = update_table(leaderboard_df, query, param_ranges, UGI_COLS)
244
 
245
  ws_df = leaderboard_df.sort_values(by='Reg+MyScore πŸ†', ascending=False)
246
+ ws_table = update_table(ws_df, query, param_ranges, WRITING_STYLE_COLS)
247
 
248
  arp_df = leaderboard_df.sort_values(by='Score πŸ†', ascending=False)
249
  arp_df_na = arp_df[arp_df[['Dif', 'Cor']].isna().any(axis=1)]
250
  arp_df = arp_df[~arp_df[['Dif', 'Cor']].isna().any(axis=1)]
251
 
252
+ arp_table = update_table(arp_df, query, param_ranges, ANIME_RATING_COLS)
253
+ arp_na_table = update_table(arp_df_na, query, param_ranges, ANIME_RATING_COLS).fillna('NA')
254
 
255
  return ugi_table, ws_table, arp_table, arp_na_table
256
 
257
  search_bar.change(
258
  fn=update_all_tables,
259
+ inputs=[search_bar, filter_columns_size],
260
  outputs=[leaderboard_table_ugi, leaderboard_table_ws, leaderboard_table_arp, leaderboard_table_arp_na]
261
  )
262
 
263
  filter_columns_size.change(
264
  fn=update_all_tables,
265
+ inputs=[search_bar, filter_columns_size],
 
 
 
 
 
 
266
  outputs=[leaderboard_table_ugi, leaderboard_table_ws, leaderboard_table_arp, leaderboard_table_arp_na]
267
  )
268