File size: 2,747 Bytes
5102800
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pandas as pd
from src.envs import EVAL_RESULTS_PATH
from src.populate import get_leaderboard_df
from src.display.utils import (
    AutoEvalColumn,
)

def update_table(
    hidden_df: pd.DataFrame,
    query: str,
):
    filtered_df = filter_queries(query, hidden_df)
    return filtered_df


def search_table(df: pd.DataFrame, query: str) -> pd.DataFrame:
    return df[(df[AutoEvalColumn.model.name].str.contains(query, case=False))]


def filter_queries(query: str, filtered_df: pd.DataFrame) -> pd.DataFrame:
    final_df = []
    if query != "":
        queries = [q.strip() for q in query.split(";")]
        for _q in queries:
            _q = _q.strip()
            if _q != "":
                temp_filtered_df = search_table(filtered_df, _q)
                if len(temp_filtered_df) > 0:
                    final_df.append(temp_filtered_df)
        if len(final_df) > 0:
            filtered_df = pd.concat(final_df)
            filtered_df = filtered_df.drop_duplicates(
                subset=[AutoEvalColumn.model.name, ]
            )

    return filtered_df



def show_result_page(root_path: str, title: str, index: int):
    raw_data, original_df = get_leaderboard_df(EVAL_RESULTS_PATH + f'/{root_path}')
    leaderboard_df = original_df.copy()
    number_of_field = list(leaderboard_df.keys())
    with gr.TabItem(title, elem_id="llm-benchmark-tab-table", id=index):
        with gr.Row():
            with gr.Column():
                with gr.Row():
                    search_bar = gr.Textbox(
                        placeholder=" 🔍 Search for your model (separate multiple queries with `;`) and press ENTER...",
                        show_label=False,
                        elem_id="search-bar",
                    )

        
        leaderboard_table = gr.components.Dataframe(
            value=leaderboard_df,
            headers=list(leaderboard_df.keys()),
            datatype=['markdown'],
            elem_id="leaderboard-table",
            column_widths=(['20%'] if len(number_of_field) > 6 else [str((1.5 / (len(number_of_field))) * 100) + '%']) * len(number_of_field),
            min_width=180,
            interactive=False,
            visible=True,
            wrap=True
        )
        

        # Dummy leaderboard for handling the case when the user uses backspace key
        hidden_leaderboard_table = gr.components.Dataframe(
            value=original_df,
            headers=list(original_df.keys()),
            interactive=False,
            visible=False,
        )

        search_bar.submit(
            update_table,
            [
                hidden_leaderboard_table,
                search_bar,
            ],
            leaderboard_table,
        )