Spaces:
Running
Running
Commit
·
0bac2c0
1
Parent(s):
66a9b43
Add GPT-OSS github repo link
Browse files- frontend/layout.py +277 -115
frontend/layout.py
CHANGED
|
@@ -9,7 +9,12 @@ from .content import LeaderboardContent, AboutContent, SubmissionContent
|
|
| 9 |
from frontend.leaderboard import refresh_leaderboard, format_parameter_count
|
| 10 |
import os
|
| 11 |
import pandas as pd
|
| 12 |
-
from gradio_leaderboard import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
from pathlib import Path
|
| 14 |
import inspect
|
| 15 |
|
|
@@ -44,8 +49,16 @@ def create_leaderboard_tab(refresh_callback: Callable = None) -> gr.TabItem:
|
|
| 44 |
col_name = col[1] if isinstance(col, tuple) else col
|
| 45 |
|
| 46 |
# Always show these columns
|
| 47 |
-
if col_name in [
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
default_visible.append(col)
|
| 50 |
# Show all ROC-AUC and ΔAUC-PR task columns
|
| 51 |
elif col_group in ["ROC-AUC", "ΔAUC-PR"]:
|
|
@@ -60,8 +73,12 @@ def create_leaderboard_tab(refresh_callback: Callable = None) -> gr.TabItem:
|
|
| 60 |
else refresh_leaderboard().reset_index(drop=True)
|
| 61 |
)
|
| 62 |
|
| 63 |
-
new_data[("", "Avg. AUC")] = pd.to_numeric(
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
ranks = []
|
| 66 |
for i in range(1, len(new_data) + 1):
|
| 67 |
if i == 1:
|
|
@@ -80,9 +97,18 @@ def create_leaderboard_tab(refresh_callback: Callable = None) -> gr.TabItem:
|
|
| 80 |
if search and search.strip():
|
| 81 |
search = search.lower()
|
| 82 |
mask = (
|
| 83 |
-
filtered[("", "Model")]
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
)
|
| 87 |
filtered = filtered[mask]
|
| 88 |
|
|
@@ -90,7 +116,9 @@ def create_leaderboard_tab(refresh_callback: Callable = None) -> gr.TabItem:
|
|
| 90 |
if type_filter and len(type_filter) > 0:
|
| 91 |
# Extract emoji by splitting on space and taking first part
|
| 92 |
# e.g., "0️⃣ Zero-shot" -> "0️⃣"
|
| 93 |
-
type_emojis = [
|
|
|
|
|
|
|
| 94 |
filtered = filtered[filtered[("", "Type")].isin(type_emojis)]
|
| 95 |
|
| 96 |
# Min AUC filter
|
|
@@ -105,7 +133,11 @@ def create_leaderboard_tab(refresh_callback: Callable = None) -> gr.TabItem:
|
|
| 105 |
selected_columns = get_default_columns(df)
|
| 106 |
|
| 107 |
# Always hide these columns (used for links and tooltips)
|
| 108 |
-
always_hidden = [
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
html = "<div class='leaderboard-container'><table class='leaderboard-table sortable-table'>"
|
| 111 |
|
|
@@ -168,7 +200,11 @@ def create_leaderboard_tab(refresh_callback: Callable = None) -> gr.TabItem:
|
|
| 168 |
continue
|
| 169 |
if top not in ("", None):
|
| 170 |
# Add col-score class to AUC columns for consistent width handling
|
| 171 |
-
extra_class =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
html += f"<th class='sortable-header{extra_class}' data-column='{col_idx}' onclick='sortTable({col_idx})'>{sub} <span class='sort-indicator'></span></th>"
|
| 173 |
col_idx += 1
|
| 174 |
html += "</tr>"
|
|
@@ -227,19 +263,29 @@ def create_leaderboard_tab(refresh_callback: Callable = None) -> gr.TabItem:
|
|
| 227 |
css_class = "col-date"
|
| 228 |
elif col_name in ["Pretrained", "Zero-shot", "Few-shot"]:
|
| 229 |
css_class = "col-boolean"
|
| 230 |
-
elif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
css_class = "col-score"
|
| 232 |
|
| 233 |
# Get string value for title attribute (escape quotes for HTML)
|
| 234 |
val_str = str(val) if val is not None else ""
|
| 235 |
-
val_str_escaped = val_str.replace('"',
|
| 236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
|
| 238 |
# Helper function to check if value should be displayed as empty
|
| 239 |
def is_empty_value(v):
|
| 240 |
if pd.isna(v) or v is None:
|
| 241 |
return True
|
| 242 |
-
if str(v).lower().strip() in [
|
| 243 |
return True
|
| 244 |
return False
|
| 245 |
|
|
@@ -247,9 +293,16 @@ def create_leaderboard_tab(refresh_callback: Callable = None) -> gr.TabItem:
|
|
| 247 |
if col == ("", "Model"):
|
| 248 |
tag_str = str(hf_space_tag).strip().lower()
|
| 249 |
display_val = "" if is_empty_value(val) else val
|
| 250 |
-
if
|
| 251 |
-
|
| 252 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
else:
|
| 254 |
html += f"<td class='{css_class}'{title_attr}>{display_val}</td>"
|
| 255 |
|
|
@@ -257,14 +310,24 @@ def create_leaderboard_tab(refresh_callback: Callable = None) -> gr.TabItem:
|
|
| 257 |
elif col == ("", "Publication"):
|
| 258 |
# Create custom tooltip with Publication and Model Description
|
| 259 |
pub_str = str(val) if val is not None else ""
|
| 260 |
-
desc_str =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
custom_tooltip = f"Publication:\n{pub_str}\n\nModel Description:\n{desc_str}"
|
| 262 |
-
custom_tooltip_escaped = custom_tooltip.replace(
|
|
|
|
|
|
|
| 263 |
custom_title_attr = f' title="{custom_tooltip_escaped}"'
|
| 264 |
|
| 265 |
display_val = "" if is_empty_value(val) else val
|
| 266 |
link_str = str(publication_link).strip().lower()
|
| 267 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
# Put custom title on the link itself
|
| 269 |
html += f"<td class='{css_class}'><a href='{publication_link}' target='_blank' style='color: #20C2D9; text-decoration: none;'{custom_title_attr}>{display_val}</a></td>"
|
| 270 |
else:
|
|
@@ -274,7 +337,11 @@ def create_leaderboard_tab(refresh_callback: Callable = None) -> gr.TabItem:
|
|
| 274 |
elif col == ("", "# Parameters"):
|
| 275 |
formatted_val = format_parameter_count(val)
|
| 276 |
# Store raw numeric value in data-value for sorting
|
| 277 |
-
data_value_attr =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
html += f"<td class='{css_class}'{data_value_attr}{title_attr}>{formatted_val}</td>"
|
| 279 |
|
| 280 |
else:
|
|
@@ -481,18 +548,20 @@ table.leaderboard-table th.col-score {
|
|
| 481 |
|
| 482 |
return html
|
| 483 |
|
| 484 |
-
|
| 485 |
-
|
| 486 |
# Header section
|
| 487 |
print(Leaderboard.__module__)
|
| 488 |
header_html = gr.HTML(LeaderboardContent.get_header_html())
|
| 489 |
|
| 490 |
# Load initial data
|
| 491 |
-
result_data = refresh_leaderboard()
|
| 492 |
|
| 493 |
# add rank column with medals for top 3
|
| 494 |
-
result_data[("", "Avg. AUC")] = pd.to_numeric(
|
| 495 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 496 |
ranks = []
|
| 497 |
for i in range(1, len(result_data) + 1):
|
| 498 |
if i == 1:
|
|
@@ -514,18 +583,32 @@ table.leaderboard-table th.col-score {
|
|
| 514 |
elem_id="leaderboard-search",
|
| 515 |
container=False,
|
| 516 |
max_lines=1,
|
| 517 |
-
type="text"
|
| 518 |
)
|
| 519 |
|
| 520 |
# Filters in an accordion
|
| 521 |
-
with gr.Accordion(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 522 |
with gr.Row():
|
| 523 |
# Type filter (multi-select checkboxes)
|
| 524 |
type_filter = gr.CheckboxGroup(
|
| 525 |
-
choices=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 526 |
label="Model Type",
|
| 527 |
-
value=[
|
| 528 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 529 |
)
|
| 530 |
|
| 531 |
# Min AUC filter
|
|
@@ -534,13 +617,21 @@ table.leaderboard-table th.col-score {
|
|
| 534 |
value=0,
|
| 535 |
minimum=0,
|
| 536 |
maximum=1,
|
| 537 |
-
step=0.01
|
| 538 |
)
|
| 539 |
|
| 540 |
# Column selection dropdown
|
| 541 |
# Get all column names for the dropdown
|
| 542 |
-
all_columns = [
|
| 543 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 544 |
default_columns = get_default_columns(result_data)
|
| 545 |
|
| 546 |
# Format column names for display
|
|
@@ -557,7 +648,8 @@ table.leaderboard-table th.col-score {
|
|
| 557 |
# Create mapping from display name to actual column
|
| 558 |
column_display_to_actual = dict(zip(column_choices, column_values))
|
| 559 |
default_display_names = [
|
| 560 |
-
display_name
|
|
|
|
| 561 |
if col in default_columns
|
| 562 |
]
|
| 563 |
|
|
@@ -565,7 +657,7 @@ table.leaderboard-table th.col-score {
|
|
| 565 |
choices=column_choices,
|
| 566 |
value=default_display_names,
|
| 567 |
label="Select Columns to Display",
|
| 568 |
-
interactive=True
|
| 569 |
)
|
| 570 |
|
| 571 |
# Refresh button
|
|
@@ -581,9 +673,14 @@ table.leaderboard-table th.col-score {
|
|
| 581 |
table = gr.HTML(make_html_table(result_data))
|
| 582 |
|
| 583 |
# Wire up the filter components
|
| 584 |
-
def apply_filters_wrapper(
|
|
|
|
|
|
|
| 585 |
# Convert display names back to actual column tuples
|
| 586 |
-
selected_columns = [
|
|
|
|
|
|
|
|
|
|
| 587 |
return apply_filters(search, type_filter, min_auc, selected_columns)
|
| 588 |
|
| 589 |
# Connect all inputs to apply_filters
|
|
@@ -591,10 +688,14 @@ table.leaderboard-table th.col-score {
|
|
| 591 |
component.change(
|
| 592 |
fn=apply_filters_wrapper,
|
| 593 |
inputs=[search, type_filter, min_auc, column_selector],
|
| 594 |
-
outputs=table
|
| 595 |
)
|
| 596 |
|
| 597 |
-
refresh_btn.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 598 |
|
| 599 |
# Connect refresh button
|
| 600 |
def refresh_data():
|
|
@@ -607,7 +708,10 @@ table.leaderboard-table th.col-score {
|
|
| 607 |
return new_data
|
| 608 |
|
| 609 |
# Info section
|
| 610 |
-
info_html = gr.HTML(
|
|
|
|
|
|
|
|
|
|
| 611 |
|
| 612 |
return tab, table
|
| 613 |
|
|
@@ -628,52 +732,76 @@ def create_submission_tab(submit_callback: Callable = None) -> gr.TabItem:
|
|
| 628 |
|
| 629 |
with gr.TabItem("Submit", elem_id="submission-tab", id=2) as tab:
|
| 630 |
with gr.Blocks(elem_classes=["form-wrapper"]):
|
| 631 |
-
gr.HTML(
|
|
|
|
| 632 |
<h2 class="header-emoji">{SubmissionContent.emoji}</h2>
|
| 633 |
<h2 class="header-title">{SubmissionContent.title}</h2>
|
| 634 |
-
</div>"""
|
|
|
|
| 635 |
|
| 636 |
# Instructions
|
| 637 |
-
instructions_html = gr.HTML(
|
|
|
|
|
|
|
| 638 |
|
| 639 |
# Submission form
|
| 640 |
with gr.Blocks():
|
| 641 |
# Required fields
|
| 642 |
-
gr.HTML(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 643 |
model_name = gr.Textbox(
|
| 644 |
show_label=True,
|
| 645 |
-
placeholder=SubmissionContent.form_placeholders[
|
| 646 |
-
|
|
|
|
|
|
|
| 647 |
container=False,
|
| 648 |
elem_classes=["form-container"],
|
| 649 |
max_lines=1,
|
| 650 |
)
|
| 651 |
|
| 652 |
-
gr.HTML(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 653 |
hf_space_tag = gr.Textbox(
|
| 654 |
label=SubmissionContent.form_labels["hf_space_tag"],
|
| 655 |
-
placeholder=SubmissionContent.form_placeholders[
|
| 656 |
-
|
|
|
|
|
|
|
| 657 |
container=False,
|
| 658 |
max_lines=1,
|
| 659 |
-
elem_classes=["form-container"]
|
| 660 |
)
|
| 661 |
|
| 662 |
-
gr.HTML(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 663 |
model_description = gr.Textbox(
|
| 664 |
label=SubmissionContent.form_labels["model_description"],
|
| 665 |
placeholder=SubmissionContent.form_placeholders[
|
| 666 |
"model_description"
|
| 667 |
],
|
| 668 |
-
#info=SubmissionContent.form_info["model_description"],
|
| 669 |
lines=3,
|
| 670 |
container=False,
|
| 671 |
-
elem_classes=["form-container"]
|
| 672 |
)
|
| 673 |
|
| 674 |
# Optional fields in accordion
|
| 675 |
# with gr.Accordion("Additional Information", open=False):
|
| 676 |
-
gr.HTML(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 677 |
organization = gr.Textbox(
|
| 678 |
label=SubmissionContent.form_labels["organization"],
|
| 679 |
placeholder=SubmissionContent.form_placeholders[
|
|
@@ -684,27 +812,39 @@ def create_submission_tab(submit_callback: Callable = None) -> gr.TabItem:
|
|
| 684 |
max_lines=1,
|
| 685 |
)
|
| 686 |
|
| 687 |
-
gr.HTML(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 688 |
model_size = gr.Textbox(
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
|
| 692 |
-
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
|
| 697 |
|
| 698 |
-
gr.HTML(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 699 |
pretrained = gr.Radio(
|
| 700 |
choices=["Yes", "No"],
|
| 701 |
value="No",
|
| 702 |
container=False,
|
| 703 |
-
elem_classes=["form-container-radio"]
|
| 704 |
)
|
| 705 |
|
| 706 |
-
pretraining_label = gr.HTML(
|
| 707 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 708 |
pretraining_data = gr.Textbox(
|
| 709 |
label=SubmissionContent.form_labels["pretraining_data"],
|
| 710 |
placeholder=SubmissionContent.form_placeholders[
|
|
@@ -713,16 +853,13 @@ def create_submission_tab(submit_callback: Callable = None) -> gr.TabItem:
|
|
| 713 |
visible=False,
|
| 714 |
container=False,
|
| 715 |
max_lines=1,
|
| 716 |
-
elem_classes=["form-container"]
|
| 717 |
)
|
| 718 |
|
| 719 |
# When checkbox changes, update visibility
|
| 720 |
def toggle_pretrain_fields(choice):
|
| 721 |
-
show =
|
| 722 |
-
return [
|
| 723 |
-
gr.update(visible=show),
|
| 724 |
-
gr.update(visible=show)
|
| 725 |
-
]
|
| 726 |
|
| 727 |
pretrained.change(
|
| 728 |
fn=toggle_pretrain_fields,
|
|
@@ -730,15 +867,18 @@ def create_submission_tab(submit_callback: Callable = None) -> gr.TabItem:
|
|
| 730 |
outputs=[pretraining_label, pretraining_data],
|
| 731 |
)
|
| 732 |
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
|
| 740 |
-
gr.HTML(
|
| 741 |
-
|
|
|
|
|
|
|
|
|
|
| 742 |
publication_title = gr.Textbox(
|
| 743 |
label=SubmissionContent.form_labels["publication_title"],
|
| 744 |
placeholder=SubmissionContent.form_placeholders[
|
|
@@ -746,10 +886,14 @@ def create_submission_tab(submit_callback: Callable = None) -> gr.TabItem:
|
|
| 746 |
],
|
| 747 |
container=False,
|
| 748 |
max_lines=1,
|
| 749 |
-
elem_classes=["form-container"]
|
| 750 |
)
|
| 751 |
|
| 752 |
-
gr.HTML(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 753 |
publication_link = gr.Textbox(
|
| 754 |
label=SubmissionContent.form_labels["publication_link"],
|
| 755 |
placeholder=SubmissionContent.form_placeholders[
|
|
@@ -757,45 +901,51 @@ def create_submission_tab(submit_callback: Callable = None) -> gr.TabItem:
|
|
| 757 |
],
|
| 758 |
max_lines=1,
|
| 759 |
container=False,
|
| 760 |
-
elem_classes=["form-container"]
|
| 761 |
)
|
| 762 |
|
| 763 |
-
gr.HTML(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 764 |
zero_shot = gr.Radio(
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
gr.HTML(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 772 |
few_shot = gr.Radio(
|
| 773 |
choices=["Yes", "No"],
|
| 774 |
value="No",
|
| 775 |
container=False,
|
| 776 |
-
elem_classes=["form-container-radio"]
|
| 777 |
)
|
| 778 |
|
| 779 |
-
n_shot_label = gr.HTML(
|
| 780 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 781 |
n_shot = gr.Textbox(
|
| 782 |
label=SubmissionContent.form_labels["n_shot"],
|
| 783 |
-
placeholder=SubmissionContent.form_placeholders[
|
| 784 |
-
"n_shot"
|
| 785 |
-
],
|
| 786 |
visible=False,
|
| 787 |
container=False,
|
| 788 |
max_lines=1,
|
| 789 |
-
elem_classes=["form-container"]
|
| 790 |
)
|
| 791 |
|
| 792 |
-
|
| 793 |
def toggle_n_shot_fields(choice):
|
| 794 |
-
show =
|
| 795 |
-
return [
|
| 796 |
-
gr.update(visible=show),
|
| 797 |
-
gr.update(visible=show)
|
| 798 |
-
]
|
| 799 |
|
| 800 |
few_shot.change(
|
| 801 |
fn=toggle_n_shot_fields,
|
|
@@ -803,15 +953,25 @@ def create_submission_tab(submit_callback: Callable = None) -> gr.TabItem:
|
|
| 803 |
outputs=[n_shot_label, n_shot],
|
| 804 |
)
|
| 805 |
|
| 806 |
-
agree = gr.Checkbox(
|
| 807 |
-
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
|
|
|
| 811 |
|
| 812 |
# Submit button and result
|
| 813 |
-
submit_btn = gr.Button(
|
| 814 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 815 |
result_msg = gr.HTML()
|
| 816 |
|
| 817 |
if submit_callback:
|
|
@@ -939,7 +1099,9 @@ function() {
|
|
| 939 |
radio_circle="#20C2D9",
|
| 940 |
)
|
| 941 |
|
| 942 |
-
with gr.Blocks(
|
|
|
|
|
|
|
| 943 |
# Tab container
|
| 944 |
with gr.Tabs(elem_classes="tab-nav") as tabs:
|
| 945 |
|
|
|
|
| 9 |
from frontend.leaderboard import refresh_leaderboard, format_parameter_count
|
| 10 |
import os
|
| 11 |
import pandas as pd
|
| 12 |
+
from gradio_leaderboard import (
|
| 13 |
+
Leaderboard,
|
| 14 |
+
SearchColumns,
|
| 15 |
+
ColumnFilter,
|
| 16 |
+
SelectColumns,
|
| 17 |
+
)
|
| 18 |
from pathlib import Path
|
| 19 |
import inspect
|
| 20 |
|
|
|
|
| 49 |
col_name = col[1] if isinstance(col, tuple) else col
|
| 50 |
|
| 51 |
# Always show these columns
|
| 52 |
+
if col_name in [
|
| 53 |
+
"Rank",
|
| 54 |
+
"Type",
|
| 55 |
+
"Model",
|
| 56 |
+
"Organization",
|
| 57 |
+
"Publication",
|
| 58 |
+
"Avg. AUC",
|
| 59 |
+
"Avg. ΔAUC-PR",
|
| 60 |
+
"# Parameters",
|
| 61 |
+
]:
|
| 62 |
default_visible.append(col)
|
| 63 |
# Show all ROC-AUC and ΔAUC-PR task columns
|
| 64 |
elif col_group in ["ROC-AUC", "ΔAUC-PR"]:
|
|
|
|
| 73 |
else refresh_leaderboard().reset_index(drop=True)
|
| 74 |
)
|
| 75 |
|
| 76 |
+
new_data[("", "Avg. AUC")] = pd.to_numeric(
|
| 77 |
+
new_data[("", "Avg. AUC")], errors="coerce"
|
| 78 |
+
)
|
| 79 |
+
new_data = new_data.sort_values(
|
| 80 |
+
by=("", "Avg. AUC"), ascending=False, na_position="last"
|
| 81 |
+
)
|
| 82 |
ranks = []
|
| 83 |
for i in range(1, len(new_data) + 1):
|
| 84 |
if i == 1:
|
|
|
|
| 97 |
if search and search.strip():
|
| 98 |
search = search.lower()
|
| 99 |
mask = (
|
| 100 |
+
filtered[("", "Model")]
|
| 101 |
+
.astype(str)
|
| 102 |
+
.str.lower()
|
| 103 |
+
.str.contains(search, na=False)
|
| 104 |
+
| filtered[("", "Organization")]
|
| 105 |
+
.astype(str)
|
| 106 |
+
.str.lower()
|
| 107 |
+
.str.contains(search, na=False)
|
| 108 |
+
| filtered[("", "Publication")]
|
| 109 |
+
.astype(str)
|
| 110 |
+
.str.lower()
|
| 111 |
+
.str.contains(search, na=False)
|
| 112 |
)
|
| 113 |
filtered = filtered[mask]
|
| 114 |
|
|
|
|
| 116 |
if type_filter and len(type_filter) > 0:
|
| 117 |
# Extract emoji by splitting on space and taking first part
|
| 118 |
# e.g., "0️⃣ Zero-shot" -> "0️⃣"
|
| 119 |
+
type_emojis = [
|
| 120 |
+
t.split(" ")[0] if " " in t else t for t in type_filter
|
| 121 |
+
]
|
| 122 |
filtered = filtered[filtered[("", "Type")].isin(type_emojis)]
|
| 123 |
|
| 124 |
# Min AUC filter
|
|
|
|
| 133 |
selected_columns = get_default_columns(df)
|
| 134 |
|
| 135 |
# Always hide these columns (used for links and tooltips)
|
| 136 |
+
always_hidden = [
|
| 137 |
+
("", "HF_Space_Tag"),
|
| 138 |
+
("", "Publication Link"),
|
| 139 |
+
("", "Model Description"),
|
| 140 |
+
]
|
| 141 |
|
| 142 |
html = "<div class='leaderboard-container'><table class='leaderboard-table sortable-table'>"
|
| 143 |
|
|
|
|
| 200 |
continue
|
| 201 |
if top not in ("", None):
|
| 202 |
# Add col-score class to AUC columns for consistent width handling
|
| 203 |
+
extra_class = (
|
| 204 |
+
" col-score"
|
| 205 |
+
if "AUC" in top or "ΔAUC" in top
|
| 206 |
+
else ""
|
| 207 |
+
)
|
| 208 |
html += f"<th class='sortable-header{extra_class}' data-column='{col_idx}' onclick='sortTable({col_idx})'>{sub} <span class='sort-indicator'></span></th>"
|
| 209 |
col_idx += 1
|
| 210 |
html += "</tr>"
|
|
|
|
| 263 |
css_class = "col-date"
|
| 264 |
elif col_name in ["Pretrained", "Zero-shot", "Few-shot"]:
|
| 265 |
css_class = "col-boolean"
|
| 266 |
+
elif (
|
| 267 |
+
"AUC" in col_name
|
| 268 |
+
or "ΔAUC" in col_name
|
| 269 |
+
or "Avg." in col_name
|
| 270 |
+
or "AUC" in col_group
|
| 271 |
+
or "ΔAUC" in col_group
|
| 272 |
+
):
|
| 273 |
css_class = "col-score"
|
| 274 |
|
| 275 |
# Get string value for title attribute (escape quotes for HTML)
|
| 276 |
val_str = str(val) if val is not None else ""
|
| 277 |
+
val_str_escaped = val_str.replace('"', """).replace(
|
| 278 |
+
"'", "'"
|
| 279 |
+
)
|
| 280 |
+
title_attr = (
|
| 281 |
+
f' title="{val_str_escaped}"' if val_str else ""
|
| 282 |
+
)
|
| 283 |
|
| 284 |
# Helper function to check if value should be displayed as empty
|
| 285 |
def is_empty_value(v):
|
| 286 |
if pd.isna(v) or v is None:
|
| 287 |
return True
|
| 288 |
+
if str(v).lower().strip() in ["nan", "none", ""]:
|
| 289 |
return True
|
| 290 |
return False
|
| 291 |
|
|
|
|
| 293 |
if col == ("", "Model"):
|
| 294 |
tag_str = str(hf_space_tag).strip().lower()
|
| 295 |
display_val = "" if is_empty_value(val) else val
|
| 296 |
+
if (
|
| 297 |
+
hf_space_tag
|
| 298 |
+
and tag_str
|
| 299 |
+
and tag_str not in ["none", "nan", "", "."]
|
| 300 |
+
):
|
| 301 |
+
if "github" in hf_space_tag:
|
| 302 |
+
html += f"<td class='{css_class}'><a href='{hf_space_tag}' target='_blank' style='color: #20C2D9; text-decoration: none;'{title_attr}>{display_val}</a></td>"
|
| 303 |
+
else:
|
| 304 |
+
# Put title on the link itself, not the td
|
| 305 |
+
html += f"<td class='{css_class}'><a href='https://huggingface.co/spaces/{hf_space_tag}/blob/main/README.md' target='_blank' style='color: #20C2D9; text-decoration: none;'{title_attr}>{display_val}</a></td>"
|
| 306 |
else:
|
| 307 |
html += f"<td class='{css_class}'{title_attr}>{display_val}</td>"
|
| 308 |
|
|
|
|
| 310 |
elif col == ("", "Publication"):
|
| 311 |
# Create custom tooltip with Publication and Model Description
|
| 312 |
pub_str = str(val) if val is not None else ""
|
| 313 |
+
desc_str = (
|
| 314 |
+
str(model_description)
|
| 315 |
+
if model_description
|
| 316 |
+
else "No description available"
|
| 317 |
+
)
|
| 318 |
custom_tooltip = f"Publication:\n{pub_str}\n\nModel Description:\n{desc_str}"
|
| 319 |
+
custom_tooltip_escaped = custom_tooltip.replace(
|
| 320 |
+
'"', """
|
| 321 |
+
).replace("'", "'")
|
| 322 |
custom_title_attr = f' title="{custom_tooltip_escaped}"'
|
| 323 |
|
| 324 |
display_val = "" if is_empty_value(val) else val
|
| 325 |
link_str = str(publication_link).strip().lower()
|
| 326 |
+
if (
|
| 327 |
+
publication_link
|
| 328 |
+
and link_str
|
| 329 |
+
and link_str not in ["none", "nan", "", "."]
|
| 330 |
+
):
|
| 331 |
# Put custom title on the link itself
|
| 332 |
html += f"<td class='{css_class}'><a href='{publication_link}' target='_blank' style='color: #20C2D9; text-decoration: none;'{custom_title_attr}>{display_val}</a></td>"
|
| 333 |
else:
|
|
|
|
| 337 |
elif col == ("", "# Parameters"):
|
| 338 |
formatted_val = format_parameter_count(val)
|
| 339 |
# Store raw numeric value in data-value for sorting
|
| 340 |
+
data_value_attr = (
|
| 341 |
+
f' data-value="{val}"'
|
| 342 |
+
if pd.notna(val) and val != ""
|
| 343 |
+
else ' data-value=""'
|
| 344 |
+
)
|
| 345 |
html += f"<td class='{css_class}'{data_value_attr}{title_attr}>{formatted_val}</td>"
|
| 346 |
|
| 347 |
else:
|
|
|
|
| 548 |
|
| 549 |
return html
|
| 550 |
|
|
|
|
|
|
|
| 551 |
# Header section
|
| 552 |
print(Leaderboard.__module__)
|
| 553 |
header_html = gr.HTML(LeaderboardContent.get_header_html())
|
| 554 |
|
| 555 |
# Load initial data
|
| 556 |
+
result_data = refresh_leaderboard() # df
|
| 557 |
|
| 558 |
# add rank column with medals for top 3
|
| 559 |
+
result_data[("", "Avg. AUC")] = pd.to_numeric(
|
| 560 |
+
result_data[("", "Avg. AUC")], errors="coerce"
|
| 561 |
+
)
|
| 562 |
+
result_data = result_data.sort_values(
|
| 563 |
+
by=("", "Avg. AUC"), ascending=False, na_position="last"
|
| 564 |
+
)
|
| 565 |
ranks = []
|
| 566 |
for i in range(1, len(result_data) + 1):
|
| 567 |
if i == 1:
|
|
|
|
| 583 |
elem_id="leaderboard-search",
|
| 584 |
container=False,
|
| 585 |
max_lines=1,
|
| 586 |
+
type="text",
|
| 587 |
)
|
| 588 |
|
| 589 |
# Filters in an accordion
|
| 590 |
+
with gr.Accordion(
|
| 591 |
+
"Filters & Column Selection",
|
| 592 |
+
open=False,
|
| 593 |
+
elem_classes=["filter-accordion"],
|
| 594 |
+
):
|
| 595 |
with gr.Row():
|
| 596 |
# Type filter (multi-select checkboxes)
|
| 597 |
type_filter = gr.CheckboxGroup(
|
| 598 |
+
choices=[
|
| 599 |
+
"0️⃣ Zero-shot",
|
| 600 |
+
"1️⃣ Few-shot",
|
| 601 |
+
"⤵️ Pre-trained",
|
| 602 |
+
"🔼 Models trained from scratch",
|
| 603 |
+
],
|
| 604 |
label="Model Type",
|
| 605 |
+
value=[
|
| 606 |
+
"0️⃣ Zero-shot",
|
| 607 |
+
"1️⃣ Few-shot",
|
| 608 |
+
"⤵️ Pre-trained",
|
| 609 |
+
"🔼 Models trained from scratch",
|
| 610 |
+
], # All selected by default
|
| 611 |
+
interactive=True,
|
| 612 |
)
|
| 613 |
|
| 614 |
# Min AUC filter
|
|
|
|
| 617 |
value=0,
|
| 618 |
minimum=0,
|
| 619 |
maximum=1,
|
| 620 |
+
step=0.01,
|
| 621 |
)
|
| 622 |
|
| 623 |
# Column selection dropdown
|
| 624 |
# Get all column names for the dropdown
|
| 625 |
+
all_columns = [
|
| 626 |
+
col
|
| 627 |
+
for col in result_data.columns
|
| 628 |
+
if col
|
| 629 |
+
not in [
|
| 630 |
+
("", "HF_Space_Tag"),
|
| 631 |
+
("", "Publication Link"),
|
| 632 |
+
("", "Model Description"),
|
| 633 |
+
]
|
| 634 |
+
]
|
| 635 |
default_columns = get_default_columns(result_data)
|
| 636 |
|
| 637 |
# Format column names for display
|
|
|
|
| 648 |
# Create mapping from display name to actual column
|
| 649 |
column_display_to_actual = dict(zip(column_choices, column_values))
|
| 650 |
default_display_names = [
|
| 651 |
+
display_name
|
| 652 |
+
for display_name, col in column_display_to_actual.items()
|
| 653 |
if col in default_columns
|
| 654 |
]
|
| 655 |
|
|
|
|
| 657 |
choices=column_choices,
|
| 658 |
value=default_display_names,
|
| 659 |
label="Select Columns to Display",
|
| 660 |
+
interactive=True,
|
| 661 |
)
|
| 662 |
|
| 663 |
# Refresh button
|
|
|
|
| 673 |
table = gr.HTML(make_html_table(result_data))
|
| 674 |
|
| 675 |
# Wire up the filter components
|
| 676 |
+
def apply_filters_wrapper(
|
| 677 |
+
search, type_filter, min_auc, selected_display_names
|
| 678 |
+
):
|
| 679 |
# Convert display names back to actual column tuples
|
| 680 |
+
selected_columns = [
|
| 681 |
+
column_display_to_actual[name]
|
| 682 |
+
for name in selected_display_names
|
| 683 |
+
]
|
| 684 |
return apply_filters(search, type_filter, min_auc, selected_columns)
|
| 685 |
|
| 686 |
# Connect all inputs to apply_filters
|
|
|
|
| 688 |
component.change(
|
| 689 |
fn=apply_filters_wrapper,
|
| 690 |
inputs=[search, type_filter, min_auc, column_selector],
|
| 691 |
+
outputs=table,
|
| 692 |
)
|
| 693 |
|
| 694 |
+
refresh_btn.click(
|
| 695 |
+
apply_filters_wrapper,
|
| 696 |
+
[search, type_filter, min_auc, column_selector],
|
| 697 |
+
table,
|
| 698 |
+
)
|
| 699 |
|
| 700 |
# Connect refresh button
|
| 701 |
def refresh_data():
|
|
|
|
| 708 |
return new_data
|
| 709 |
|
| 710 |
# Info section
|
| 711 |
+
info_html = gr.HTML(
|
| 712 |
+
LeaderboardContent.get_info_html(),
|
| 713 |
+
elem_classes=["info-leaderboard"],
|
| 714 |
+
)
|
| 715 |
|
| 716 |
return tab, table
|
| 717 |
|
|
|
|
| 732 |
|
| 733 |
with gr.TabItem("Submit", elem_id="submission-tab", id=2) as tab:
|
| 734 |
with gr.Blocks(elem_classes=["form-wrapper"]):
|
| 735 |
+
gr.HTML(
|
| 736 |
+
f"""<div class="header-section">
|
| 737 |
<h2 class="header-emoji">{SubmissionContent.emoji}</h2>
|
| 738 |
<h2 class="header-title">{SubmissionContent.title}</h2>
|
| 739 |
+
</div>"""
|
| 740 |
+
)
|
| 741 |
|
| 742 |
# Instructions
|
| 743 |
+
instructions_html = gr.HTML(
|
| 744 |
+
SubmissionContent.get_instructions_html()
|
| 745 |
+
)
|
| 746 |
|
| 747 |
# Submission form
|
| 748 |
with gr.Blocks():
|
| 749 |
# Required fields
|
| 750 |
+
gr.HTML(
|
| 751 |
+
f"<div>{SubmissionContent.form_labels['model_name']}</div>",
|
| 752 |
+
container=False,
|
| 753 |
+
elem_classes=["field-label"],
|
| 754 |
+
)
|
| 755 |
model_name = gr.Textbox(
|
| 756 |
show_label=True,
|
| 757 |
+
placeholder=SubmissionContent.form_placeholders[
|
| 758 |
+
"model_name"
|
| 759 |
+
],
|
| 760 |
+
# info=SubmissionContent.form_info["model_name"],
|
| 761 |
container=False,
|
| 762 |
elem_classes=["form-container"],
|
| 763 |
max_lines=1,
|
| 764 |
)
|
| 765 |
|
| 766 |
+
gr.HTML(
|
| 767 |
+
f"<div>{SubmissionContent.form_labels['hf_space_tag']}</div>",
|
| 768 |
+
container=False,
|
| 769 |
+
elem_classes=["field-label"],
|
| 770 |
+
)
|
| 771 |
hf_space_tag = gr.Textbox(
|
| 772 |
label=SubmissionContent.form_labels["hf_space_tag"],
|
| 773 |
+
placeholder=SubmissionContent.form_placeholders[
|
| 774 |
+
"hf_space_tag"
|
| 775 |
+
],
|
| 776 |
+
# info=SubmissionContent.form_info["hf_space_tag"],
|
| 777 |
container=False,
|
| 778 |
max_lines=1,
|
| 779 |
+
elem_classes=["form-container"],
|
| 780 |
)
|
| 781 |
|
| 782 |
+
gr.HTML(
|
| 783 |
+
f"<div>{SubmissionContent.form_labels['model_description']}</div>",
|
| 784 |
+
container=False,
|
| 785 |
+
elem_classes=["field-label"],
|
| 786 |
+
)
|
| 787 |
model_description = gr.Textbox(
|
| 788 |
label=SubmissionContent.form_labels["model_description"],
|
| 789 |
placeholder=SubmissionContent.form_placeholders[
|
| 790 |
"model_description"
|
| 791 |
],
|
| 792 |
+
# info=SubmissionContent.form_info["model_description"],
|
| 793 |
lines=3,
|
| 794 |
container=False,
|
| 795 |
+
elem_classes=["form-container"],
|
| 796 |
)
|
| 797 |
|
| 798 |
# Optional fields in accordion
|
| 799 |
# with gr.Accordion("Additional Information", open=False):
|
| 800 |
+
gr.HTML(
|
| 801 |
+
f"<div>{SubmissionContent.form_labels['organization']}</div>",
|
| 802 |
+
container=False,
|
| 803 |
+
elem_classes=["field-label"],
|
| 804 |
+
)
|
| 805 |
organization = gr.Textbox(
|
| 806 |
label=SubmissionContent.form_labels["organization"],
|
| 807 |
placeholder=SubmissionContent.form_placeholders[
|
|
|
|
| 812 |
max_lines=1,
|
| 813 |
)
|
| 814 |
|
| 815 |
+
gr.HTML(
|
| 816 |
+
f"<div>{SubmissionContent.form_labels['model_size']}</div>",
|
| 817 |
+
container=False,
|
| 818 |
+
elem_classes=["field-label"],
|
| 819 |
+
)
|
| 820 |
model_size = gr.Textbox(
|
| 821 |
+
label=SubmissionContent.form_labels["model_size"],
|
| 822 |
+
placeholder=SubmissionContent.form_placeholders[
|
| 823 |
+
"model_size"
|
| 824 |
+
],
|
| 825 |
+
container=False,
|
| 826 |
+
max_lines=1,
|
| 827 |
+
elem_classes=["form-container"],
|
| 828 |
+
)
|
| 829 |
|
| 830 |
+
gr.HTML(
|
| 831 |
+
f"<div>{SubmissionContent.form_labels['pretrained']}</div>",
|
| 832 |
+
container=False,
|
| 833 |
+
elem_classes=["field-label"],
|
| 834 |
+
)
|
| 835 |
pretrained = gr.Radio(
|
| 836 |
choices=["Yes", "No"],
|
| 837 |
value="No",
|
| 838 |
container=False,
|
| 839 |
+
elem_classes=["form-container-radio"],
|
| 840 |
)
|
| 841 |
|
| 842 |
+
pretraining_label = gr.HTML(
|
| 843 |
+
f"<div>{SubmissionContent.form_labels['pretraining_data']}</div>",
|
| 844 |
+
container=False,
|
| 845 |
+
elem_classes=["field-label"],
|
| 846 |
+
visible=False,
|
| 847 |
+
)
|
| 848 |
pretraining_data = gr.Textbox(
|
| 849 |
label=SubmissionContent.form_labels["pretraining_data"],
|
| 850 |
placeholder=SubmissionContent.form_placeholders[
|
|
|
|
| 853 |
visible=False,
|
| 854 |
container=False,
|
| 855 |
max_lines=1,
|
| 856 |
+
elem_classes=["form-container"],
|
| 857 |
)
|
| 858 |
|
| 859 |
# When checkbox changes, update visibility
|
| 860 |
def toggle_pretrain_fields(choice):
|
| 861 |
+
show = choice == "Yes"
|
| 862 |
+
return [gr.update(visible=show), gr.update(visible=show)]
|
|
|
|
|
|
|
|
|
|
| 863 |
|
| 864 |
pretrained.change(
|
| 865 |
fn=toggle_pretrain_fields,
|
|
|
|
| 867 |
outputs=[pretraining_label, pretraining_data],
|
| 868 |
)
|
| 869 |
|
| 870 |
+
# pretrained = gr.Textbox(
|
| 871 |
+
# label=SubmissionContent.form_labels["pretrained"],
|
| 872 |
+
# placeholder=SubmissionContent.form_placeholders[
|
| 873 |
+
# "pretrained"
|
| 874 |
+
# ],
|
| 875 |
+
# )
|
| 876 |
|
| 877 |
+
gr.HTML(
|
| 878 |
+
f"<div>{SubmissionContent.form_labels['publication_title']}</div>",
|
| 879 |
+
container=False,
|
| 880 |
+
elem_classes=["field-label"],
|
| 881 |
+
)
|
| 882 |
publication_title = gr.Textbox(
|
| 883 |
label=SubmissionContent.form_labels["publication_title"],
|
| 884 |
placeholder=SubmissionContent.form_placeholders[
|
|
|
|
| 886 |
],
|
| 887 |
container=False,
|
| 888 |
max_lines=1,
|
| 889 |
+
elem_classes=["form-container"],
|
| 890 |
)
|
| 891 |
|
| 892 |
+
gr.HTML(
|
| 893 |
+
f"<div>{SubmissionContent.form_labels['publication_link']}</div>",
|
| 894 |
+
container=False,
|
| 895 |
+
elem_classes=["field-label"],
|
| 896 |
+
)
|
| 897 |
publication_link = gr.Textbox(
|
| 898 |
label=SubmissionContent.form_labels["publication_link"],
|
| 899 |
placeholder=SubmissionContent.form_placeholders[
|
|
|
|
| 901 |
],
|
| 902 |
max_lines=1,
|
| 903 |
container=False,
|
| 904 |
+
elem_classes=["form-container"],
|
| 905 |
)
|
| 906 |
|
| 907 |
+
gr.HTML(
|
| 908 |
+
f"<div>{SubmissionContent.form_labels['zero_shot']}</div>",
|
| 909 |
+
container=False,
|
| 910 |
+
elem_classes=["field-label"],
|
| 911 |
+
)
|
| 912 |
zero_shot = gr.Radio(
|
| 913 |
+
choices=["Yes", "No"],
|
| 914 |
+
value="No",
|
| 915 |
+
container=False,
|
| 916 |
+
elem_classes=["form-container-radio"],
|
| 917 |
+
)
|
| 918 |
+
|
| 919 |
+
gr.HTML(
|
| 920 |
+
f"<div>{SubmissionContent.form_labels['few_shot']}</div>",
|
| 921 |
+
container=False,
|
| 922 |
+
elem_classes=["field-label"],
|
| 923 |
+
)
|
| 924 |
few_shot = gr.Radio(
|
| 925 |
choices=["Yes", "No"],
|
| 926 |
value="No",
|
| 927 |
container=False,
|
| 928 |
+
elem_classes=["form-container-radio"],
|
| 929 |
)
|
| 930 |
|
| 931 |
+
n_shot_label = gr.HTML(
|
| 932 |
+
f"<div>{SubmissionContent.form_labels['n_shot']}</div>",
|
| 933 |
+
container=False,
|
| 934 |
+
elem_classes=["field-label"],
|
| 935 |
+
visible=False,
|
| 936 |
+
)
|
| 937 |
n_shot = gr.Textbox(
|
| 938 |
label=SubmissionContent.form_labels["n_shot"],
|
| 939 |
+
placeholder=SubmissionContent.form_placeholders["n_shot"],
|
|
|
|
|
|
|
| 940 |
visible=False,
|
| 941 |
container=False,
|
| 942 |
max_lines=1,
|
| 943 |
+
elem_classes=["form-container"],
|
| 944 |
)
|
| 945 |
|
|
|
|
| 946 |
def toggle_n_shot_fields(choice):
|
| 947 |
+
show = choice == "Yes"
|
| 948 |
+
return [gr.update(visible=show), gr.update(visible=show)]
|
|
|
|
|
|
|
|
|
|
| 949 |
|
| 950 |
few_shot.change(
|
| 951 |
fn=toggle_n_shot_fields,
|
|
|
|
| 953 |
outputs=[n_shot_label, n_shot],
|
| 954 |
)
|
| 955 |
|
| 956 |
+
agree = gr.Checkbox(
|
| 957 |
+
label="I confirm that the submission fulfills the requirements and that the results are reproducible.",
|
| 958 |
+
elem_id="agree-checkbox",
|
| 959 |
+
container=False,
|
| 960 |
+
elem_classes=["form-container-checkbox"],
|
| 961 |
+
)
|
| 962 |
|
| 963 |
# Submit button and result
|
| 964 |
+
submit_btn = gr.Button(
|
| 965 |
+
"Submit",
|
| 966 |
+
value="primary",
|
| 967 |
+
interactive=False,
|
| 968 |
+
elem_classes=["submit-button"],
|
| 969 |
+
)
|
| 970 |
+
agree.change(
|
| 971 |
+
lambda x: gr.update(interactive=x),
|
| 972 |
+
inputs=agree,
|
| 973 |
+
outputs=submit_btn,
|
| 974 |
+
)
|
| 975 |
result_msg = gr.HTML()
|
| 976 |
|
| 977 |
if submit_callback:
|
|
|
|
| 1099 |
radio_circle="#20C2D9",
|
| 1100 |
)
|
| 1101 |
|
| 1102 |
+
with gr.Blocks(
|
| 1103 |
+
css=css, js=js, title="Tox21 Leaderboard", theme=theme
|
| 1104 |
+
) as app:
|
| 1105 |
# Tab container
|
| 1106 |
with gr.Tabs(elem_classes="tab-nav") as tabs:
|
| 1107 |
|