File size: 2,855 Bytes
697be1a
24a15c0
 
697be1a
24a15c0
697be1a
 
 
 
24a15c0
 
697be1a
 
 
24a15c0
697be1a
 
24a15c0
f008087
24a15c0
 
697be1a
 
7aa2aea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3b31368
7aa2aea
 
 
3b31368
7aa2aea
 
 
 
 
 
697be1a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24a15c0
 
7aa2aea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
697be1a
 
 
 
 
 
 
 
 
 
 
 
 
 
7aa2aea
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
import io

import pandas as pd
import requests
import streamlit as st

REPO_URL = "https://github.com/LudwigStumpp/llm-leaderboard"


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="πŸ†",
    )
    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():
    csv_table = grab_file_from_repo(REPO_URL, "leaderboard.csv")
    df = pd.read_csv(io.StringIO(csv_table), index_col=0)
    st.markdown("### Leaderboard")
    st.dataframe(filter_dataframe(df))


def setup_benchmarks():
    csv_table = grab_file_from_repo(REPO_URL, "benchmarks.csv")
    df = pd.read_csv(io.StringIO(csv_table), 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_footer():
    st.markdown(
        """
        ---
        Made with ❀️ by the awesome open-source community from all over 🌍.
        """
    )


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


if __name__ == "__main__":
    main()