mlabonne commited on
Commit
b338d34
1 Parent(s): f17f4c6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +104 -0
app.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import streamlit as st
3
+ import requests
4
+ import pandas as pd
5
+ from io import StringIO
6
+ import plotly.graph_objs as go
7
+
8
+ from yall import create_yall
9
+
10
+
11
+ def convert_markdown_table_to_dataframe(md_content):
12
+ """
13
+ Converts markdown table to Pandas DataFrame, handling special characters and links,
14
+ extracts Hugging Face URLs, and adds them to a new column.
15
+ """
16
+ # Remove leading and trailing | characters
17
+ cleaned_content = re.sub(r'\|\s*$', '', re.sub(r'^\|\s*', '', md_content, flags=re.MULTILINE), flags=re.MULTILINE)
18
+
19
+ # Create DataFrame from cleaned content
20
+ df = pd.read_csv(StringIO(cleaned_content), sep="\|", engine='python')
21
+
22
+ # Remove the first row after the header
23
+ df = df.drop(0, axis=0)
24
+
25
+ # Strip whitespace from column names
26
+ df.columns = df.columns.str.strip()
27
+
28
+ # Extract Hugging Face URLs and add them to a new column
29
+ model_link_pattern = r'\[(.*?)\]\((.*?)\)\s*\[.*?\]\(.*?\)'
30
+ df['URL'] = df['Model'].apply(lambda x: re.search(model_link_pattern, x).group(2) if re.search(model_link_pattern, x) else None)
31
+
32
+ # Clean Model column to have only the model link text
33
+ df['Model'] = df['Model'].apply(lambda x: re.sub(model_link_pattern, r'\1', x))
34
+
35
+ return df
36
+
37
+
38
+ def create_bar_chart(df, category):
39
+ """Create and display a bar chart for a given category."""
40
+ st.write(f"### {category} Scores")
41
+
42
+ # Sort the DataFrame based on the category score
43
+ sorted_df = df[['Model', category]].sort_values(by=category, ascending=True)
44
+
45
+ # Create the bar chart with color gradient
46
+ fig = go.Figure(go.Bar(
47
+ x=sorted_df[category],
48
+ y=sorted_df['Model'],
49
+ orientation='h',
50
+ marker=dict(color=sorted_df[category], colorscale='Magma')
51
+ ))
52
+
53
+ # Update layout for better readability
54
+ fig.update_layout(
55
+ xaxis_title=category,
56
+ yaxis_title="Model",
57
+ margin=dict(l=20, r=20, t=20, b=20)
58
+ )
59
+
60
+ st.plotly_chart(fig, use_container_width=True)
61
+
62
+
63
+ def main():
64
+ st.set_page_config(page_title="YALL - Yet Another LLM Leaderboard", layout="wide")
65
+
66
+ st.title("🏆 YALL - Yet Another LLM Leaderboard")
67
+ st.markdown("Leaderboard made with [🧐 LLM AutoEval](https://github.com/mlabonne/llm-autoeval) using [Nous](https://huggingface.co/NousResearch) benchmark suite. It's a collection of my own evaluations.")
68
+
69
+ content = create_yall()
70
+ if content:
71
+ try:
72
+ score_columns = ['Average', 'AGIEval', 'GPT4All', 'TruthfulQA', 'Bigbench']
73
+
74
+ # Display dataframe
75
+ df = convert_markdown_table_to_dataframe(content)
76
+ for col in score_columns:
77
+ df[col] = pd.to_numeric(df[col].str.strip(), errors='coerce')
78
+ st.dataframe(df, use_container_width=True)
79
+
80
+ # Full-width plot for the first category
81
+ create_bar_chart(df, score_columns[0])
82
+
83
+ # Next two plots in two columns
84
+ col1, col2 = st.columns(2)
85
+ with col1:
86
+ create_bar_chart(df, score_columns[1])
87
+ with col2:
88
+ create_bar_chart(df, score_columns[2])
89
+
90
+ # Last two plots in two columns
91
+ col3, col4 = st.columns(2)
92
+ with col3:
93
+ create_bar_chart(df, score_columns[3])
94
+ with col4:
95
+ create_bar_chart(df, score_columns[4])
96
+
97
+ except Exception as e:
98
+ st.error("An error occurred while processing the markdown table.")
99
+ st.error(str(e))
100
+ else:
101
+ st.error("Failed to download the content from the URL provided.")
102
+
103
+ if __name__ == "__main__":
104
+ main()