w601sxs commited on
Commit
ad57016
·
1 Parent(s): d083ce0

adding app

Browse files
Files changed (1) hide show
  1. app.py +88 -0
app.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
9
+ def convert_markdown_table_to_dataframe(md_content):
10
+ """
11
+ Converts a markdown table to a Pandas DataFrame, handling special characters, links,
12
+ and extracting Hugging Face URLs.
13
+ """
14
+ cleaned_content = re.sub(r'\|\s*$', '', re.sub(r'^\|\s*', '', md_content, flags=re.MULTILINE), flags=re.MULTILINE)
15
+ df = pd.read_csv(StringIO(cleaned_content), sep="\|", engine='python')
16
+ df = df.drop(0, axis=0) # Remove first row if it's not the header
17
+ df.columns = df.columns.str.strip() # Clean column names
18
+
19
+ # Extract Model names and URLs
20
+ model_link_pattern = r'\[(.*?)\]\((.*?)\)'
21
+ df['URL'] = df['Model'].apply(lambda x: re.search(model_link_pattern, x).group(2) if re.search(model_link_pattern, x) else None)
22
+ df['Model'] = df['Model'].apply(lambda x: re.sub(model_link_pattern, r'\1', x))
23
+ return df
24
+
25
+
26
+ def create_bar_chart(df, metric):
27
+ """
28
+ Creates and displays a bar chart for a given metric.
29
+ """
30
+ st.write(f"### {metric} Scores")
31
+ if metric not in df.columns:
32
+ st.write(f"No data available for {metric}.")
33
+ return
34
+
35
+ sorted_df = df[['Model', metric]].dropna().sort_values(by=metric, ascending=True)
36
+ fig = go.Figure(go.Bar(
37
+ x=sorted_df[metric],
38
+ y=sorted_df['Model'],
39
+ orientation='h',
40
+ marker=dict(color=sorted_df[metric], colorscale='Inferno')
41
+ ))
42
+ fig.update_layout(margin=dict(l=20, r=20, t=20, b=20))
43
+ st.plotly_chart(fig, use_container_width=True)
44
+
45
+
46
+ def main():
47
+ st.set_page_config(page_title="LLM Leaderboard", layout="wide")
48
+ st.title("🏆 LLM Leaderboard")
49
+
50
+ # URL to your markdown file
51
+ md_url = st.text_input("Enter the URL to the markdown file", "https://raw.githubusercontent.com/yourrepo/README.md")
52
+
53
+ if not md_url:
54
+ st.error("Please provide a valid URL to a markdown file containing the leaderboard table.")
55
+ return
56
+
57
+ try:
58
+ response = requests.get(md_url)
59
+ response.raise_for_status()
60
+ md_content = response.text
61
+
62
+ df = convert_markdown_table_to_dataframe(md_content)
63
+
64
+ # Automatically detect metrics (all columns except 'Model' and 'URL')
65
+ metric_columns = [col for col in df.columns if col not in ['Model', 'URL']]
66
+
67
+ # Convert metric columns to numeric, handling errors gracefully
68
+ for col in metric_columns:
69
+ df[col] = pd.to_numeric(df[col], errors='coerce')
70
+
71
+ # Sortable leaderboard table
72
+ st.dataframe(
73
+ df[['Model'] + metric_columns + ['URL']],
74
+ use_container_width=True,
75
+ hide_index=True,
76
+ )
77
+
78
+ # Bar charts for each metric
79
+ for metric in metric_columns:
80
+ create_bar_chart(df, metric)
81
+
82
+ except Exception as e:
83
+ st.error(f"An error occurred while processing the markdown table: {e}")
84
+
85
+
86
+ if __name__ == "__main__":
87
+ main()
88
+