File size: 4,043 Bytes
7262dff
 
 
75fec05
 
 
7262dff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75fec05
7262dff
75fec05
 
7262dff
 
 
 
 
 
75fec05
7262dff
 
 
 
 
 
75fec05
7262dff
 
 
 
 
 
 
75fec05
7262dff
 
 
 
75fec05
7262dff
 
 
 
 
 
75fec05
 
7262dff
 
 
 
 
 
 
 
 
 
 
 
 
75fec05
 
7262dff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
109
110
111
112
113
114
115
116
117
118
119
__all__ = ['block', 'make_clickable_model', 'make_clickable_user', 'get_submissions']
import os

import gradio as gr
import pandas as pd

from constants import *

global data_component, filter_component

def get_baseline_df():
    df = pd.read_csv(CSV_DIR)
    df['Average'] = ((df['Streaming_OS'] + df['Dialogue_OS']) / 2).round(2)
    df = df.sort_values(by="Average", ascending=False)
    present_columns = ['Model'] + checkbox_group.value
    df = df[present_columns]
    return df

def get_all_df():
    df = pd.read_csv(CSV_DIR)
    df['Average'] = ((df['Streaming_OS'] + df['Dialogue_OS']) / 2).round(2)
    df = df.sort_values(by="Average", ascending=False)
    return df

def on_filter_model_size_method_change(selected_columns):
    updated_data = get_all_df()

    # columns:
    selected_columns = [item for item in TASK_INFO if item in selected_columns]
    present_columns = ['Model'] + selected_columns
    updated_data = updated_data[present_columns]
    updated_data = updated_data.sort_values(by=selected_columns[0], ascending=False)
    updated_headers = present_columns
    update_datatype = [DATA_TITILE_TYPE[COLUMN_NAMES.index(x)] for x in updated_headers]
    filter_component = gr.components.Dataframe(
        value=updated_data, 
        headers=updated_headers,
        type="pandas", 
        datatype=update_datatype,
        interactive=False,
        visible=True,
    )

    return filter_component

def search_model(query):
    df = get_all_df()
    filtered_df = df[df['Model'].str.contains(query, case=False)]
    return filtered_df

block = gr.Blocks()

with block:
    gr.Markdown(
        LEADERBORAD_INTRODUCTION
    )
    with gr.Tabs(elem_classes="tab-buttons") as tabs:
        with gr.TabItem("πŸ“Š SVBench", elem_id="svbench-tab-table", id=1):
            with gr.Accordion("Citation", open=False):
                    citation_button = gr.Textbox(
                        value=CITATION_BUTTON_TEXT,
                        label=CITATION_BUTTON_LABEL,
                        elem_id="citation-button",
                        lines=10,
                    )
    
            gr.Markdown(
                TABLE_INTRODUCTION
            )

            # selection for column part:
            checkbox_group = gr.CheckboxGroup(
                choices=TASK_INFO,
                value=AVG_INFO,
                label="Evaluation Dimension",
                interactive=True,
            )

            search_box = gr.Textbox(
                label="Search Model",
                placeholder="Enter model name",
                interactive=True,
            )

            data_component = gr.components.Dataframe(
                value=get_baseline_df, 
                headers=['Model', 'Type', 'Size'] + AVG_INFO,
                type="pandas", 
                datatype=DATA_TITILE_TYPE,
                interactive=False,
                visible=True,
            )

            checkbox_group.change(fn=on_filter_model_size_method_change, inputs=[checkbox_group], outputs=data_component)
            search_box.change(fn=search_model, inputs=[search_box], outputs=data_component)

        # table 2
        with gr.TabItem("πŸ“ About", elem_id="svbench-tab-table", id=2):
            gr.Markdown(LEADERBORAD_INFO, elem_classes="markdown-text")
           
        # table 3    
        with gr.TabItem("πŸš€ Submit here! ", elem_id="-tab-table", id=3):
            gr.Markdown(SUBMIT_INTRODUCTION, elem_classes="markdown-text")



    def refresh_data():
        value1 = get_baseline_df()
        return value1

    with gr.Row():
        data_run = gr.Button("Refresh")
    with gr.Row():
        result_download = gr.Button("Download Leaderboard")
        file_download = gr.File(label="download the csv of leaderboard.", visible=False)
        data_run.click(on_filter_model_size_method_change, inputs=[checkbox_group], outputs=data_component)
        result_download.click(lambda: (CSV_DIR, gr.update(visible=True)), inputs=None, outputs=[file_download, file_download])

block.launch()