File size: 3,468 Bytes
24a15c0
697be1a
24a15c0
697be1a
 
48cd666
 
 
697be1a
 
24a15c0
 
697be1a
 
 
24a15c0
697be1a
 
24a15c0
f008087
24a15c0
 
697be1a
 
7aa2aea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3b31368
7aa2aea
 
 
3b31368
7aa2aea
 
 
 
 
 
697be1a
 
 
 
 
 
40eaa37
697be1a
 
 
 
 
 
 
 
 
 
 
 
48cd666
40eaa37
 
 
 
7aa2aea
 
 
 
 
48cd666
7aa2aea
 
 
 
 
 
 
 
 
 
40eaa37
7aa2aea
697be1a
 
3be1fea
48cd666
3be1fea
 
04eb23d
3be1fea
 
 
 
 
 
 
 
 
 
 
697be1a
 
 
 
 
 
 
 
 
 
 
 
7aa2aea
3be1fea
697be1a
 
 
 
 
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import pandas as pd
import requests
import streamlit as st

REPO_URL = "https://github.com/LudwigStumpp/llm-leaderboard"
LEADERBOARD_PATH = "data/leaderboard.csv"
BENCHMARKS_PATH = "data/benchmarks.csv"
SOURCES_PATH = "data/sources.csv"


def grab_file_from_repo(repo_url: str, filename: str) -> str:
    """Grabs a file from a GitHub repository.

    Args:
        repo_url (str): URL of the GitHub repository.
        filename (str): Name of the file to grab.

    Returns:
        str: Content of the file.
    """
    url = repo_url.replace("github.com", "raw.githubusercontent.com") + f"/main/{filename}"
    return requests.get(url).text


def filter_dataframe(df: pd.DataFrame) -> pd.DataFrame:
    """
    Adds a UI on top of a dataframe to let viewers filter columns

    Modified from https://blog.streamlit.io/auto-generate-a-dataframe-filtering-ui-in-streamlit-with-filter_dataframe/

    Args:
        df (pd.DataFrame): Original dataframe

    Returns:
        pd.DataFrame: Filtered dataframe
    """
    modify = st.checkbox("Add filters")

    if not modify:
        return df

    df = df.copy()

    modification_container = st.container()

    with modification_container:
        to_filter_index = st.multiselect("Filter by model:", df.index)
        if to_filter_index:
            df = pd.DataFrame(df.loc[to_filter_index])

        to_filter_columns = st.multiselect("Filter by benchmark:", df.columns)
        if to_filter_columns:
            df = pd.DataFrame(df[to_filter_columns])

    return df


def setup_basic():
    title = "LLM-Leaderboard"

    st.set_page_config(
        page_title=title,
        page_icon="πŸ†",
        layout="wide",
    )
    st.title(title)

    st.markdown(
        """
        A joint community effort to create one central leaderboard for LLMs.
        Visit [llm-leaderboard](https://github.com/LudwigStumpp/llm-leaderboard) to contribute.
        """
    )


def setup_table():
    df = pd.read_csv(LEADERBOARD_PATH, index_col=0)
    df = df.sort_index(ascending=True)
    df = df.replace(r"^\s*$", float("nan"), regex=True)
    df = df.astype(float, errors="ignore")

    st.markdown("### Leaderboard")
    st.dataframe(filter_dataframe(df))


def setup_benchmarks():
    df = pd.read_csv(BENCHMARKS_PATH, index_col=0)
    df = df.sort_index(ascending=True)

    st.markdown("### Covered Benchmarks")

    selected_benchmark = st.selectbox("Select a benchmark to learn more:", df.index.unique())
    df_selected = df.loc[selected_benchmark]
    text = [
        f"Name: {selected_benchmark} ",
    ]
    for key in df_selected.keys():
        text.append(f"{key}: {df_selected[key]} ")
    st.markdown("\n".join(text))


def setup_sources():
    df = pd.read_csv(SOURCES_PATH, index_col=0)
    df = df.sort_index(ascending=True)

    st.markdown("### Sources of Above Figures")

    selected_source = st.selectbox("Select a source to learn more:", df.index.unique())
    df_selected = df.loc[selected_source]
    text = [
        f"Author: {selected_source} ",
    ]
    for key in df_selected.keys():
        text.append(f"{key}: {df_selected[key]} ")
    st.markdown("\n".join(text))


def setup_footer():
    st.markdown(
        """
        ---
        Made with ❀️ by the awesome open-source community from all over 🌍.
        """
    )


def main():
    setup_basic()
    setup_table()
    setup_benchmarks()
    setup_sources()
    setup_footer()


if __name__ == "__main__":
    main()