File size: 2,841 Bytes
5d1d0b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from apscheduler.schedulers.background import BackgroundScheduler
from leaderboard.content import (
    TITLE,
    BANNER,
    INTRO,
    INTRO2,
    CITATION_BUTTON_LABEL,
    CITATION_BUTTON_TEXT,
)
import gradio as gr
import pandas as pd
import json


df = pd.DataFrame()


def update_data():
    global df
    with open("leaderboard/leaderboard.json", "r") as f:
        data = json.load(f)
    df = create_dataframe(data)


def filter_columns(df, show_all):
    if show_all:
        return df
    else:
        mean_columns = [col for col in df.columns if "Mean" in col or col == "Model"]
        return df[mean_columns]


def create_dataframe(data):
    rows = []
    for model in data["models"]:
        name_with_link = f'<a href="{model["url"]}" target="_blank" style="color: blue; text-decoration: underline;">{model["name"]}</a>'
        row = {"Model": name_with_link}
        row.update(model["scores"])
        rows.append(row)

    df = pd.DataFrame(rows)

    for col in df.columns:
        if "Mean" in col:
            df[col] = df[col].apply(lambda x: f"<strong>{x}</strong>")

    return df


def update_display(show_all, df):
    filtered_df = filter_columns(df, show_all)
    legend_visibility = gr.update(visible=show_all)
    return filtered_df, legend_visibility

update_data()
demo = gr.Blocks()
with demo:
    gr.HTML(TITLE)
    gr.HTML(BANNER)
    gr.Markdown(INTRO, elem_classes="markdown-text")
    gr.Markdown(INTRO2, elem_classes="markdown-text")
    show_all_columns = gr.Checkbox(label="Show all datasets", value=True)
    data_display = gr.Dataframe(df, datatype="markdown")

    legend_accordion = gr.Accordion("Legend:", open=False, visible=True)
    with legend_accordion:
        gr.Markdown(
            """
        - Exist.: Existence
        - Count: Count
        - Posi.: Position
        - Col.: Color
        - Post.: Poster
        - Cel.: Celebrity
        - Sce.: Scene
        - Lan.: Landmark
        - Art.: Artwork
        - Com. R.: Commonsense Reasoning
        - Code: Code Reasoning
        - Num.: Numerical Calculation
        - Tran.: Text Translation
        - OCR: OCR
        """
        )

    with gr.Row():
        with gr.Accordion("📙 Citation", open=False):
            citation_button = gr.Textbox(
                value=CITATION_BUTTON_TEXT,
                label=CITATION_BUTTON_LABEL,
                elem_id="citation-button",
                lines=10,
                show_copy_button=True,
            )

    show_all_columns.change(
        update_display,
        inputs=[show_all_columns, gr.State(df)],
        outputs=[data_display, legend_accordion],
    )


scheduler = BackgroundScheduler()
scheduler.add_job(update_data, "cron", hour=0)  # Update data once a day at midnight
scheduler.start()

demo.queue(default_concurrency_limit=40).launch(share=True)