Spaces:
Running
Running
| import gradio as gr | |
| import pandas as pd | |
| from pathlib import Path | |
| from src.json_leaderboard import create_leaderboard_df, get_leaderboard_stats | |
| from src.about import ( | |
| CITATION_BUTTON_LABEL, | |
| CITATION_BUTTON_TEXT, | |
| INTRODUCTION_TEXT, | |
| LLM_BENCHMARKS_TEXT, | |
| LINKS_AND_INFO, | |
| TITLE, | |
| ) | |
| from src.display.css_html_js import custom_css | |
| def create_simple_leaderboard(): | |
| """Create a simple leaderboard from JSON data""" | |
| json_path = Path(__file__).parent / "leaderboard_data.json" | |
| df = create_leaderboard_df(str(json_path)) | |
| if df.empty: | |
| return gr.Dataframe(value=pd.DataFrame({"Error": ["No data available"]})) | |
| return gr.Dataframe( | |
| value=df, | |
| headers=list(df.columns), | |
| datatype=["html", "str", "html", "str", "str", "str", "str"], | |
| interactive=False, | |
| wrap=True | |
| ) | |
| def get_stats_display(): | |
| """Get formatted statistics for display""" | |
| json_path = Path(__file__).parent / "leaderboard_data.json" | |
| stats = get_leaderboard_stats(str(json_path)) | |
| if not stats: | |
| return "No statistics available" | |
| stats_text = f""" | |
| ### π Leaderboard Statistics | |
| - **Total Models**: {stats['total_models']} | |
| - **Best Score**: {stats['max_acc']:.1f} | |
| - **Lowest Score**: {stats['min_acc']:.1f} | |
| """ | |
| return stats_text | |
| # Create the Gradio interface | |
| demo = gr.Blocks(css=custom_css, title="MMLongBench-Doc Leaderboard") | |
| with demo: | |
| gr.HTML(TITLE) | |
| gr.HTML(LINKS_AND_INFO) | |
| gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text") | |
| with gr.Tabs(elem_classes="tab-buttons") as tabs: | |
| with gr.TabItem("π Leaderboard", elem_id="llm-benchmark-tab-table", id=0): | |
| # Statistics display | |
| stats_display = gr.Markdown(get_stats_display()) | |
| # Leaderboard table | |
| leaderboard_table = create_simple_leaderboard() | |
| with gr.Row(): | |
| with gr.Column(): | |
| gr.Markdown("## π Citation") | |
| gr.Markdown("If you use [MMLongBench-Doc](https://arxiv.org/abs/2407.01523) in your research, please cite our work:") | |
| citation_textbox = gr.Textbox( | |
| value=CITATION_BUTTON_TEXT, | |
| elem_id="citation-textbox", | |
| show_label=False, | |
| interactive=False, | |
| lines=8, | |
| show_copy_button=True | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |