|
import re |
|
import streamlit as st |
|
import requests |
|
import pandas as pd |
|
from io import StringIO |
|
import plotly.graph_objs as go |
|
from huggingface_hub import HfApi |
|
from huggingface_hub.utils import RepositoryNotFoundError, RevisionNotFoundError |
|
|
|
from yall import create_yall |
|
|
|
|
|
|
|
def convert_markdown_table_to_dataframe(md_content): |
|
""" |
|
Converts markdown table to Pandas DataFrame, handling special characters and links, |
|
extracts Hugging Face URLs, and adds them to a new column. |
|
""" |
|
|
|
cleaned_content = re.sub(r'\|\s*$', '', re.sub(r'^\|\s*', '', md_content, flags=re.MULTILINE), flags=re.MULTILINE) |
|
|
|
|
|
df = pd.read_csv(StringIO(cleaned_content), sep="\|", engine='python') |
|
|
|
|
|
df = df.drop(0, axis=0) |
|
|
|
|
|
df.columns = df.columns.str.strip() |
|
|
|
|
|
model_link_pattern = r'\[(.*?)\]\((.*?)\)\s*\[.*?\]\(.*?\)' |
|
df['URL'] = df['Model'].apply(lambda x: re.search(model_link_pattern, x).group(2) if re.search(model_link_pattern, x) else None) |
|
|
|
|
|
df['Model'] = df['Model'].apply(lambda x: re.sub(model_link_pattern, r'\1', x)) |
|
|
|
return df |
|
|
|
@st.cache_data |
|
def get_model_info(df): |
|
api = HfApi() |
|
|
|
|
|
df['Likes'] = None |
|
df['Tags'] = None |
|
|
|
|
|
for index, row in df.iterrows(): |
|
model = row['Model'].strip() |
|
try: |
|
model_info = api.model_info(repo_id=str(model)) |
|
df.loc[index, 'Likes'] = model_info.likes |
|
df.loc[index, 'Tags'] = ', '.join(model_info.tags) |
|
|
|
except (RepositoryNotFoundError, RevisionNotFoundError): |
|
df.loc[index, 'Likes'] = -1 |
|
df.loc[index, 'Tags'] = '' |
|
|
|
return df |
|
|
|
|
|
|
|
def create_bar_chart(df, category): |
|
"""Create and display a bar chart for a given category.""" |
|
st.write(f"### {category} Scores") |
|
|
|
|
|
sorted_df = df[['Model', category]].sort_values(by=category, ascending=True) |
|
|
|
|
|
fig = go.Figure(go.Bar( |
|
x=sorted_df[category], |
|
y=sorted_df['Model'], |
|
orientation='h', |
|
marker=dict(color=sorted_df[category], colorscale='Twilight') |
|
)) |
|
|
|
|
|
fig.update_layout( |
|
margin=dict(l=20, r=20, t=20, b=20) |
|
) |
|
|
|
|
|
st.plotly_chart(fig, use_container_width=True, height=len(df) * 35) |
|
|
|
|
|
|
|
|
|
|
|
def main(): |
|
st.set_page_config(page_title="YALL - Yet Another LLM Leaderboard", layout="wide") |
|
|
|
st.title("π YALL - Yet Another LLM Leaderboard") |
|
st.markdown("Leaderboard made with π§ [LLM AutoEval](https: |
|
content = create_yall() |
|
tab1, tab2 = st.tabs(["π Leaderboard", "π About"]) |
|
|
|
# Leaderboard tab |
|
with tab1: |
|
if content: |
|
try: |
|
score_columns = ['Average', 'AGIEval', 'GPT4All', 'TruthfulQA', 'Bigbench'] |
|
|
|
# Display dataframe |
|
full_df = convert_markdown_table_to_dataframe(content) |
|
for col in score_columns: |
|
# Corrected use of pd.to_numeric |
|
full_df[col] = pd.to_numeric(full_df[col].str.strip(), errors='coerce') |
|
full_df = get_model_info(full_df) |
|
full_df['Tags'] = full_df['Tags'].fillna('') |
|
df = pd.DataFrame(columns=full_df.columns) |
|
|
|
# Toggles for filtering by tags |
|
show_phi = st.checkbox("Phi (2.8B)", value=True) |
|
show_mistral = st.checkbox("Mistral (7B)", value=True) |
|
show_other = st.checkbox("Other", value=True) |
|
|
|
# Create a DataFrame based on selected filters |
|
dfs_to_concat = [] |
|
|
|
if show_phi: |
|
dfs_to_concat.append(full_df[full_df['Tags'].str.lower().str.contains('phi,|phi-msft,')]) |
|
if show_mistral: |
|
dfs_to_concat.append(full_df[full_df['Tags'].str.lower().str.contains('mistral,')]) |
|
if show_other: |
|
other_df = full_df[~full_df['Tags'].str.lower().str.contains('phi,|phi-msft,|mistral,')] |
|
dfs_to_concat.append(other_df) |
|
|
|
# Concatenate the DataFrames |
|
if dfs_to_concat: |
|
df = pd.concat(dfs_to_concat, ignore_index=True) |
|
|
|
# Add a search bar |
|
search_query = st.text_input("Search models", "") |
|
|
|
# Filter the DataFrame based on the search query |
|
if search_query: |
|
df = df[df['Model'].str.contains(search_query, case=False)] |
|
|
|
# Display the filtered DataFrame or the entire leaderboard |
|
st.dataframe( |
|
df[['Model'] + score_columns + ['Likes', 'URL']], |
|
use_container_width=True, |
|
column_config={ |
|
"Likes": st.column_config.NumberColumn( |
|
"Likes", |
|
help="Number of likes on Hugging Face", |
|
format="%d β€οΈ", |
|
), |
|
"URL": st.column_config.LinkColumn("URL"), |
|
}, |
|
hide_index=True, |
|
height=len(df) * 37, |
|
) |
|
|
|
# Add a button to export data to CSV |
|
if st.button("Export to CSV"): |
|
# Export the DataFrame to CSV |
|
csv_data = df.to_csv(index=False) |
|
|
|
# Create a link to download the CSV file |
|
st.download_button( |
|
label="Download CSV", |
|
data=csv_data, |
|
file_name="leaderboard.csv", |
|
key="download-csv", |
|
help="Click to download the CSV file", |
|
) |
|
|
|
# Full-width plot for the first category |
|
create_bar_chart(df, score_columns[0]) |
|
|
|
# Next two plots in two columns |
|
col1, col2 = st.columns(2) |
|
with col1: |
|
create_bar_chart(df, score_columns[1]) |
|
with col2: |
|
create_bar_chart(df, score_columns[2]) |
|
|
|
# Last two plots in two columns |
|
col3, col4 = st.columns(2) |
|
with col3: |
|
create_bar_chart(df, score_columns[3]) |
|
with col4: |
|
create_bar_chart(df, score_columns[4]) |
|
|
|
|
|
except Exception as e: |
|
st.error("An error occurred while processing the markdown table.") |
|
st.error(str(e)) |
|
else: |
|
st.error("Failed to download the content from the URL provided.") |
|
|
|
# About tab |
|
with tab2: |
|
st.markdown(''' |
|
### Nous benchmark suite |
|
|
|
Popularized by [Teknium](https: |
|
* [**AGIEval**](https: * **GPT4ALL** (0-shot): `hellaswag,openbookqa,winogrande,arc_easy,arc_challenge,boolq,piqa` |
|
* [**TruthfulQA**](https: * [**Bigbench**](https: |
|
### Reproducibility |
|
|
|
You can easily reproduce these results using π§ [LLM AutoEval](https: |
|
### Clone this space |
|
|
|
You can create your own leaderboard with your LLM AutoEval results on GitHub Gist. You just need to clone this space and specify two variables: |
|
|
|
* Change the `gist_id` in [yall.py](https: * Create "New Secret" in Settings > Variables and secrets (name: "github", value: [your GitHub token](https: |
|
A special thanks to [gblazex](https: ''') |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|