File size: 2,463 Bytes
5c68808
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322b7f1
5c68808
 
 
 
 
 
 
322b7f1
5c68808
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from lb_info import load_results, BUILD_L1_DF
from desc import (
    LEADERBOARD_INTRODUCTION,
    LEADERBOARD_MD,
    CITATION_BUTTON_TEXT,
    CITATION_BUTTON_LABEL,
    CINEPILE_ABOUT_MD,
)
from urllib.request import urlopen


def filter_df(fields):
    # Use set operations to avoid duplicates
    headers = (
        [
            "Model",
            "Params (B)",
            "Average Accuracy",
        ]
        + fields
        + [
            "Average Rank",
        ]
    )

    # Remove duplicates in headers by keeping the earliest entry
    headers = list(dict.fromkeys(headers))
    return table[headers]


with gr.Blocks(theme=gr.themes.Soft()) as demo:
    struct = load_results()
    results = struct

    # Build leaderboard DataFrame for CinePile data
    table, check_box = BUILD_L1_DF(results)

    N_MODELS = len(table)
    UP_TS = "20th October 2024"  # Replace with actual timestamp

    gr.Markdown(LEADERBOARD_INTRODUCTION.format(N_MODELS, UP_TS))

    with gr.Tabs(elem_classes="tab-buttons") as tabs:
        # First Tab: CinePile Leaderboard
        with gr.TabItem("CinePile Leaderboard", elem_id="main"):
            gr.Markdown(LEADERBOARD_MD)

            # Checkbox for selecting question categories
            checkbox_group = gr.CheckboxGroup(
                choices=check_box["question_categories"],
                label="Question Categories",
                interactive=True,
            )

            # DataFrame component for displaying the leaderboard
            data_component = gr.DataFrame(
                value=table[check_box["essential"]],
                datatype=[check_box["type_map"][x] for x in check_box["essential"]],
                interactive=False,
                visible=True,
            )

            # Update the table when checkbox changes
            checkbox_group.change(
                fn=filter_df, inputs=checkbox_group, outputs=data_component
            )

        # Second Tab: About
        with gr.TabItem("About CinePile", elem_id="about"):
            gr.Markdown(urlopen(CINEPILE_ABOUT_MD).read().decode())

        # Add citation support under "About"
        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",
                )

demo.launch()