Spaces:
Running
Running
jasonshaoshun
commited on
Commit
·
29eaa40
1
Parent(s):
2797503
debug
Browse files
app.py
CHANGED
|
@@ -46,7 +46,6 @@ from src.submission.submit import add_new_eval
|
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
-
|
| 50 |
from gradio_leaderboard import SelectColumns, Leaderboard
|
| 51 |
import pandas as pd
|
| 52 |
from typing import List, Dict, Union, Optional, Any
|
|
@@ -54,43 +53,31 @@ from dataclasses import fields
|
|
| 54 |
|
| 55 |
class SmartSelectColumns(SelectColumns):
|
| 56 |
"""
|
| 57 |
-
Enhanced SelectColumns component
|
| 58 |
"""
|
| 59 |
def __init__(
|
| 60 |
self,
|
| 61 |
benchmark_keywords: Optional[List[str]] = None,
|
| 62 |
model_keywords: Optional[List[str]] = None,
|
| 63 |
-
column_mapping: Optional[Dict[str, str]] = None,
|
| 64 |
initial_selected: Optional[List[str]] = None,
|
| 65 |
**kwargs
|
| 66 |
):
|
| 67 |
"""
|
| 68 |
-
Initialize SmartSelectColumns with
|
| 69 |
|
| 70 |
Args:
|
| 71 |
-
benchmark_keywords: List of benchmark names to filter by
|
| 72 |
-
model_keywords: List of model names to filter by
|
| 73 |
-
column_mapping: Dict mapping actual column names to display names
|
| 74 |
initial_selected: List of columns to show initially
|
| 75 |
"""
|
| 76 |
super().__init__(**kwargs)
|
| 77 |
self.benchmark_keywords = benchmark_keywords or []
|
| 78 |
self.model_keywords = model_keywords or []
|
| 79 |
-
self.column_mapping = column_mapping or {}
|
| 80 |
-
self.reverse_mapping = {v: k for k, v in self.column_mapping.items()} if column_mapping else {}
|
| 81 |
self.initial_selected = initial_selected or []
|
| 82 |
-
|
| 83 |
-
def preprocess_value(self, x: List[str]) -> List[str]:
|
| 84 |
-
"""Transform selected display names back to actual column names."""
|
| 85 |
-
return [self.reverse_mapping.get(col, col) for col in x]
|
| 86 |
-
|
| 87 |
-
def postprocess_value(self, y: List[str]) -> List[str]:
|
| 88 |
-
"""Transform actual column names to display names."""
|
| 89 |
-
return [self.column_mapping.get(col, col) for col in y]
|
| 90 |
|
| 91 |
def get_filtered_groups(self, df: pd.DataFrame) -> Dict[str, List[str]]:
|
| 92 |
"""
|
| 93 |
-
|
| 94 |
"""
|
| 95 |
filtered_groups = {}
|
| 96 |
|
|
@@ -102,10 +89,7 @@ class SmartSelectColumns(SelectColumns):
|
|
| 102 |
]
|
| 103 |
if matching_cols:
|
| 104 |
group_name = f"Benchmark group for {benchmark}"
|
| 105 |
-
filtered_groups[group_name] =
|
| 106 |
-
self.column_mapping.get(col, col)
|
| 107 |
-
for col in matching_cols
|
| 108 |
-
]
|
| 109 |
|
| 110 |
# Create model groups
|
| 111 |
for model in self.model_keywords:
|
|
@@ -115,10 +99,7 @@ class SmartSelectColumns(SelectColumns):
|
|
| 115 |
]
|
| 116 |
if matching_cols:
|
| 117 |
group_name = f"Model group for {model}"
|
| 118 |
-
filtered_groups[group_name] =
|
| 119 |
-
self.column_mapping.get(col, col)
|
| 120 |
-
for col in matching_cols
|
| 121 |
-
]
|
| 122 |
|
| 123 |
return filtered_groups
|
| 124 |
|
|
@@ -128,13 +109,8 @@ class SmartSelectColumns(SelectColumns):
|
|
| 128 |
) -> Dict:
|
| 129 |
"""Update component with new values."""
|
| 130 |
if isinstance(value, pd.DataFrame):
|
| 131 |
-
|
| 132 |
-
choices = [self.column_mapping.get(col, col) for col in value.columns]
|
| 133 |
-
|
| 134 |
-
# Use initial selection or default columns
|
| 135 |
selected = self.initial_selected if self.initial_selected else choices
|
| 136 |
-
|
| 137 |
-
# Get dynamically filtered groups
|
| 138 |
filtered_cols = self.get_filtered_groups(value)
|
| 139 |
|
| 140 |
return {
|
|
@@ -143,13 +119,11 @@ class SmartSelectColumns(SelectColumns):
|
|
| 143 |
"filtered_cols": filtered_cols
|
| 144 |
}
|
| 145 |
|
| 146 |
-
# Handle fields object
|
| 147 |
if hasattr(value, '__dataclass_fields__'):
|
| 148 |
field_names = [field.name for field in fields(value)]
|
| 149 |
-
choices = [self.column_mapping.get(name, name) for name in field_names]
|
| 150 |
return {
|
| 151 |
-
"choices":
|
| 152 |
-
"value": self.initial_selected if self.initial_selected else
|
| 153 |
}
|
| 154 |
|
| 155 |
return super().update(value)
|
|
@@ -366,6 +340,7 @@ def init_leaderboard_mib_subgraph(dataframe, track):
|
|
| 366 |
# Important: We need to rename our DataFrame columns to match display names
|
| 367 |
renamed_df = dataframe.rename(columns=display_mapping)
|
| 368 |
|
|
|
|
| 369 |
# return Leaderboard(
|
| 370 |
# value=renamed_df, # Use DataFrame with display names
|
| 371 |
# datatype=[c.type for c in fields(AutoEvalColumn_mib_subgraph)],
|
|
@@ -378,51 +353,80 @@ def init_leaderboard_mib_subgraph(dataframe, track):
|
|
| 378 |
# interactive=False,
|
| 379 |
# )
|
| 380 |
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
model_keywords = ["qwen2_5", "gpt2", "gemma2", "llama3"]
|
| 385 |
|
| 386 |
-
#
|
| 387 |
-
mappings = {
|
| 388 |
-
"ioi_llama3": "IOI (LLaMA-3)",
|
| 389 |
-
"ioi_qwen2_5": "IOI (Qwen-2.5)",
|
| 390 |
-
"ioi_gpt2": "IOI (GPT-2)",
|
| 391 |
-
"ioi_gemma2": "IOI (Gemma-2)",
|
| 392 |
-
"mcqa_llama3": "MCQA (LLaMA-3)",
|
| 393 |
-
"mcqa_qwen2_5": "MCQA (Qwen-2.5)",
|
| 394 |
-
"mcqa_gemma2": "MCQA (Gemma-2)",
|
| 395 |
-
"arithmetic_addition_llama3": "Arithmetic Addition (LLaMA-3)",
|
| 396 |
-
"arithmetic_subtraction_llama3": "Arithmetic Subtraction (LLaMA-3)",
|
| 397 |
-
"arc_easy_llama3": "ARC Easy (LLaMA-3)",
|
| 398 |
-
"arc_easy_gemma2": "ARC Easy (Gemma-2)",
|
| 399 |
-
"arc_challenge_llama3": "ARC Challenge (LLaMA-3)",
|
| 400 |
-
"eval_name": "Evaluation Name",
|
| 401 |
-
"Method": "Method",
|
| 402 |
-
"Average": "Average Score"
|
| 403 |
-
}
|
| 404 |
-
# mappings = {}
|
| 405 |
-
|
| 406 |
-
# Create SmartSelectColumns instance
|
| 407 |
smart_columns = SmartSelectColumns(
|
| 408 |
benchmark_keywords=benchmark_keywords,
|
| 409 |
model_keywords=model_keywords,
|
| 410 |
-
column_mapping=mappings,
|
| 411 |
initial_selected=["Method", "Average"]
|
| 412 |
)
|
| 413 |
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
# Create Leaderboard
|
| 417 |
leaderboard = Leaderboard(
|
| 418 |
-
value=
|
| 419 |
datatype=[c.type for c in fields(AutoEvalColumn_mib_subgraph)],
|
| 420 |
select_columns=smart_columns,
|
| 421 |
search_columns=["Method"],
|
| 422 |
hide_columns=[],
|
| 423 |
interactive=False
|
| 424 |
)
|
| 425 |
-
print(
|
| 426 |
return leaderboard
|
| 427 |
|
| 428 |
|
|
@@ -430,9 +434,6 @@ def init_leaderboard_mib_subgraph(dataframe, track):
|
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
# def init_leaderboard_mib_subgraph(dataframe, track):
|
| 437 |
# """Initialize the subgraph leaderboard with group-based column selection."""
|
| 438 |
# if dataframe is None or dataframe.empty:
|
|
|
|
| 46 |
|
| 47 |
|
| 48 |
|
|
|
|
| 49 |
from gradio_leaderboard import SelectColumns, Leaderboard
|
| 50 |
import pandas as pd
|
| 51 |
from typing import List, Dict, Union, Optional, Any
|
|
|
|
| 53 |
|
| 54 |
class SmartSelectColumns(SelectColumns):
|
| 55 |
"""
|
| 56 |
+
Enhanced SelectColumns component with basic filtering functionality.
|
| 57 |
"""
|
| 58 |
def __init__(
|
| 59 |
self,
|
| 60 |
benchmark_keywords: Optional[List[str]] = None,
|
| 61 |
model_keywords: Optional[List[str]] = None,
|
|
|
|
| 62 |
initial_selected: Optional[List[str]] = None,
|
| 63 |
**kwargs
|
| 64 |
):
|
| 65 |
"""
|
| 66 |
+
Initialize SmartSelectColumns with minimal configuration.
|
| 67 |
|
| 68 |
Args:
|
| 69 |
+
benchmark_keywords: List of benchmark names to filter by
|
| 70 |
+
model_keywords: List of model names to filter by
|
|
|
|
| 71 |
initial_selected: List of columns to show initially
|
| 72 |
"""
|
| 73 |
super().__init__(**kwargs)
|
| 74 |
self.benchmark_keywords = benchmark_keywords or []
|
| 75 |
self.model_keywords = model_keywords or []
|
|
|
|
|
|
|
| 76 |
self.initial_selected = initial_selected or []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
def get_filtered_groups(self, df: pd.DataFrame) -> Dict[str, List[str]]:
|
| 79 |
"""
|
| 80 |
+
Create column groups based on simple substring matching.
|
| 81 |
"""
|
| 82 |
filtered_groups = {}
|
| 83 |
|
|
|
|
| 89 |
]
|
| 90 |
if matching_cols:
|
| 91 |
group_name = f"Benchmark group for {benchmark}"
|
| 92 |
+
filtered_groups[group_name] = matching_cols
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
# Create model groups
|
| 95 |
for model in self.model_keywords:
|
|
|
|
| 99 |
]
|
| 100 |
if matching_cols:
|
| 101 |
group_name = f"Model group for {model}"
|
| 102 |
+
filtered_groups[group_name] = matching_cols
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
return filtered_groups
|
| 105 |
|
|
|
|
| 109 |
) -> Dict:
|
| 110 |
"""Update component with new values."""
|
| 111 |
if isinstance(value, pd.DataFrame):
|
| 112 |
+
choices = list(value.columns)
|
|
|
|
|
|
|
|
|
|
| 113 |
selected = self.initial_selected if self.initial_selected else choices
|
|
|
|
|
|
|
| 114 |
filtered_cols = self.get_filtered_groups(value)
|
| 115 |
|
| 116 |
return {
|
|
|
|
| 119 |
"filtered_cols": filtered_cols
|
| 120 |
}
|
| 121 |
|
|
|
|
| 122 |
if hasattr(value, '__dataclass_fields__'):
|
| 123 |
field_names = [field.name for field in fields(value)]
|
|
|
|
| 124 |
return {
|
| 125 |
+
"choices": field_names,
|
| 126 |
+
"value": self.initial_selected if self.initial_selected else field_names
|
| 127 |
}
|
| 128 |
|
| 129 |
return super().update(value)
|
|
|
|
| 340 |
# Important: We need to rename our DataFrame columns to match display names
|
| 341 |
renamed_df = dataframe.rename(columns=display_mapping)
|
| 342 |
|
| 343 |
+
# Original code
|
| 344 |
# return Leaderboard(
|
| 345 |
# value=renamed_df, # Use DataFrame with display names
|
| 346 |
# datatype=[c.type for c in fields(AutoEvalColumn_mib_subgraph)],
|
|
|
|
| 353 |
# interactive=False,
|
| 354 |
# )
|
| 355 |
|
| 356 |
+
|
| 357 |
+
|
| 358 |
+
|
| 359 |
+
# # Complete column groups for both benchmarks and models
|
| 360 |
+
# # Define keywords for filtering
|
| 361 |
+
# benchmark_keywords = ["ioi", "mcqa", "arithmetic_addition", "arithmetic_subtraction", "arc_easy", "arc_challenge"]
|
| 362 |
+
# model_keywords = ["qwen2_5", "gpt2", "gemma2", "llama3"]
|
| 363 |
+
|
| 364 |
+
# # Optional: Define display names
|
| 365 |
+
# mappings = {
|
| 366 |
+
# "ioi_llama3": "IOI (LLaMA-3)",
|
| 367 |
+
# "ioi_qwen2_5": "IOI (Qwen-2.5)",
|
| 368 |
+
# "ioi_gpt2": "IOI (GPT-2)",
|
| 369 |
+
# "ioi_gemma2": "IOI (Gemma-2)",
|
| 370 |
+
# "mcqa_llama3": "MCQA (LLaMA-3)",
|
| 371 |
+
# "mcqa_qwen2_5": "MCQA (Qwen-2.5)",
|
| 372 |
+
# "mcqa_gemma2": "MCQA (Gemma-2)",
|
| 373 |
+
# "arithmetic_addition_llama3": "Arithmetic Addition (LLaMA-3)",
|
| 374 |
+
# "arithmetic_subtraction_llama3": "Arithmetic Subtraction (LLaMA-3)",
|
| 375 |
+
# "arc_easy_llama3": "ARC Easy (LLaMA-3)",
|
| 376 |
+
# "arc_easy_gemma2": "ARC Easy (Gemma-2)",
|
| 377 |
+
# "arc_challenge_llama3": "ARC Challenge (LLaMA-3)",
|
| 378 |
+
# "eval_name": "Evaluation Name",
|
| 379 |
+
# "Method": "Method",
|
| 380 |
+
# "Average": "Average Score"
|
| 381 |
+
# }
|
| 382 |
+
# # mappings = {}
|
| 383 |
+
|
| 384 |
+
# # Create SmartSelectColumns instance
|
| 385 |
+
# smart_columns = SmartSelectColumns(
|
| 386 |
+
# benchmark_keywords=benchmark_keywords,
|
| 387 |
+
# model_keywords=model_keywords,
|
| 388 |
+
# column_mapping=mappings,
|
| 389 |
+
# initial_selected=["Method", "Average"]
|
| 390 |
+
# )
|
| 391 |
+
|
| 392 |
+
# print("\nDebugging DataFrame columns:", renamed_df.columns.tolist())
|
| 393 |
+
|
| 394 |
+
# # Create Leaderboard
|
| 395 |
+
# leaderboard = Leaderboard(
|
| 396 |
+
# value=renamed_df,
|
| 397 |
+
# datatype=[c.type for c in fields(AutoEvalColumn_mib_subgraph)],
|
| 398 |
+
# select_columns=smart_columns,
|
| 399 |
+
# search_columns=["Method"],
|
| 400 |
+
# hide_columns=[],
|
| 401 |
+
# interactive=False
|
| 402 |
+
# )
|
| 403 |
+
# print(f"Successfully created leaderboard.")
|
| 404 |
+
# return leaderboard
|
| 405 |
+
|
| 406 |
+
print("\nDebugging DataFrame columns:", dataframe.columns.tolist())
|
| 407 |
+
|
| 408 |
+
# Define simple keywords for filtering
|
| 409 |
+
benchmark_keywords = ["ioi", "mcqa", "arithmetic", "arc"]
|
| 410 |
model_keywords = ["qwen2_5", "gpt2", "gemma2", "llama3"]
|
| 411 |
|
| 412 |
+
# Create SmartSelectColumns with minimal configuration
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 413 |
smart_columns = SmartSelectColumns(
|
| 414 |
benchmark_keywords=benchmark_keywords,
|
| 415 |
model_keywords=model_keywords,
|
|
|
|
| 416 |
initial_selected=["Method", "Average"]
|
| 417 |
)
|
| 418 |
|
| 419 |
+
# Create and return the leaderboard
|
| 420 |
+
print("\nCreating leaderboard...")
|
|
|
|
| 421 |
leaderboard = Leaderboard(
|
| 422 |
+
value=dataframe,
|
| 423 |
datatype=[c.type for c in fields(AutoEvalColumn_mib_subgraph)],
|
| 424 |
select_columns=smart_columns,
|
| 425 |
search_columns=["Method"],
|
| 426 |
hide_columns=[],
|
| 427 |
interactive=False
|
| 428 |
)
|
| 429 |
+
print("Leaderboard created successfully")
|
| 430 |
return leaderboard
|
| 431 |
|
| 432 |
|
|
|
|
| 434 |
|
| 435 |
|
| 436 |
|
|
|
|
|
|
|
|
|
|
| 437 |
# def init_leaderboard_mib_subgraph(dataframe, track):
|
| 438 |
# """Initialize the subgraph leaderboard with group-based column selection."""
|
| 439 |
# if dataframe is None or dataframe.empty:
|