Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 4,538 Bytes
6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc b85d9b0 6efebdc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
import gradio as gr
from fuzzywuzzy import fuzz
from utils import submit_gradio_module
def search_leaderboard(df, model_name, columns_to_show, threshold=95):
"""
Search the leaderboard for models matching the search term using fuzzy matching.
Args:
df: The dataframe containing all leaderboard data
model_name: The search term to find models
columns_to_show: List of columns to include in the result
threshold: Minimum similarity threshold (default: 95)
Returns:
Filtered dataframe with only matching models and selected columns
"""
if not model_name.strip():
return df.loc[:, columns_to_show]
search_name = model_name.lower() # compute once for efficiency
def calculate_similarity(row):
return fuzz.partial_ratio(search_name, row["Model"].lower())
filtered_df = df.copy()
filtered_df["similarity"] = filtered_df.apply(calculate_similarity, axis=1)
filtered_df = filtered_df[filtered_df["similarity"] >= threshold].sort_values(
"similarity", ascending=False
)
filtered_df = filtered_df.drop("similarity", axis=1).loc[:, columns_to_show]
return filtered_df
def update_columns_to_show(df, columns_to_show):
"""
Update the displayed columns in the dataframe.
Args:
df: The dataframe to update
columns_to_show: List of columns to include
Returns:
gradio.update object with the updated dataframe
"""
dummy_df = df.loc[:, [col for col in df.columns if col in columns_to_show]]
columns_widths = []
for col in dummy_df.columns:
if col == "Rank":
columns_widths.append(80)
elif col == "Model":
columns_widths.append(400)
else:
columns_widths.append(150)
return gr.update(value=dummy_df, column_widths=columns_widths)
def create_leaderboard_tab(
df,
initial_columns_to_show,
search_function,
update_function,
about_section,
task_type,
model_param_limit=2000,
):
"""
Create a complete leaderboard tab with search, column selection, and data display.
Args:
df: The dataframe containing the leaderboard data
initial_columns_to_show: Initial list of columns to display
search_function: Function to handle searching
update_function: Function to handle column updates
about_section: Markdown text for the About tab
task_type: Type of the task ("Retriever" or "Reranker")
Returns:
A gradio Tabs component with the complete leaderboard interface
"""
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("π 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=df.columns.tolist(),
value=initial_columns_to_show,
scale=4,
)
leaderboard = gr.Dataframe(
value=df.loc[:, initial_columns_to_show],
datatype="markdown",
wrap=True,
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, model_param_limit=model_param_limit)
with gr.Tab("βΉοΈ About"):
gr.Markdown(about_section)
return tabs
|