Spaces:
Runtime error
Runtime error
| import json | |
| import gradio as gr | |
| import pandas as pd | |
| from pages.summarization_playground import custom_css | |
| with open("prompt/prompt.json", "r") as file: | |
| json_data = file.read() | |
| prompts = json.loads(json_data)# Sample data for the leaderboard | |
| winning_rate = [prompt['metric']['winning_number'] for prompt in prompts] | |
| winning_rate = [num / sum(winning_rate) for num in winning_rate] | |
| data = { | |
| 'Rank': [i+1 for i in range(len(prompts))], | |
| 'Methods': [prompt['id'] for prompt in prompts], | |
| 'Rouge Score': [prompt['metric']['Rouge'] for prompt in prompts], | |
| 'Winning Rate': winning_rate, | |
| 'Authors': [prompt['author'] for prompt in prompts] | |
| } | |
| df = pd.DataFrame(data) | |
| df = df.sort_values(by='Rouge Score', ascending=False) | |
| df.loc[0]['Authors'] = 'π '+df.loc[0]['Authors'] | |
| df.loc[1]['Authors'] = 'π₯ '+df.loc[1]['Authors'] | |
| df.loc[2]['Authors'] = 'π₯ '+df.loc[2]['Authors'] | |
| def update_leaderboard(sort_by): | |
| # In a real implementation, this would filter the data based on the category | |
| sorted_df = df.sort_values(by=sort_by, ascending=False) | |
| # Update ranks based on new sorting | |
| sorted_df['Rank'] = range(1, len(sorted_df) + 1) | |
| # Convert DataFrame to HTML with clickable headers for sorting | |
| html = sorted_df.to_html(index=False, escape=False) | |
| # Add sorting links to column headers | |
| for column in sorted_df.columns: | |
| html = html.replace(f'<th>{column}</th>', | |
| f'<th><a href="#" onclick="sortBy(\'{column}\'); return false;">{column}</a></th>') | |
| return html | |
| def create_leaderboard(): | |
| with gr.Blocks(css=custom_css) as demo: | |
| gr.Markdown("# π Summarization Arena Leaderboard") | |
| with gr.Row(): | |
| gr.Markdown("[Blog](placeholder) | [GitHub](placeholder) | [Paper](placeholder) | [Dataset](placeholder) | [Twitter](placeholder) | [Discord](placeholder)") | |
| gr.Markdown("Welcome to our open platform for evaluating LLM summarization capabilities. We use the DATASET_NAME_PLACEHOLDER dataset to generate summaries with MODEL_NAME_PLACEHOLDER. These summaries are then evaluated by STRONGER_MODEL_NAME_PLACEHOLDER using the METRIC1_PLACEHOLDER and METRIC2_PLACEHOLDER metrics") | |
| sort_by = gr.Dropdown(list(df.columns), label="Sort by", value="Rouge Score") | |
| gr.Markdown("**Performance**\n\n**methods**: 5, **questions**: 15") | |
| leaderboard = gr.HTML(update_leaderboard("Rouge Score"), elem_id="leaderboard") | |
| sort_by.change(update_leaderboard, inputs=[sort_by], outputs=[leaderboard]) | |
| return demo |