Super fast , batteries included Leaderboard component β‘οΈ
tags:
The gradio_leaderboard
package helps you build fully functional and performant leaderboard demos with gradio
.
Place the gradio_leaderboard.Leaderboard
component anywhere in your Gradio application (and optionally pass in some configuration). That's it!
For example usage, please see the Usage section.
For details on configuration, please see the Configuration section.
For the API reference, see the Initialization section.
pip install gradio_leaderboard
or add gradio_leaderboard
to your requirements.txt
.
import gradio as gr
from gradio_leaderboard import Leaderboard
from pathlib import Path
import pandas as pd
abs_path = Path(__file__).parent
# Any pandas-compatible data
df = pd.read_json(str(abs_path / "leaderboard_data.json"))
with gr.Blocks() as demo:
gr.Markdown("""
# π₯ Leaderboard Component
""")
Leaderboard(
value=df,
select_columns=["T", "Model", "Average β¬οΈ", "ARC",
"HellaSwag", "MMLU", "TruthfulQA",
"Winogrande", "GSM8K"],
search_columns=["model_name_for_query", "Type"],
hide_columns=["model_name_for_query", "Model Size"],
filter_columns=["T", "Precision", "Model Size"],
)
if __name__ == "__main__":
demo.launch()
When column selection is enabled, a checkboxgroup will be displayed in the top left corner of the leaderboard that lets users select which columns are displayed.
You can disable/configure the column selection behavior of the Leaderboard
with the select_columns
parameter.
It's value can be:
None
: Column selection is not allowed and all of the columns are displayed when the leaderboard loads.list of column names
: All columns can be selected and the elements of this list correspond to the initial set of selected columns.SelectColumns instance
: You can import SelectColumns
from gradio_leaderboard
for full control of the column selection behavior as well as the checkboxgroup appearance. See an example below.import pandas as pd
import gradio as gr
from gradio_leaderboard import Leaderboard, SelectColumns
with gr.Blocks() as demo:
Leaderboard(
value=pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]}),
select_columns=SelectColumns(default_selection=["a", "b"],
cant_deselect="a",
label="Select The Columns",
info="Helpful information")
)
demo.launch()
When searching is enabled, a textbox will appear in the top left corner of the leaderboard. Users will be able to display rows that match their search query.
Searching follows the following rules:
;
.primary search column
by default.secondary search column
, the query must be preceded by the column name and a colon (:
), e.g. Name: Maria
.ANY
primary search column and ALL
secondary search columns.You can configure searching with the search_columns
parameter. It's value can be:
a list
: In which case the first element is the primary search column
and the remaining are the secondary search columns
.SearchColumns
instance. This lets you specify the primary and secondary columns explicitly as well as customize the search textbox appearance.import pandas as pd
import gradio as gr
from gradio_leaderboard import Leaderboard, SearchColumns
with gr.Blocks() as demo:
Leaderboard(
value=pd.DataFrame({"name": ["Freddy", "Maria", "Mark"], "country": ["USA", "Mexico", "USA"]}),
search_columns=SearchColumns(primary_column="name", secondary_columns="country",
placeholder="Search by name or country. To search by country, type 'country:<query>'",
label="Search"),
)
demo.launch()
You can let users filter out rows from the leaderboard with the filter_columns
parameter.
This will display a series of form elements that users can use to select/deselect which rows are displayed.
This parameter must be a list
but it's elements must be:
a string
: Corresponding to the column name you'd like to add a filter fora ColumnFilter
: A special class for full control of the filter's type, e.g. checkboxgroup
, checkbox
, slider
, or dropdown
, as well as it's appearance in the UI.If the type
of the ColumnFilter
is not specified, a heuristic will be used to choose the most appropriate type. If the data in the column is boolean-valued, a checkbox
will be used. If it is numeric, a slider will be used. For all others, a checkboxgroup
will be used.
import pandas as pd
import gradio as gr
from gradio_leaderboard import Leaderboard, ColumnFilter
with gr.Blocks() as demo:
Leaderboard(
value=pd.DataFrame({"name": ["Freddy", "Maria", "Mark"], "country": ["USA", "Mexico", "USA"],
"age": [25, 30, 35], "score": [100, 200, 300]}),
filter_columns=[
"name",
ColumnFilter("country", type="dropdown", label="Select Country πΊπΈπ²π½"),
ColumnFilter("age", type="slider", min=20, max=40, greater_than=True),
ColumnFilter("score", type="slider", min=50, max=350, greater_than=True)],
)
demo.launch()
Leaderboard
pd.DataFrame | None
str | list[str]
list[str] | SearchColumns
list[str] | SelectColumns
list[str | ColumnFilter] | None
list[str] | None
list[dict[str, str | bool]] | None
str | None
bool | None
float | None
int
int | None
int
bool | None
bool
str | None
list[str] | str | None
bool
bool
bool
list[str | int] | None