Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
| from pathlib import Path | |
| from utils import load_json_results | |
| import gradio as gr | |
| from leaderboard_tab import search_leaderboard, update_columns_to_show, create_leaderboard_tab | |
| # Constants | |
| LLM_IN_CONTEXT_ABOUT_SECTION = """""" | |
| # Global variables | |
| llm_in_context_df = None | |
| def load_reranking_leaderboard(): | |
| """Load and prepare the reranking leaderboard data""" | |
| global llm_in_context_df | |
| dataframe_path = Path(__file__).parent / "results" / "llm_in_context_results.json" | |
| # Prepare dataframe | |
| llm_in_context_df = load_json_results( | |
| dataframe_path, | |
| prepare_for_display=True, | |
| sort_col="Overall Score", | |
| drop_cols=["Revision", "Precision", "Task"] | |
| ) | |
| llm_in_context_df.insert(0, "Rank", range(1, 1 + len(llm_in_context_df))) | |
| llm_in_context_df.rename(columns={"nDCG": "nDCG@10", "MRR": "MRR@10"}, inplace=True) | |
| return llm_in_context_df | |
| def reranking_search_leaderboard(model_name, columns_to_show): | |
| """Search function for reranking leaderboard""" | |
| return search_leaderboard(llm_in_context_df, model_name, columns_to_show) | |
| def update_reranker_columns_to_show(columns_to_show): | |
| """Update displayed columns for reranking leaderboard""" | |
| return update_columns_to_show(llm_in_context_df, columns_to_show) | |
| def create_llm_in_context_tab(): | |
| """Create the complete reranking leaderboard tab""" | |
| global llm_in_context_df | |
| # Load data if not already loaded | |
| if (llm_in_context_df is None): | |
| llm_in_context_df = load_reranking_leaderboard() | |
| # Define default columns to show | |
| default_columns = ["Rank", "Model", "Overall Score", "Model Parameters (in Millions)", | |
| "Embedding Dimensions", "Downloads Last Month", "MRR@10", "nDCG@10", "MAP"] | |
| columns_widths = [80 if col == "Rank" else 400 if col == "Model" else 150 for col in initial_columns_to_show] | |
| with gr.Tabs() as tabs: | |
| with gr.Tab("๐ Context Dependant Leaderboard"): | |
| with gr.Column(): | |
| with gr.Row(equal_height=True): | |
| search_box = gr.Textbox( | |
| placeholder="Search for models...", | |
| label="Search (You can also press Enter to search)", | |
| scale=5 | |
| ) | |
| search_button = gr.Button( | |
| value="Search", | |
| variant="primary", | |
| scale=1 | |
| ) | |
| columns_to_show_input = gr.CheckboxGroup( | |
| label="Columns to Show", | |
| choices=llm_in_context_df.columns.tolist(), | |
| value=initial_columns_to_show, | |
| scale=4 | |
| ) | |
| leaderboard = gr.Dataframe( | |
| value=llm_in_context_df.loc[:, initial_columns_to_show], | |
| datatype="markdown", | |
| wrap=False, | |
| show_fullscreen_button=True, | |
| interactive=False, | |
| column_widths=columns_widths | |
| ) | |
| # Connect events | |
| search_box.submit( | |
| search_function, | |
| inputs=[search_box, columns_to_show_input], | |
| outputs=leaderboard | |
| ) | |
| columns_to_show_input.select( | |
| update_function, | |
| inputs=columns_to_show_input, | |
| outputs=leaderboard | |
| ) | |
| search_button.click( | |
| search_function, | |
| inputs=[search_box, columns_to_show_input], | |
| outputs=leaderboard | |
| ) | |
| with gr.Tab("๐ Context About Leaderboard"): | |
| with gr.Column(): | |
| with gr.Row(equal_height=True): | |
| search_box = gr.Textbox( | |
| placeholder="Search for models...", | |
| label="Search (You can also press Enter to search)", | |
| scale=5 | |
| ) | |
| search_button = gr.Button( | |
| value="Search", | |
| variant="primary", | |
| scale=1 | |
| ) | |
| columns_to_show_input = gr.CheckboxGroup( | |
| label="Columns to Show", | |
| choices=llm_in_context_df.columns.tolist(), | |
| value=initial_columns_to_show, | |
| scale=4 | |
| ) | |
| leaderboard = gr.Dataframe( | |
| value=llm_in_context_df.loc[:, initial_columns_to_show], | |
| datatype="markdown", | |
| wrap=False, | |
| show_fullscreen_button=True, | |
| interactive=False, | |
| column_widths=columns_widths | |
| ) | |
| # Connect events | |
| search_box.submit( | |
| search_function, | |
| inputs=[search_box, columns_to_show_input], | |
| outputs=leaderboard | |
| ) | |
| columns_to_show_input.select( | |
| update_function, | |
| inputs=columns_to_show_input, | |
| outputs=leaderboard | |
| ) | |
| search_button.click( | |
| search_function, | |
| inputs=[search_box, columns_to_show_input], | |
| outputs=leaderboard | |
| ) | |
| with gr.Tab("๐ต๏ธ Submit"): | |
| submit_gradio_module(task_type) | |
| with gr.Tab("โน๏ธ About"): | |
| gr.Markdown(about_section) | |
| return tabs | |