Spaces:
Running
Running
sunmarinup commited on
Commit ·
5574759
1
Parent(s): 585a9bb
Get columns from the entry
Browse files- app.py +6 -15
- src/leaderboard/read_evals.py +17 -12
- tests/test_leaderboard.py +8 -7
app.py
CHANGED
|
@@ -6,23 +6,13 @@ import pandas as pd
|
|
| 6 |
|
| 7 |
from src.about import TITLE, INTRODUCTION_TEXT
|
| 8 |
from src.display.css_html_js import custom_css
|
|
|
|
| 9 |
from src.utils import download_github_file_content
|
| 10 |
|
| 11 |
# GitHub API endpoint for the file (handles Git LFS files)
|
| 12 |
LEADERBOARD_API_URL = "https://api.github.com/repos/upgini/mle-bench/contents/rankings/low/tabular/overall_ranks.csv"
|
| 13 |
LEADERBOARD_GITHUB_URL = "https://github.com/upgini/mle-bench/blob/main/rankings/low/tabular/overall_ranks.csv"
|
| 14 |
|
| 15 |
-
DISPLAY_COLUMNS = [
|
| 16 |
-
"experiment_id",
|
| 17 |
-
"Agent",
|
| 18 |
-
"LLM(s) used",
|
| 19 |
-
"mean_normalized_score",
|
| 20 |
-
"std_normalized_score",
|
| 21 |
-
"mean_medal_pct",
|
| 22 |
-
"sem_medal_pct",
|
| 23 |
-
"Date",
|
| 24 |
-
]
|
| 25 |
-
|
| 26 |
|
| 27 |
def download_leaderboard() -> pd.DataFrame:
|
| 28 |
"""Download the remote leaderboard CSV from GitHub (handles Git LFS).
|
|
@@ -32,14 +22,15 @@ def download_leaderboard() -> pd.DataFrame:
|
|
| 32 |
csv_content = download_github_file_content(LEADERBOARD_API_URL, timeout=30)
|
| 33 |
|
| 34 |
df = pd.read_csv(io.StringIO(csv_content))
|
|
|
|
| 35 |
if df.empty:
|
| 36 |
-
return pd.DataFrame(columns=
|
| 37 |
|
| 38 |
-
missing_cols = [col for col in
|
| 39 |
if missing_cols:
|
| 40 |
raise ValueError(f"Leaderboard is missing expected columns: {', '.join(missing_cols)}")
|
| 41 |
|
| 42 |
-
df = df[
|
| 43 |
df["mean_normalized_score"] = df["mean_normalized_score"].round(3)
|
| 44 |
df["std_normalized_score"] = df["std_normalized_score"].round(3)
|
| 45 |
df["mean_medal_pct"] = (df["mean_medal_pct"] * 100).round(1)
|
|
@@ -69,7 +60,7 @@ def create_app():
|
|
| 69 |
gr.Markdown(INTRODUCTION_TEXT)
|
| 70 |
|
| 71 |
leaderboard_table = gr.DataFrame(
|
| 72 |
-
value=pd.DataFrame(columns=
|
| 73 |
wrap=True,
|
| 74 |
interactive=False,
|
| 75 |
type="pandas",
|
|
|
|
| 6 |
|
| 7 |
from src.about import TITLE, INTRODUCTION_TEXT
|
| 8 |
from src.display.css_html_js import custom_css
|
| 9 |
+
from src.leaderboard.read_evals import TabularLeaderboardEntry
|
| 10 |
from src.utils import download_github_file_content
|
| 11 |
|
| 12 |
# GitHub API endpoint for the file (handles Git LFS files)
|
| 13 |
LEADERBOARD_API_URL = "https://api.github.com/repos/upgini/mle-bench/contents/rankings/low/tabular/overall_ranks.csv"
|
| 14 |
LEADERBOARD_GITHUB_URL = "https://github.com/upgini/mle-bench/blob/main/rankings/low/tabular/overall_ranks.csv"
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
def download_leaderboard() -> pd.DataFrame:
|
| 18 |
"""Download the remote leaderboard CSV from GitHub (handles Git LFS).
|
|
|
|
| 22 |
csv_content = download_github_file_content(LEADERBOARD_API_URL, timeout=30)
|
| 23 |
|
| 24 |
df = pd.read_csv(io.StringIO(csv_content))
|
| 25 |
+
display_columns = TabularLeaderboardEntry.get_display_columns()
|
| 26 |
if df.empty:
|
| 27 |
+
return pd.DataFrame(columns=display_columns)
|
| 28 |
|
| 29 |
+
missing_cols = [col for col in display_columns if col not in df.columns]
|
| 30 |
if missing_cols:
|
| 31 |
raise ValueError(f"Leaderboard is missing expected columns: {', '.join(missing_cols)}")
|
| 32 |
|
| 33 |
+
df = df[display_columns].copy()
|
| 34 |
df["mean_normalized_score"] = df["mean_normalized_score"].round(3)
|
| 35 |
df["std_normalized_score"] = df["std_normalized_score"].round(3)
|
| 36 |
df["mean_medal_pct"] = (df["mean_medal_pct"] * 100).round(1)
|
|
|
|
| 60 |
gr.Markdown(INTRODUCTION_TEXT)
|
| 61 |
|
| 62 |
leaderboard_table = gr.DataFrame(
|
| 63 |
+
value=pd.DataFrame(columns=TabularLeaderboardEntry.get_display_columns()),
|
| 64 |
wrap=True,
|
| 65 |
interactive=False,
|
| 66 |
type="pandas",
|
src/leaderboard/read_evals.py
CHANGED
|
@@ -21,6 +21,22 @@ class TabularLeaderboardEntry:
|
|
| 21 |
sem_medal_pct: float
|
| 22 |
date: str
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
@classmethod
|
| 25 |
def from_dataframe_row(cls, row: pd.Series) -> "TabularLeaderboardEntry":
|
| 26 |
"""Create a TabularLeaderboardEntry from a pandas DataFrame row."""
|
|
@@ -69,18 +85,7 @@ def parse_tabular_leaderboard(df: pd.DataFrame) -> list[TabularLeaderboardEntry]
|
|
| 69 |
def tabular_leaderboard_to_dataframe(entries: list[TabularLeaderboardEntry]) -> pd.DataFrame:
|
| 70 |
"""Convert a list of TabularLeaderboardEntry objects to a DataFrame."""
|
| 71 |
if not entries:
|
| 72 |
-
return pd.DataFrame(
|
| 73 |
-
columns=[
|
| 74 |
-
"experiment_id",
|
| 75 |
-
"Agent",
|
| 76 |
-
"LLM(s) used",
|
| 77 |
-
"mean_normalized_score",
|
| 78 |
-
"std_normalized_score",
|
| 79 |
-
"mean_medal_pct",
|
| 80 |
-
"sem_medal_pct",
|
| 81 |
-
"Date",
|
| 82 |
-
]
|
| 83 |
-
)
|
| 84 |
|
| 85 |
data = [entry.to_dict() for entry in entries]
|
| 86 |
return pd.DataFrame(data)
|
|
|
|
| 21 |
sem_medal_pct: float
|
| 22 |
date: str
|
| 23 |
|
| 24 |
+
@classmethod
|
| 25 |
+
def get_display_columns(cls) -> list[str]:
|
| 26 |
+
"""Get the list of column names for DataFrame display."""
|
| 27 |
+
# Create a dummy instance to get the column order from to_dict()
|
| 28 |
+
dummy = cls(
|
| 29 |
+
experiment_id="",
|
| 30 |
+
agent="",
|
| 31 |
+
llms_used="",
|
| 32 |
+
mean_normalized_score=0.0,
|
| 33 |
+
std_normalized_score=0.0,
|
| 34 |
+
mean_medal_pct=0.0,
|
| 35 |
+
sem_medal_pct=0.0,
|
| 36 |
+
date="",
|
| 37 |
+
)
|
| 38 |
+
return list(dummy.to_dict().keys())
|
| 39 |
+
|
| 40 |
@classmethod
|
| 41 |
def from_dataframe_row(cls, row: pd.Series) -> "TabularLeaderboardEntry":
|
| 42 |
"""Create a TabularLeaderboardEntry from a pandas DataFrame row."""
|
|
|
|
| 85 |
def tabular_leaderboard_to_dataframe(entries: list[TabularLeaderboardEntry]) -> pd.DataFrame:
|
| 86 |
"""Convert a list of TabularLeaderboardEntry objects to a DataFrame."""
|
| 87 |
if not entries:
|
| 88 |
+
return pd.DataFrame(columns=TabularLeaderboardEntry.get_display_columns())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
data = [entry.to_dict() for entry in entries]
|
| 91 |
return pd.DataFrame(data)
|
tests/test_leaderboard.py
CHANGED
|
@@ -4,7 +4,8 @@ import pandas as pd
|
|
| 4 |
import pytest
|
| 5 |
import requests
|
| 6 |
|
| 7 |
-
from app import
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
@pytest.fixture
|
|
@@ -53,7 +54,7 @@ class TestDownloadLeaderboard:
|
|
| 53 |
# Assertions
|
| 54 |
assert isinstance(df, pd.DataFrame)
|
| 55 |
assert len(df) == 3
|
| 56 |
-
assert list(df.columns) ==
|
| 57 |
mock_download.assert_called_once()
|
| 58 |
|
| 59 |
@patch("app.download_github_file_content")
|
|
@@ -119,7 +120,7 @@ class TestDownloadLeaderboard:
|
|
| 119 |
|
| 120 |
# Check that df is created correctly (extra columns should be filtered)
|
| 121 |
assert len(df) == 2
|
| 122 |
-
assert list(df.columns) ==
|
| 123 |
# Verify the df doesn't have extra columns
|
| 124 |
assert "extra_col" not in df.columns
|
| 125 |
|
|
@@ -167,14 +168,14 @@ class TestDownloadLeaderboard:
|
|
| 167 |
@patch("app.download_github_file_content")
|
| 168 |
def test_empty_dataframe(self, mock_download):
|
| 169 |
"""Test handling of empty CSV (header only)."""
|
| 170 |
-
csv_data = ",".join(
|
| 171 |
mock_download.return_value = csv_data
|
| 172 |
|
| 173 |
df = download_leaderboard()
|
| 174 |
|
| 175 |
assert isinstance(df, pd.DataFrame)
|
| 176 |
assert len(df) == 0
|
| 177 |
-
assert list(df.columns) ==
|
| 178 |
|
| 179 |
@patch("app.download_github_file_content")
|
| 180 |
def test_invalid_date_handling(self, mock_download):
|
|
@@ -207,7 +208,7 @@ class TestDownloadLeaderboard:
|
|
| 207 |
# Should successfully download via download_url
|
| 208 |
assert isinstance(df, pd.DataFrame)
|
| 209 |
assert len(df) == 3
|
| 210 |
-
assert list(df.columns) ==
|
| 211 |
mock_download.assert_called_once()
|
| 212 |
|
| 213 |
@patch("app.download_github_file_content")
|
|
@@ -220,7 +221,7 @@ class TestDownloadLeaderboard:
|
|
| 220 |
|
| 221 |
assert isinstance(df, pd.DataFrame)
|
| 222 |
assert len(df) == 3
|
| 223 |
-
assert list(df.columns) ==
|
| 224 |
mock_download.assert_called_once()
|
| 225 |
|
| 226 |
|
|
|
|
| 4 |
import pytest
|
| 5 |
import requests
|
| 6 |
|
| 7 |
+
from app import download_leaderboard, refresh_leaderboard
|
| 8 |
+
from src.leaderboard.read_evals import TabularLeaderboardEntry
|
| 9 |
|
| 10 |
|
| 11 |
@pytest.fixture
|
|
|
|
| 54 |
# Assertions
|
| 55 |
assert isinstance(df, pd.DataFrame)
|
| 56 |
assert len(df) == 3
|
| 57 |
+
assert list(df.columns) == TabularLeaderboardEntry.get_display_columns()
|
| 58 |
mock_download.assert_called_once()
|
| 59 |
|
| 60 |
@patch("app.download_github_file_content")
|
|
|
|
| 120 |
|
| 121 |
# Check that df is created correctly (extra columns should be filtered)
|
| 122 |
assert len(df) == 2
|
| 123 |
+
assert list(df.columns) == TabularLeaderboardEntry.get_display_columns()
|
| 124 |
# Verify the df doesn't have extra columns
|
| 125 |
assert "extra_col" not in df.columns
|
| 126 |
|
|
|
|
| 168 |
@patch("app.download_github_file_content")
|
| 169 |
def test_empty_dataframe(self, mock_download):
|
| 170 |
"""Test handling of empty CSV (header only)."""
|
| 171 |
+
csv_data = ",".join(TabularLeaderboardEntry.get_display_columns()) # Header only
|
| 172 |
mock_download.return_value = csv_data
|
| 173 |
|
| 174 |
df = download_leaderboard()
|
| 175 |
|
| 176 |
assert isinstance(df, pd.DataFrame)
|
| 177 |
assert len(df) == 0
|
| 178 |
+
assert list(df.columns) == TabularLeaderboardEntry.get_display_columns()
|
| 179 |
|
| 180 |
@patch("app.download_github_file_content")
|
| 181 |
def test_invalid_date_handling(self, mock_download):
|
|
|
|
| 208 |
# Should successfully download via download_url
|
| 209 |
assert isinstance(df, pd.DataFrame)
|
| 210 |
assert len(df) == 3
|
| 211 |
+
assert list(df.columns) == TabularLeaderboardEntry.get_display_columns()
|
| 212 |
mock_download.assert_called_once()
|
| 213 |
|
| 214 |
@patch("app.download_github_file_content")
|
|
|
|
| 221 |
|
| 222 |
assert isinstance(df, pd.DataFrame)
|
| 223 |
assert len(df) == 3
|
| 224 |
+
assert list(df.columns) == TabularLeaderboardEntry.get_display_columns()
|
| 225 |
mock_download.assert_called_once()
|
| 226 |
|
| 227 |
|