"""A gradio app that renders a static leaderboard. This is used for Hugging Face Space.""" import ast import argparse import glob import pickle import gradio as gr import numpy as np import pandas as pd import plotly.graph_objects as go import pandas as pd def make_default_md(): leaderboard_md = f""" # 🏆 CZ-EVAL Leaderboard [Developer](https://me.hynky.name/) | [Twitter](https://twitter.com/HKydlicek) CZ-EVAL is a evaluation leadboard of Tasks in Czech for LLMs. It's evaluated on following datasets: - Math Problems Understanding [Klokan-QA](https://huggingface.co/datasets/hynky/klokan-qa) - Reasoning and General Knowledge [TSP-QA](https://huggingface.co/datasets/hynky/tsp-qa) 💻 Code: The evaluation code can be found at [hynky1999/LLM-Eval](https://github.com/hynky1999/LLM-Eval). Model inference is done using [Open-Router](https://openrouter.ai/) or on cloud using [Modal Labs](https://modal.com/). """ return leaderboard_md def make_arena_leaderboard_md(arena_df): total_models = len(arena_df) leaderboard_md = f""" Total #models: **{total_models}**. Last updated: Feb 15, 2024. """ return leaderboard_md def make_full_leaderboard_md(elo_results): leaderboard_md = f""" Three benchmarks are displayed: **Arena Elo**, **MT-Bench** and **MMLU**. - [Klokan-QA](https://huggingface.co/datasets/hynky/klokan-qa) - Mathematical competitions dataset - [TSP](https://huggingface.co/datasets/hynky/TSP) - Comprehensive dataset of """ return leaderboard_md # Combine all category accuracies into a single DataFrame def plot_spider(df, title): categories = df.columns.tolist()[1:] categories = [ *categories, categories[0], ] # Ensure the graph is circular by appending the start to the end colors = [ "#1f77b4", # muted blue "#ff7f0e", # safety orange "#2ca02c", # cooked asparagus green "#d62728", # brick red "#9467bd", # muted purple "#8c564b", # chestnut brown "#e377c2", # raspberry yogurt pink "#7f7f7f", # middle gray "#bcbd22", # curry yellow-green "#17becf", # blue-teal ] # Setting for 1000x1000 fig_1000 = go.Figure() for i, (idx, row) in enumerate(df.iterrows()): name = row[0] row = row.tolist()[1:] row = row + [ row[0] ] # Ensure the graph is circular by appending the start to the end color = colors[i] fig_1000.add_trace( go.Scatterpolar( r=row, theta=categories, opacity=0.4, name=name, line=dict( color=color, width=4 ), # Adjust line width for better visibility ) ) fig_1000.update_layout( width=600, height=628, polar=dict( angularaxis=dict( gridwidth=2, # Increase line width for better visibility rotation=90, direction="clockwise", ), radialaxis=dict( visible=True, range=[0, 100], angle=45, tickangle=45, tickvals=[0, 25, 50, 75, 100], ticktext=["0%", "25%", "50%", "75%", "100%"], ), ), title_text=title, title_x=0.5, title_y=0.97, title_xanchor="center", title_yanchor="top", title_font_size=24, title_font_color="#333333", font=dict(family="Arial", size=16, color="#333333"), legend=dict( orientation="h", yanchor="bottom", y=-0.45, xanchor="center", x=0.5 ), ) return fig_1000 def openrouter_hyperlink(model_name): return f'{model_name}' def get_full_table(model_table_df): num_cols = ["klokan", "culture", "analytical", "critical", "verbal"] # Multiply by 100 and round to 2 decimals # Add average model_table_df["average"] = model_table_df[num_cols].mean(axis=1) model_table_df[num_cols + ["average"]] = model_table_df[ num_cols + ["average"] ].apply(lambda x: round(x * 100, 2)) # Sort and add rank model_table_df.sort_values(by="average", ascending=False, inplace=True) model_table_df.insert(0, "rank", np.arange(1, len(model_table_df) + 1)) # Add link model_table_df["model_name"] = model_table_df["model_name"].apply( lambda x: openrouter_hyperlink(x) ) model_table_df.rename( columns={ "model_name": "🤖 Model", "klokan": "🧮 Klokan-QA", "culture": "🌍 TSP-Culture", "analytical": "🔍 TSP-Analytical", "critical": "💡 TSP-Critical", "verbal": "📖 TSP-Verbal", "average": "📊 Average", }, inplace=True, ) return model_table_df def build_leaderboard_tab(leaderboard_table_file, klokan_table_file, tsp_table_file): results = pd.read_csv(leaderboard_table_file) results = get_full_table(results) # p1, p2 = get_grafs(pd.read_json(klokan_table_file), pd.read_json(tsp_table_file)) default_md = make_default_md() md_1 = gr.Markdown(default_md, elem_id="leaderboard_markdown") with gr.Tabs() as tabs: # arena table with gr.Tab("CZ-EVAL Leaderboard", id=0): md = make_arena_leaderboard_md(results) gr.Markdown(md, elem_id="leaderboard_markdown") gr.Dataframe( datatype=[ "str", "markdown", "number", "number", "number", "number", "number", "number", "str", "str", "str", ], value=results, elem_id="arena_leaderboard_dataframe", height=700, column_widths=[ 50, 200, 120, 100, 100, 150, 150, 100, 150, 150, 150, ], wrap=True, ) p1 = plot_spider(pd.read_csv(klokan_table_file), "Klokan-QA - Acurracy") p2 = plot_spider(pd.read_csv(tsp_table_file), "TSP - Accuracy") gr.Markdown( f"""## More Statistics for CZ-EVAL\n Below are figures for more statistics. """, elem_id="leaderboard_markdown", ) with gr.Row(): with gr.Column(): gr.Markdown( "#### Figure 1: Performance of models on Klokan-QA per difficulty" ) plot_1 = gr.Plot(p1, show_label=False) with gr.Column(): gr.Markdown("#### Figure 2: Performance of models on TSP dataset") plot_2 = gr.Plot(p2, show_label=False) return [md_1, plot_1, plot_2] block_css = """ #notice_markdown { font-size: 104% } #notice_markdown th { display: none; } #notice_markdown td { padding-top: 6px; padding-bottom: 6px; } #leaderboard_markdown { font-size: 104% } #leaderboard_markdown td { padding-top: 6px; padding-bottom: 6px; } #leaderboard_dataframe td { line-height: 0.1em; } footer { display:none !important } .image-container { display: flex; align-items: center; padding: 1px; } .image-container img { margin: 0 30px; height: 20px; max-height: 100%; width: auto; max-width: 20%; } """ def build_demo(leadboard_table, klokan_table, tsp_table): text_size = gr.themes.sizes.text_lg with gr.Blocks( title="CZ-EVAL Leaderboard", theme=gr.themes.Base(text_size=text_size), css=block_css, ) as demo: leader_components = build_leaderboard_tab( leadboard_table, klokan_table, tsp_table ) return demo demo = build_demo( leadboard_table="./leaderboard/table.csv", klokan_table="./leaderboard/klokan.csv", tsp_table="./leaderboard/tsp.csv", ) if __name__ == "__main__": demo.launch()