Spaces:
Sleeping
Sleeping
Update leaderboard.py
Browse files- leaderboard.py +4 -229
leaderboard.py
CHANGED
|
@@ -48,13 +48,9 @@ class Leaderboard:
|
|
| 48 |
"""
|
| 49 |
# Get evaluation results from database
|
| 50 |
if tag and tag != "All":
|
| 51 |
-
df = self.db_manager.get_leaderboard_df(tag=tag)
|
| 52 |
else:
|
| 53 |
-
df = self.db_manager.get_leaderboard_df()
|
| 54 |
-
|
| 55 |
-
# Filter by benchmark if specified
|
| 56 |
-
if benchmark_id and not df.empty:
|
| 57 |
-
df = df[df['benchmark_id'] == benchmark_id]
|
| 58 |
|
| 59 |
return df
|
| 60 |
|
|
@@ -68,7 +64,7 @@ class Leaderboard:
|
|
| 68 |
pd.DataFrame: Formatted leaderboard for display
|
| 69 |
"""
|
| 70 |
if df.empty:
|
| 71 |
-
return pd.DataFrame()
|
| 72 |
|
| 73 |
# Select and rename columns for display
|
| 74 |
display_df = df[['model_name', 'benchmark_name', 'tag', 'score', 'completed_at']].copy()
|
|
@@ -157,225 +153,4 @@ class Leaderboard:
|
|
| 157 |
xaxis_title="Tag",
|
| 158 |
yaxis_title="Count"
|
| 159 |
)
|
| 160 |
-
return fig
|
| 161 |
-
|
| 162 |
-
# Count models by tag
|
| 163 |
-
tag_counts = df['tag'].value_counts().reset_index()
|
| 164 |
-
tag_counts.columns = ['Tag', 'Count']
|
| 165 |
-
|
| 166 |
-
# Create pie chart
|
| 167 |
-
fig = px.pie(
|
| 168 |
-
tag_counts,
|
| 169 |
-
names='Tag',
|
| 170 |
-
values='Count',
|
| 171 |
-
title='Model Distribution by Tag',
|
| 172 |
-
color='Tag',
|
| 173 |
-
color_discrete_map=self.tag_colors
|
| 174 |
-
)
|
| 175 |
-
|
| 176 |
-
# Customize layout
|
| 177 |
-
fig.update_layout(
|
| 178 |
-
font=dict(size=12)
|
| 179 |
-
)
|
| 180 |
-
|
| 181 |
-
return fig
|
| 182 |
-
|
| 183 |
-
def create_benchmark_comparison_chart(self, df):
|
| 184 |
-
"""Create a chart comparing performance across benchmarks.
|
| 185 |
-
|
| 186 |
-
Args:
|
| 187 |
-
df: Leaderboard DataFrame
|
| 188 |
-
|
| 189 |
-
Returns:
|
| 190 |
-
plotly.graph_objects.Figure: Benchmark comparison chart
|
| 191 |
-
"""
|
| 192 |
-
if df.empty:
|
| 193 |
-
# Return empty figure
|
| 194 |
-
fig = go.Figure()
|
| 195 |
-
fig.update_layout(
|
| 196 |
-
title="No data available",
|
| 197 |
-
xaxis_title="Benchmark",
|
| 198 |
-
yaxis_title="Average Score"
|
| 199 |
-
)
|
| 200 |
-
return fig
|
| 201 |
-
|
| 202 |
-
# Calculate average score by benchmark
|
| 203 |
-
benchmark_avg = df.groupby('benchmark_name')['score'].mean().reset_index()
|
| 204 |
-
benchmark_avg.columns = ['Benchmark', 'Average Score']
|
| 205 |
-
|
| 206 |
-
# Create bar chart
|
| 207 |
-
fig = px.bar(
|
| 208 |
-
benchmark_avg,
|
| 209 |
-
x='Benchmark',
|
| 210 |
-
y='Average Score',
|
| 211 |
-
title='Average Performance by Benchmark',
|
| 212 |
-
color='Benchmark'
|
| 213 |
-
)
|
| 214 |
-
|
| 215 |
-
# Customize layout
|
| 216 |
-
fig.update_layout(
|
| 217 |
-
xaxis_title="Benchmark",
|
| 218 |
-
yaxis_title="Average Score",
|
| 219 |
-
font=dict(size=12)
|
| 220 |
-
)
|
| 221 |
-
|
| 222 |
-
return fig
|
| 223 |
-
|
| 224 |
-
# Leaderboard UI components
|
| 225 |
-
def create_leaderboard_ui(leaderboard, db_manager):
|
| 226 |
-
"""Create the leaderboard UI components.
|
| 227 |
-
|
| 228 |
-
Args:
|
| 229 |
-
leaderboard: Leaderboard instance
|
| 230 |
-
db_manager: Database manager instance
|
| 231 |
-
|
| 232 |
-
Returns:
|
| 233 |
-
gr.Blocks: Gradio Blocks component with leaderboard UI
|
| 234 |
-
"""
|
| 235 |
-
with gr.Blocks() as leaderboard_ui:
|
| 236 |
-
gr.Markdown("# Dynamic Highscores Leaderboard")
|
| 237 |
-
|
| 238 |
-
with gr.Row():
|
| 239 |
-
with gr.Column(scale=1):
|
| 240 |
-
tag_filter = gr.Dropdown(
|
| 241 |
-
choices=leaderboard.model_tags,
|
| 242 |
-
value="All",
|
| 243 |
-
label="Filter by Tag"
|
| 244 |
-
)
|
| 245 |
-
|
| 246 |
-
benchmark_filter = gr.Dropdown(
|
| 247 |
-
choices=[("all", "All Benchmarks")],
|
| 248 |
-
value="all",
|
| 249 |
-
label="Filter by Benchmark"
|
| 250 |
-
)
|
| 251 |
-
|
| 252 |
-
refresh_button = gr.Button("Refresh Leaderboard")
|
| 253 |
-
|
| 254 |
-
with gr.Column(scale=2):
|
| 255 |
-
chart_type = gr.Radio(
|
| 256 |
-
choices=["bar", "scatter"],
|
| 257 |
-
value="bar",
|
| 258 |
-
label="Chart Type"
|
| 259 |
-
)
|
| 260 |
-
|
| 261 |
-
view_type = gr.Radio(
|
| 262 |
-
choices=["Table", "Chart", "Dashboard"],
|
| 263 |
-
value="Table",
|
| 264 |
-
label="View Type"
|
| 265 |
-
)
|
| 266 |
-
|
| 267 |
-
# Table view
|
| 268 |
-
leaderboard_table = gr.Dataframe(
|
| 269 |
-
headers=["Model", "Benchmark", "Tag", "Score", "Completed"],
|
| 270 |
-
label="Leaderboard",
|
| 271 |
-
visible=True
|
| 272 |
-
)
|
| 273 |
-
|
| 274 |
-
# Chart view
|
| 275 |
-
with gr.Row(visible=False) as chart_view:
|
| 276 |
-
performance_chart = gr.Plot(label="Performance Chart")
|
| 277 |
-
|
| 278 |
-
# Dashboard view
|
| 279 |
-
with gr.Row(visible=False) as dashboard_view:
|
| 280 |
-
with gr.Column(scale=2):
|
| 281 |
-
dashboard_performance_chart = gr.Plot(label="Performance Comparison")
|
| 282 |
-
|
| 283 |
-
with gr.Column(scale=1):
|
| 284 |
-
with gr.Row():
|
| 285 |
-
tag_distribution_chart = gr.Plot(label="Model Distribution")
|
| 286 |
-
|
| 287 |
-
with gr.Row():
|
| 288 |
-
benchmark_comparison_chart = gr.Plot(label="Benchmark Comparison")
|
| 289 |
-
|
| 290 |
-
# Event handlers
|
| 291 |
-
def refresh_benchmarks():
|
| 292 |
-
benchmarks = db_manager.get_benchmarks()
|
| 293 |
-
|
| 294 |
-
# Format for dropdown
|
| 295 |
-
choices = [("all", "All Benchmarks")]
|
| 296 |
-
choices.extend([(str(b["id"]), b["name"]) for b in benchmarks])
|
| 297 |
-
|
| 298 |
-
return gr.update(choices=choices)
|
| 299 |
-
|
| 300 |
-
def update_leaderboard(tag, benchmark_id, chart_type_val, view_type_val):
|
| 301 |
-
# Get leaderboard data
|
| 302 |
-
if benchmark_id == "all":
|
| 303 |
-
benchmark_id = None
|
| 304 |
-
else:
|
| 305 |
-
benchmark_id = int(benchmark_id)
|
| 306 |
-
|
| 307 |
-
df = leaderboard.get_leaderboard_data(tag=tag, benchmark_id=benchmark_id)
|
| 308 |
-
|
| 309 |
-
# Format for display
|
| 310 |
-
display_df = leaderboard.format_leaderboard_for_display(df)
|
| 311 |
-
|
| 312 |
-
# Create charts
|
| 313 |
-
perf_chart = leaderboard.create_performance_chart(df, chart_type=chart_type_val)
|
| 314 |
-
tag_chart = leaderboard.create_tag_distribution_chart(df)
|
| 315 |
-
benchmark_chart = leaderboard.create_benchmark_comparison_chart(df)
|
| 316 |
-
|
| 317 |
-
# Update visibility based on view type
|
| 318 |
-
table_visible = view_type_val == "Table"
|
| 319 |
-
chart_visible = view_type_val == "Chart"
|
| 320 |
-
dashboard_visible = view_type_val == "Dashboard"
|
| 321 |
-
|
| 322 |
-
return (
|
| 323 |
-
display_df,
|
| 324 |
-
perf_chart,
|
| 325 |
-
perf_chart, # Same chart for both views
|
| 326 |
-
tag_chart,
|
| 327 |
-
benchmark_chart,
|
| 328 |
-
gr.update(visible=table_visible),
|
| 329 |
-
gr.update(visible=chart_visible),
|
| 330 |
-
gr.update(visible=dashboard_visible)
|
| 331 |
-
)
|
| 332 |
-
|
| 333 |
-
# Connect event handlers
|
| 334 |
-
refresh_button.click(
|
| 335 |
-
fn=lambda tag, benchmark, chart_t, view_t: update_leaderboard(tag, benchmark, chart_t, view_t),
|
| 336 |
-
inputs=[tag_filter, benchmark_filter, chart_type, view_type],
|
| 337 |
-
outputs=[
|
| 338 |
-
leaderboard_table,
|
| 339 |
-
performance_chart,
|
| 340 |
-
dashboard_performance_chart,
|
| 341 |
-
tag_distribution_chart,
|
| 342 |
-
benchmark_comparison_chart,
|
| 343 |
-
leaderboard_table,
|
| 344 |
-
chart_view,
|
| 345 |
-
dashboard_view
|
| 346 |
-
]
|
| 347 |
-
)
|
| 348 |
-
|
| 349 |
-
view_type.change(
|
| 350 |
-
fn=lambda view_t: (
|
| 351 |
-
gr.update(visible=view_t == "Table"),
|
| 352 |
-
gr.update(visible=view_t == "Chart"),
|
| 353 |
-
gr.update(visible=view_t == "Dashboard")
|
| 354 |
-
),
|
| 355 |
-
inputs=[view_type],
|
| 356 |
-
outputs=[leaderboard_table, chart_view, dashboard_view]
|
| 357 |
-
)
|
| 358 |
-
|
| 359 |
-
# Initialize on load
|
| 360 |
-
leaderboard_ui.load(
|
| 361 |
-
fn=refresh_benchmarks,
|
| 362 |
-
inputs=[],
|
| 363 |
-
outputs=[benchmark_filter]
|
| 364 |
-
)
|
| 365 |
-
|
| 366 |
-
leaderboard_ui.load(
|
| 367 |
-
fn=lambda: update_leaderboard("All", "all", "bar", "Table"),
|
| 368 |
-
inputs=[],
|
| 369 |
-
outputs=[
|
| 370 |
-
leaderboard_table,
|
| 371 |
-
performance_chart,
|
| 372 |
-
dashboard_performance_chart,
|
| 373 |
-
tag_distribution_chart,
|
| 374 |
-
benchmark_comparison_chart,
|
| 375 |
-
leaderboard_table,
|
| 376 |
-
chart_view,
|
| 377 |
-
dashboard_view
|
| 378 |
-
]
|
| 379 |
-
)
|
| 380 |
-
|
| 381 |
-
return leaderboard_ui
|
|
|
|
| 48 |
"""
|
| 49 |
# Get evaluation results from database
|
| 50 |
if tag and tag != "All":
|
| 51 |
+
df = self.db_manager.get_leaderboard_df(tag=tag, benchmark_id=benchmark_id)
|
| 52 |
else:
|
| 53 |
+
df = self.db_manager.get_leaderboard_df(benchmark_id=benchmark_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
return df
|
| 56 |
|
|
|
|
| 64 |
pd.DataFrame: Formatted leaderboard for display
|
| 65 |
"""
|
| 66 |
if df.empty:
|
| 67 |
+
return pd.DataFrame(columns=['Model', 'Benchmark', 'Tag', 'Score', 'Completed'])
|
| 68 |
|
| 69 |
# Select and rename columns for display
|
| 70 |
display_df = df[['model_name', 'benchmark_name', 'tag', 'score', 'completed_at']].copy()
|
|
|
|
| 153 |
xaxis_title="Tag",
|
| 154 |
yaxis_title="Count"
|
| 155 |
)
|
| 156 |
+
return fig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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