lukehinds commited on
Commit
240cd3c
·
1 Parent(s): 80fe2b4

Render board correctly for model link

Browse files
Files changed (1) hide show
  1. app.py +32 -22
app.py CHANGED
@@ -217,41 +217,51 @@ def init_leaderboard(df):
217
  else:
218
  logger.info(f"Initializing leaderboard with {len(df)} rows")
219
 
220
- # Ensure "Security Score ⬆️" and "Safetensors" columns are present
221
- if "Security Score ⬆️" not in df.columns:
222
- logger.warning("Security Score column not found in DataFrame")
223
- df["Security Score ⬆️"] = None
224
- if "Safetensors" not in df.columns:
225
- logger.warning("Safetensors column not found in DataFrame")
226
- df["Safetensors"] = None
 
 
 
 
 
 
 
 
 
 
 
227
 
228
  # Sort by Security Score if available
229
  if "Security Score ⬆️" in df.columns:
230
  df = df.sort_values(by="Security Score ⬆️", ascending=False)
231
  logger.info("Sorted leaderboard by Security Score")
232
 
233
- # Ensure all required columns are present
234
- for col in COLS:
235
- if col not in df.columns:
236
- logger.warning(f"Column {col} not found in DataFrame, adding with None values")
237
- df[col] = None
238
-
239
  # Select only the columns we want to display
240
  df = df[COLS]
241
 
242
  logger.info(f"Final leaderboard columns: {df.columns.tolist()}")
243
  logger.debug(f"Leaderboard data:\n{df}")
244
 
245
- # Create the leaderboard
246
- return gr.Dataframe(
247
- headers=COLS,
248
- datatype=["str"] * len(COLS),
249
- row_count=10,
250
- col_count=(len(COLS), "fixed"),
251
  value=df,
252
- wrap=True,
253
- column_widths=[50] + [None] * (len(COLS) - 1),
254
- type="pandas",
 
 
 
 
 
 
 
 
 
255
  )
256
 
257
 
 
217
  else:
218
  logger.info(f"Initializing leaderboard with {len(df)} rows")
219
 
220
+ # Ensure all required columns exist
221
+ for col in COLS:
222
+ if col not in df.columns:
223
+ logger.warning(f"Column {col} not found in DataFrame, adding with None values")
224
+ df[col] = None
225
+
226
+ # Map dataset columns to display columns
227
+ column_mapping = {
228
+ "model_id": "Model",
229
+ "security_score": "Security Score ⬆️",
230
+ "safetensors_compliant": "Safetensors",
231
+ "precision": "Precision"
232
+ }
233
+
234
+ for src, dst in column_mapping.items():
235
+ if src in df.columns:
236
+ df[dst] = df[src]
237
+ logger.debug(f"Mapped column {src} to {dst}")
238
 
239
  # Sort by Security Score if available
240
  if "Security Score ⬆️" in df.columns:
241
  df = df.sort_values(by="Security Score ⬆️", ascending=False)
242
  logger.info("Sorted leaderboard by Security Score")
243
 
 
 
 
 
 
 
244
  # Select only the columns we want to display
245
  df = df[COLS]
246
 
247
  logger.info(f"Final leaderboard columns: {df.columns.tolist()}")
248
  logger.debug(f"Leaderboard data:\n{df}")
249
 
250
+ # Create the leaderboard using gradio_leaderboard
251
+ return Leaderboard(
 
 
 
 
252
  value=df,
253
+ datatype=["html" if col == "Model" else "number" if col == "Security Score ⬆️" else "bool" if col == "Safetensors" else "str" for col in COLS],
254
+ select_columns=SelectColumns(
255
+ default_selection=COLS,
256
+ cant_deselect=["Model", "Security Score ⬆️", "Safetensors"],
257
+ label="Select Columns to Display:",
258
+ ),
259
+ search_columns=["Model"],
260
+ filter_columns=[
261
+ ColumnFilter("Safetensors", type="boolean", label="Show only Safetensors models"),
262
+ ColumnFilter("Security Score ⬆️", type="slider", min=0, max=1, step=0.1, label="Minimum Security Score"),
263
+ ],
264
+ interactive=False,
265
  )
266
 
267