MEDIC-Benchmark / app.py
tathagataraha's picture
[MODIFY] Metrics for medical summarization, aci bench and soap notes
c92b14d
raw
history blame
47.6 kB
import subprocess
import gradio as gr
import pandas as pd
from apscheduler.schedulers.background import BackgroundScheduler
from huggingface_hub import snapshot_download
from src.about import (
CITATION_BUTTON_LABEL,
CITATION_BUTTON_TEXT,
EVALUATION_QUEUE_TEXT,
INTRODUCTION_TEXT,
LLM_BENCHMARKS_TEXT_1,
CROSS_EVALUATION_METRICS,
# EVALUATION_EXAMPLE_IMG,
# LLM_BENCHMARKS_TEXT_2,
# ENTITY_DISTRIBUTION_IMG,
# LLM_BENCHMARKS_TEXT_3,
TITLE,
LOGO
)
from src.display.css_html_js import custom_css
# changes to be made here
from src.display.utils import (
DATASET_BENCHMARK_COLS,
OPEN_ENDED_BENCHMARK_COLS,
MED_SAFETY_BENCHMARK_COLS,
MEDICAL_SUMMARIZATION_BENCHMARK_COLS,
ACI_BENCHMARK_COLS,
SOAP_BENCHMARK_COLS,
DATASET_COLS,
OPEN_ENDED_COLS,
MED_SAFETY_COLS,
MEDICAL_SUMMARIZATION_COLS,
ACI_COLS,
SOAP_COLS,
EVAL_COLS,
EVAL_TYPES,
NUMERIC_INTERVALS,
TYPES,
AutoEvalColumn,
ModelType,
ModelArch,
PromptTemplateName,
Precision,
WeightType,
fields,
)
from src.envs import API, EVAL_REQUESTS_PATH, EVAL_RESULTS_PATH, QUEUE_REPO, REPO_ID, RESULTS_REPO, TOKEN
from src.populate import get_evaluation_queue_df, get_leaderboard_df
from src.submission.submit import add_new_eval, PLACEHOLDER_DATASET_WISE_NORMALIZATION_CONFIG
def restart_space():
API.restart_space(repo_id=REPO_ID)
try:
print(EVAL_REQUESTS_PATH)
snapshot_download(
repo_id=QUEUE_REPO, local_dir=EVAL_REQUESTS_PATH, repo_type="dataset", tqdm_class=None, etag_timeout=30, token=TOKEN
)
except Exception:
restart_space()
try:
print(EVAL_RESULTS_PATH)
snapshot_download(
repo_id=RESULTS_REPO, local_dir=EVAL_RESULTS_PATH, repo_type="dataset", tqdm_class=None, etag_timeout=30, token=TOKEN
)
except Exception:
restart_space()
# Span based results
# changes to be made here
_, harness_datasets_original_df = get_leaderboard_df(EVAL_RESULTS_PATH, EVAL_REQUESTS_PATH, DATASET_COLS, DATASET_BENCHMARK_COLS, "accuracy", "datasets")
harness_datasets_leaderboard_df = harness_datasets_original_df.copy()
_, open_ended_original_df = get_leaderboard_df(EVAL_RESULTS_PATH, EVAL_REQUESTS_PATH, OPEN_ENDED_COLS, OPEN_ENDED_BENCHMARK_COLS, "score", "open_ended")
open_ended_leaderboard_df = open_ended_original_df.copy()
_, med_safety_original_df = get_leaderboard_df(EVAL_RESULTS_PATH, EVAL_REQUESTS_PATH, MED_SAFETY_COLS, MED_SAFETY_BENCHMARK_COLS, "score", "med_safety")
med_safety_leaderboard_df = med_safety_original_df.copy()
_, medical_summarization_original_df = get_leaderboard_df(EVAL_RESULTS_PATH, EVAL_REQUESTS_PATH, MEDICAL_SUMMARIZATION_COLS, MEDICAL_SUMMARIZATION_BENCHMARK_COLS, "score", "medical_summarization")
medical_summarization_leaderboard_df = medical_summarization_original_df.copy()
_, aci_original_df = get_leaderboard_df(EVAL_RESULTS_PATH, EVAL_REQUESTS_PATH, ACI_COLS, ACI_BENCHMARK_COLS, "score", "aci")
aci_leaderboard_df = aci_original_df.copy()
_, soap_original_df = get_leaderboard_df(EVAL_RESULTS_PATH, EVAL_REQUESTS_PATH, SOAP_COLS, SOAP_BENCHMARK_COLS, "score", "soap")
soap_leaderboard_df = soap_original_df.copy()
# breakpoint()
# # Token based results
# _, token_based_datasets_original_df = get_leaderboard_df(EVAL_RESULTS_PATH, EVAL_REQUESTS_PATH, DATASET_COLS, DATASET_BENCHMARK_COLS, "TokenBasedWithMacroAverage", "datasets")
# token_based_datasets_leaderboard_df = token_based_datasets_original_df.copy()
# _, token_based_types_original_df = get_leaderboard_df(EVAL_RESULTS_PATH, EVAL_REQUESTS_PATH, Clinical_TYPES_COLS, TYPES_BENCHMARK_COLS, "TokenBasedWithMacroAverage", "clinical_types")
# token_based_types_leaderboard_df = token_based_types_original_df.copy()
(
finished_eval_queue_df,
running_eval_queue_df,
pending_eval_queue_df,
) = get_evaluation_queue_df(EVAL_REQUESTS_PATH, EVAL_COLS)
# breakpoint()
def update_df(shown_columns, subset="datasets"):
# changes to be made here
if subset == "datasets":
leaderboard_table_df = harness_datasets_leaderboard_df.copy()
hidden_leader_board_df = harness_datasets_original_df
elif subset == "open_ended":
leaderboard_table_df = open_ended_leaderboard_df.copy()
hidden_leader_board_df = open_ended_original_df
elif subset == "med_safety":
leaderboard_table_df = med_safety_leaderboard_df.copy()
hidden_leader_board_df = med_safety_original_df
elif subset == "medical_summarization":
leaderboard_table_df = medical_summarization_leaderboard_df.copy()
hidden_leader_board_df = medical_summarization_original_df
elif subset == "aci":
leaderboard_table_df = aci_leaderboard_df.copy()
hidden_leader_board_df = aci_original_df
elif subset == "soap":
leaderboard_table_df = soap_leaderboard_df.copy()
hidden_leader_board_df = soap_original_df
# else:
# match evaluation_metric:
# case "Span Based":
# leaderboard_table_df = span_based_types_leaderboard_df.copy()
# hidden_leader_board_df = span_based_types_original_df
# case "Token Based":
# leaderboard_table_df = token_based_types_leaderboard_df.copy()
# hidden_leader_board_df = token_based_types_original_df
# case _:
# pass
value_cols = [c.name for c in fields(AutoEvalColumn) if c.never_hidden] + shown_columns
# breakpoint()
return leaderboard_table_df[value_cols], hidden_leader_board_df
# Searching and filtering
def update_table(
hidden_df: pd.DataFrame,
columns: list,
query: str = "",
type_query: list = None,
domain_specific_query: list = None,
size_query: list = None,
precision_query: str = None,
show_deleted: bool = False,
):
filtered_df = filter_models(hidden_df, type_query, domain_specific_query, size_query, precision_query, show_deleted)
filtered_df = filter_queries(query, filtered_df)
df = select_columns(filtered_df, columns, list(hidden_df.columns))
return df
def search_table(df: pd.DataFrame, query: str) -> pd.DataFrame:
return df[(df[AutoEvalColumn.model.name].str.contains(query, case=False))]
def select_columns(df: pd.DataFrame, columns: list, cols:list) -> pd.DataFrame:
always_here_cols = [
AutoEvalColumn.model_type_symbol.name,
AutoEvalColumn.model.name,
]
# We use COLS to maintain sorting
filtered_df = df[always_here_cols + [c for c in cols if c in df.columns and c in columns]]
return filtered_df
def filter_queries(query: str, filtered_df: pd.DataFrame) -> pd.DataFrame:
final_df = []
if query != "":
queries = [q.strip() for q in query.split(";")]
for _q in queries:
_q = _q.strip()
if _q != "":
temp_filtered_df = search_table(filtered_df, _q)
if len(temp_filtered_df) > 0:
final_df.append(temp_filtered_df)
if len(final_df) > 0:
filtered_df = pd.concat(final_df)
filtered_df = filtered_df.drop_duplicates(
subset=[
AutoEvalColumn.model.name,
# AutoEvalColumn.precision.name,
# AutoEvalColumn.revision.name,
]
)
return filtered_df
def filter_models(
df: pd.DataFrame, type_query: list, domain_specific_query: list, size_query: list, precision_query: list, show_deleted: bool
) -> pd.DataFrame:
# Show all models
# if show_deleted:
# filtered_df = df
# else: # Show only still on the hub models
# filtered_df = df[df[AutoEvalColumn.still_on_hub.name] == True]
filtered_df = df
if type_query is not None:
type_name = [t.split(" ")[1] for t in type_query]
filtered_df = filtered_df.loc[df[AutoEvalColumn.model_type.name].isin(type_name)]
if domain_specific_query is not None:
domain_specifics = []
if "Yes" in domain_specific_query:
domain_specifics.append(True)
if "No" in domain_specific_query:
domain_specifics.append(False)
filtered_df = filtered_df.loc[df[AutoEvalColumn.is_domain_specific.name].isin(domain_specifics)]
# if architecture_query is not None:
# arch_types = [t for t in architecture_query]
# filtered_df = filtered_df.loc[df[AutoEvalColumn.architecture.name].isin(arch_types)]
# # filtered_df = filtered_df.loc[df[AutoEvalColumn.architecture.name].isin(architecture_query + ["None"])]
if precision_query is not None:
if AutoEvalColumn.precision.name in df.columns:
filtered_df = filtered_df.loc[df[AutoEvalColumn.precision.name].isin(precision_query + ["None"])]
if size_query is not None:
numeric_interval = pd.IntervalIndex(sorted([NUMERIC_INTERVALS[s] for s in size_query]))
params_column = pd.to_numeric(df[AutoEvalColumn.params.name], errors="coerce")
mask = params_column.apply(lambda x: any(numeric_interval.contains(x)))
filtered_df = filtered_df.loc[mask]
return filtered_df
demo = gr.Blocks(css=custom_css)
with demo:
print("hello")
gr.HTML(TITLE)
gr.HTML(LOGO, elem_classes="logo")
gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
with gr.Tabs(elem_classes="tab-buttons") as tabs:
with gr.TabItem("πŸ… Closed Ended Evaluation", elem_id="llm-benchmark-tab-table", id=0):
with gr.Row():
with gr.Column():
with gr.Row():
search_bar = gr.Textbox(
placeholder=" πŸ” Search for your model (separate multiple queries with `;`) and press ENTER...",
show_label=False,
elem_id="search-bar",
)
with gr.Row():
shown_columns = gr.CheckboxGroup(
choices=[c.name for c in fields(AutoEvalColumn) if not c.hidden and not c.never_hidden and (c.invariant or c.dataset_task_col)],
value=[
c.name
for c in fields(AutoEvalColumn)
if c.displayed_by_default and not c.hidden and not c.never_hidden and (c.invariant or c.dataset_task_col)
],
label="Select columns to show",
elem_id="column-select",
interactive=True,
)
# with gr.Row():
# deleted_models_visibility = gr.Checkbox(
# value=False, label="Show gated/private/deleted models", interactive=True
# )
with gr.Column(min_width=320):
# with gr.Box(elem_id="box-filter"):
filter_columns_type = gr.CheckboxGroup(
label="Model Types",
choices=[t.to_str() for t in ModelType],
value=[t.to_str() for t in ModelType],
interactive=True,
elem_id="filter-columns-type",
)
# filter_columns_architecture = gr.CheckboxGroup(
# label="Architecture Types",
# choices=[i.value.name for i in ModelArch],
# value=[i.value.name for i in ModelArch],
# interactive=True,
# elem_id="filter-columns-architecture",
# )
filter_domain_specific = gr.CheckboxGroup(
label="Domain specific models",
choices=["Yes", "No"],
value=["Yes", "No"],
interactive=True,
elem_id="filter-columns-type",
)
filter_columns_size = gr.CheckboxGroup(
label="Model sizes (in billions of parameters)",
choices=list(NUMERIC_INTERVALS.keys()),
value=list(NUMERIC_INTERVALS.keys()),
interactive=True,
elem_id="filter-columns-size",
)
datasets_leaderboard_df, datasets_original_df = update_df(shown_columns.value, subset="datasets")
leaderboard_table = gr.components.Dataframe(
value=datasets_leaderboard_df[[c.name for c in fields(AutoEvalColumn) if c.never_hidden] + shown_columns.value],
headers=[c.name for c in fields(AutoEvalColumn) if c.never_hidden] + shown_columns.value,
datatype=TYPES,
elem_id="leaderboard-table",
interactive=False,
visible=True,
)
# Dummy leaderboard for handling the case when the user uses backspace key
hidden_leaderboard_table_for_search = gr.components.Dataframe(
value=datasets_original_df[DATASET_COLS],
headers=DATASET_COLS,
datatype=TYPES,
visible=False,
)
search_bar.submit(
update_table,
[
hidden_leaderboard_table_for_search,
shown_columns,
search_bar,
filter_columns_type,
filter_domain_specific,
filter_columns_size
# filter_columns_architecture
],
leaderboard_table,
)
for selector in [
shown_columns,
filter_columns_type,
filter_domain_specific,
# filter_columns_architecture,
filter_columns_size,
# deleted_models_visibility,
]:
selector.change(
update_table,
[
hidden_leaderboard_table_for_search,
shown_columns,
search_bar,
filter_columns_type,
filter_domain_specific,
filter_columns_size
# filter_columns_architecture,
],
leaderboard_table,
queue=True,
)
with gr.TabItem("πŸ… Open Ended Evaluation", elem_id="llm-benchmark-tab-table", id=1):
with gr.Row():
with gr.Column():
with gr.Row():
search_bar = gr.Textbox(
placeholder=" πŸ” Search for your model (separate multiple queries with `;`) and press ENTER...",
show_label=False,
elem_id="search-bar",
)
with gr.Row():
shown_columns = gr.CheckboxGroup(
choices=[c.name for c in fields(AutoEvalColumn) if not c.hidden and not c.never_hidden and (c.invariant or c.open_ended_col)],
value=[
c.name
for c in fields(AutoEvalColumn)
if c.displayed_by_default and not c.hidden and not c.never_hidden and (c.invariant or c.open_ended_col)
],
label="Select columns to show",
elem_id="column-select",
interactive=True,
)
# with gr.Row():
# deleted_models_visibility = gr.Checkbox(
# value=False, label="Show gated/private/deleted models", interactive=True
# )
with gr.Column(min_width=320):
# with gr.Box(elem_id="box-filter"):
filter_columns_type = gr.CheckboxGroup(
label="Model Types",
choices=[t.to_str() for t in ModelType],
value=[t.to_str() for t in ModelType],
interactive=True,
elem_id="filter-columns-type",
)
# filter_columns_architecture = gr.CheckboxGroup(
# label="Architecture Types",
# choices=[i.value.name for i in ModelArch],
# value=[i.value.name for i in ModelArch],
# interactive=True,
# elem_id="filter-columns-architecture",
# )
filter_domain_specific = gr.CheckboxGroup(
label="Domain specific models",
choices=["Yes", "No"],
value=["Yes", "No"],
interactive=True,
elem_id="filter-columns-type",
)
filter_columns_size = gr.CheckboxGroup(
label="Model sizes (in billions of parameters)",
choices=list(NUMERIC_INTERVALS.keys()),
value=list(NUMERIC_INTERVALS.keys()),
interactive=True,
elem_id="filter-columns-size",
)
datasets_leaderboard_df, datasets_original_df = update_df(shown_columns.value, subset="open_ended")
leaderboard_table = gr.components.Dataframe(
value=datasets_leaderboard_df[[c.name for c in fields(AutoEvalColumn) if c.never_hidden] + shown_columns.value],
headers=[c.name for c in fields(AutoEvalColumn) if c.never_hidden] + shown_columns.value,
datatype=TYPES,
elem_id="leaderboard-table",
interactive=False,
visible=True,
)
# Dummy leaderboard for handling the case when the user uses backspace key
hidden_leaderboard_table_for_search = gr.components.Dataframe(
value=datasets_original_df[OPEN_ENDED_COLS],
headers=OPEN_ENDED_COLS,
datatype=TYPES,
visible=False,
)
search_bar.submit(
update_table,
[
hidden_leaderboard_table_for_search,
shown_columns,
search_bar,
filter_columns_type,
filter_domain_specific,
filter_columns_size
# filter_columns_architecture
],
leaderboard_table,
)
for selector in [
shown_columns,
filter_columns_type,
filter_domain_specific,
# filter_columns_architecture,
filter_columns_size,
# deleted_models_visibility,
]:
selector.change(
update_table,
[
hidden_leaderboard_table_for_search,
shown_columns,
search_bar,
filter_columns_type,
filter_domain_specific,
filter_columns_size
# filter_columns_architecture,
],
leaderboard_table,
queue=True,
)
with gr.TabItem("πŸ… Med Safety", elem_id="llm-benchmark-tab-table", id=2):
with gr.Row():
with gr.Column():
with gr.Row():
search_bar = gr.Textbox(
placeholder=" πŸ” Search for your model (separate multiple queries with `;`) and press ENTER...",
show_label=False,
elem_id="search-bar",
)
with gr.Row():
shown_columns = gr.CheckboxGroup(
choices=[c.name for c in fields(AutoEvalColumn) if not c.hidden and not c.never_hidden and (c.invariant or c.med_safety_col)],
value=[
c.name
for c in fields(AutoEvalColumn)
if c.displayed_by_default and not c.hidden and not c.never_hidden and (c.invariant or c.med_safety_col)
],
label="Select columns to show",
elem_id="column-select",
interactive=True,
)
# with gr.Row():
# deleted_models_visibility = gr.Checkbox(
# value=False, label="Show gated/private/deleted models", interactive=True
# )
with gr.Column(min_width=320):
# with gr.Box(elem_id="box-filter"):
filter_columns_type = gr.CheckboxGroup(
label="Model Types",
choices=[t.to_str() for t in ModelType],
value=[t.to_str() for t in ModelType],
interactive=True,
elem_id="filter-columns-type",
)
# filter_columns_architecture = gr.CheckboxGroup(
# label="Architecture Types",
# choices=[i.value.name for i in ModelArch],
# value=[i.value.name for i in ModelArch],
# interactive=True,
# elem_id="filter-columns-architecture",
# )
filter_domain_specific = gr.CheckboxGroup(
label="Domain specific models",
choices=["Yes", "No"],
value=["Yes", "No"],
interactive=True,
elem_id="filter-columns-type",
)
filter_columns_size = gr.CheckboxGroup(
label="Model sizes (in billions of parameters)",
choices=list(NUMERIC_INTERVALS.keys()),
value=list(NUMERIC_INTERVALS.keys()),
interactive=True,
elem_id="filter-columns-size",
)
datasets_leaderboard_df, datasets_original_df = update_df(shown_columns.value, subset="med_safety")
leaderboard_table = gr.components.Dataframe(
value=datasets_leaderboard_df[[c.name for c in fields(AutoEvalColumn) if c.never_hidden] + shown_columns.value],
headers=[c.name for c in fields(AutoEvalColumn) if c.never_hidden] + shown_columns.value,
datatype=TYPES,
elem_id="leaderboard-table",
interactive=False,
visible=True,
)
# Dummy leaderboard for handling the case when the user uses backspace key
hidden_leaderboard_table_for_search = gr.components.Dataframe(
value=datasets_original_df[MED_SAFETY_COLS],
headers=MED_SAFETY_COLS,
datatype=TYPES,
visible=False,
)
search_bar.submit(
update_table,
[
hidden_leaderboard_table_for_search,
shown_columns,
search_bar,
filter_columns_type,
filter_domain_specific,
filter_columns_size
# filter_columns_architecture
],
leaderboard_table,
)
for selector in [
shown_columns,
filter_columns_type,
filter_domain_specific,
filter_columns_size,
# deleted_models_visibility,
]:
selector.change(
update_table,
[
hidden_leaderboard_table_for_search,
shown_columns,
search_bar,
filter_columns_type,
filter_domain_specific,
filter_columns_size
],
leaderboard_table,
queue=True,
)
with gr.TabItem("πŸ… Medical Summarization", elem_id="llm-benchmark-tab-table", id=3):
gr.Markdown(CROSS_EVALUATION_METRICS, elem_classes="markdown-text")
with gr.Row():
with gr.Column():
with gr.Row():
search_bar = gr.Textbox(
placeholder=" πŸ” Search for your model (separate multiple queries with `;`) and press ENTER...",
show_label=False,
elem_id="search-bar",
)
with gr.Row():
shown_columns = gr.CheckboxGroup(
choices=[c.name for c in fields(AutoEvalColumn) if not c.hidden and not c.never_hidden and (c.invariant or c.medical_summarization_col)],
value=[
c.name
for c in fields(AutoEvalColumn)
if c.displayed_by_default and not c.hidden and not c.never_hidden and (c.invariant or c.medical_summarization_col)
],
label="Select columns to show",
elem_id="column-select",
interactive=True,
)
# with gr.Row():
# deleted_models_visibility = gr.Checkbox(
# value=False, label="Show gated/private/deleted models", interactive=True
# )
with gr.Column(min_width=320):
# with gr.Box(elem_id="box-filter"):
filter_columns_type = gr.CheckboxGroup(
label="Model Types",
choices=[t.to_str() for t in ModelType],
value=[t.to_str() for t in ModelType],
interactive=True,
elem_id="filter-columns-type",
)
# filter_columns_architecture = gr.CheckboxGroup(
# label="Architecture Types",
# choices=[i.value.name for i in ModelArch],
# value=[i.value.name for i in ModelArch],
# interactive=True,
# elem_id="filter-columns-architecture",
# )
filter_domain_specific = gr.CheckboxGroup(
label="Domain specific models",
choices=["Yes", "No"],
value=["Yes", "No"],
interactive=True,
elem_id="filter-columns-type",
)
filter_columns_size = gr.CheckboxGroup(
label="Model sizes (in billions of parameters)",
choices=list(NUMERIC_INTERVALS.keys()),
value=list(NUMERIC_INTERVALS.keys()),
interactive=True,
elem_id="filter-columns-size",
)
datasets_leaderboard_df, datasets_original_df = update_df(shown_columns.value, subset="medical_summarization")
leaderboard_table = gr.components.Dataframe(
value=datasets_leaderboard_df[[c.name for c in fields(AutoEvalColumn) if c.never_hidden] + shown_columns.value],
headers=[c.name for c in fields(AutoEvalColumn) if c.never_hidden] + shown_columns.value,
datatype=TYPES,
elem_id="leaderboard-table",
interactive=False,
visible=True,
)
# Dummy leaderboard for handling the case when the user uses backspace key
hidden_leaderboard_table_for_search = gr.components.Dataframe(
value=datasets_original_df[MEDICAL_SUMMARIZATION_COLS],
headers=MEDICAL_SUMMARIZATION_COLS,
datatype=TYPES,
visible=False,
)
search_bar.submit(
update_table,
[
hidden_leaderboard_table_for_search,
shown_columns,
search_bar,
filter_columns_type,
filter_domain_specific,
filter_columns_size
# filter_columns_architecture
],
leaderboard_table,
)
for selector in [
shown_columns,
filter_columns_type,
filter_domain_specific,
filter_columns_size,
# deleted_models_visibility,
]:
selector.change(
update_table,
[
hidden_leaderboard_table_for_search,
shown_columns,
search_bar,
filter_columns_type,
filter_domain_specific,
filter_columns_size
],
leaderboard_table,
queue=True,
)
with gr.TabItem("πŸ… Note generation", elem_id="llm-benchmark-tab-table", id=4):
gr.Markdown(CROSS_EVALUATION_METRICS, elem_classes="markdown-text")
with gr.Tabs(elem_classes="tab-buttons2") as tabs:
with gr.TabItem("ACI Bench", elem_id="llm-benchmark-tab-table2", id=0):
with gr.Row():
with gr.Column():
with gr.Row():
search_bar = gr.Textbox(
placeholder=" πŸ” Search for your model (separate multiple queries with `;`) and press ENTER...",
show_label=False,
elem_id="search-bar",
)
with gr.Row():
shown_columns = gr.CheckboxGroup(
choices=[c.name for c in fields(AutoEvalColumn) if not c.hidden and not c.never_hidden and (c.invariant or c.aci_col)],
value=[
c.name
for c in fields(AutoEvalColumn)
if c.displayed_by_default and not c.hidden and not c.never_hidden and (c.invariant or c.aci_col)
],
label="Select columns to show",
elem_id="column-select",
interactive=True,
)
# with gr.Row():
# deleted_models_visibility = gr.Checkbox(
# value=False, label="Show gated/private/deleted models", interactive=True
# )
with gr.Column(min_width=320):
# with gr.Box(elem_id="box-filter"):
filter_columns_type = gr.CheckboxGroup(
label="Model Types",
choices=[t.to_str() for t in ModelType],
value=[t.to_str() for t in ModelType],
interactive=True,
elem_id="filter-columns-type",
)
# filter_columns_architecture = gr.CheckboxGroup(
# label="Architecture Types",
# choices=[i.value.name for i in ModelArch],
# value=[i.value.name for i in ModelArch],
# interactive=True,
# elem_id="filter-columns-architecture",
# )
filter_domain_specific = gr.CheckboxGroup(
label="Domain specific models",
choices=["Yes", "No"],
value=["Yes", "No"],
interactive=True,
elem_id="filter-columns-type",
)
filter_columns_size = gr.CheckboxGroup(
label="Model sizes (in billions of parameters)",
choices=list(NUMERIC_INTERVALS.keys()),
value=list(NUMERIC_INTERVALS.keys()),
interactive=True,
elem_id="filter-columns-size",
)
datasets_leaderboard_df, datasets_original_df = update_df(shown_columns.value, subset="aci")
leaderboard_table = gr.components.Dataframe(
value=datasets_leaderboard_df[[c.name for c in fields(AutoEvalColumn) if c.never_hidden] + shown_columns.value],
headers=[c.name for c in fields(AutoEvalColumn) if c.never_hidden] + shown_columns.value,
datatype=TYPES,
elem_id="leaderboard-table",
interactive=False,
visible=True,
)
# Dummy leaderboard for handling the case when the user uses backspace key
hidden_leaderboard_table_for_search = gr.components.Dataframe(
value=datasets_original_df[ACI_COLS],
headers=ACI_COLS,
datatype=TYPES,
visible=False,
)
search_bar.submit(
update_table,
[
hidden_leaderboard_table_for_search,
shown_columns,
search_bar,
filter_columns_type,
filter_domain_specific,
filter_columns_size
# filter_columns_architecture
],
leaderboard_table,
)
for selector in [
shown_columns,
filter_columns_type,
filter_domain_specific,
filter_columns_size,
# deleted_models_visibility,
]:
selector.change(
update_table,
[
hidden_leaderboard_table_for_search,
shown_columns,
search_bar,
filter_columns_type,
filter_domain_specific,
filter_columns_size
],
leaderboard_table,
queue=True,
)
with gr.TabItem("SOAP Notes", elem_id="llm-benchmark-tab-table2", id=1):
with gr.Row():
with gr.Column():
with gr.Row():
search_bar = gr.Textbox(
placeholder=" πŸ” Search for your model (separate multiple queries with `;`) and press ENTER...",
show_label=False,
elem_id="search-bar",
)
with gr.Row():
shown_columns = gr.CheckboxGroup(
choices=[c.name for c in fields(AutoEvalColumn) if not c.hidden and not c.never_hidden and (c.invariant or c.soap_col)],
value=[
c.name
for c in fields(AutoEvalColumn)
if c.displayed_by_default and not c.hidden and not c.never_hidden and (c.invariant or c.soap_col)
],
label="Select columns to show",
elem_id="column-select",
interactive=True,
)
# with gr.Row():
# deleted_models_visibility = gr.Checkbox(
# value=False, label="Show gated/private/deleted models", interactive=True
# )
with gr.Column(min_width=320):
# with gr.Box(elem_id="box-filter"):
filter_columns_type = gr.CheckboxGroup(
label="Model Types",
choices=[t.to_str() for t in ModelType],
value=[t.to_str() for t in ModelType],
interactive=True,
elem_id="filter-columns-type",
)
# filter_columns_architecture = gr.CheckboxGroup(
# label="Architecture Types",
# choices=[i.value.name for i in ModelArch],
# value=[i.value.name for i in ModelArch],
# interactive=True,
# elem_id="filter-columns-architecture",
# )
filter_domain_specific = gr.CheckboxGroup(
label="Domain specific models",
choices=["Yes", "No"],
value=["Yes", "No"],
interactive=True,
elem_id="filter-columns-type",
)
filter_columns_size = gr.CheckboxGroup(
label="Model sizes (in billions of parameters)",
choices=list(NUMERIC_INTERVALS.keys()),
value=list(NUMERIC_INTERVALS.keys()),
interactive=True,
elem_id="filter-columns-size",
)
datasets_leaderboard_df, datasets_original_df = update_df(shown_columns.value, subset="soap")
leaderboard_table = gr.components.Dataframe(
value=datasets_leaderboard_df[[c.name for c in fields(AutoEvalColumn) if c.never_hidden] + shown_columns.value],
headers=[c.name for c in fields(AutoEvalColumn) if c.never_hidden] + shown_columns.value,
datatype=TYPES,
elem_id="leaderboard-table",
interactive=False,
visible=True,
)
# Dummy leaderboard for handling the case when the user uses backspace key
hidden_leaderboard_table_for_search = gr.components.Dataframe(
value=datasets_original_df[SOAP_COLS],
headers=SOAP_COLS,
datatype=TYPES,
visible=False,
)
search_bar.submit(
update_table,
[
hidden_leaderboard_table_for_search,
shown_columns,
search_bar,
filter_columns_type,
filter_domain_specific,
filter_columns_size
# filter_columns_architecture
],
leaderboard_table,
)
for selector in [
shown_columns,
filter_columns_type,
filter_domain_specific,
filter_columns_size,
# deleted_models_visibility,
]:
selector.change(
update_table,
[
hidden_leaderboard_table_for_search,
shown_columns,
search_bar,
filter_columns_type,
filter_domain_specific,
filter_columns_size
],
leaderboard_table,
queue=True,
)
with gr.TabItem("πŸ“ About", elem_id="llm-benchmark-tab-table", id=5):
gr.Markdown(LLM_BENCHMARKS_TEXT_1, elem_classes="markdown-text")
# gr.HTML(EVALUATION_EXAMPLE_IMG, elem_classes="logo")
# gr.Markdown(LLM_BENCHMARKS_TEXT_2, elem_classes="markdown-text")
# gr.HTML(ENTITY_DISTRIBUTION_IMG, elem_classes="logo")
# gr.Markdown(LLM_BENCHMARKS_TEXT_3, elem_classes="markdown-text")
with gr.TabItem("πŸš€ Submit here! ", elem_id="llm-benchmark-tab-table", id=6):
with gr.Column():
with gr.Row():
gr.Markdown(EVALUATION_QUEUE_TEXT, elem_classes="markdown-text")
with gr.Column():
with gr.Accordion(
f"βœ… Finished Evaluations ({len(finished_eval_queue_df)})",
open=False,
):
with gr.Row():
finished_eval_table = gr.components.Dataframe(
value=finished_eval_queue_df,
headers=EVAL_COLS,
datatype=EVAL_TYPES,
row_count=5,
)
with gr.Accordion(
f"πŸ”„ Running Evaluation Queue ({len(running_eval_queue_df)})",
open=False,
):
with gr.Row():
running_eval_table = gr.components.Dataframe(
value=running_eval_queue_df,
headers=EVAL_COLS,
datatype=EVAL_TYPES,
row_count=5,
)
with gr.Accordion(
f"⏳ Pending Evaluation Queue ({len(pending_eval_queue_df)})",
open=False,
):
with gr.Row():
pending_eval_table = gr.components.Dataframe(
value=pending_eval_queue_df,
headers=EVAL_COLS,
datatype=EVAL_TYPES,
row_count=5,
)
with gr.Row():
gr.Markdown("# βœ‰οΈβœ¨ Submit your model here!", elem_classes="markdown-text")
with gr.Row():
with gr.Column():
model_name_textbox = gr.Textbox(label="Model name")
revision_name_textbox = gr.Textbox(label="Revision commit", placeholder="main")
model_type = gr.Dropdown(
choices=[t.to_str(" : ") for t in ModelType if t != ModelType.Unknown],
label="Model type",
multiselect=False,
value=None,
interactive=True,
)
with gr.Column():
precision = gr.Dropdown(
choices=[i.value.name for i in Precision if i != Precision.Unknown],
label="Precision",
multiselect=False,
value="auto",
interactive=True,
)
weight_type = gr.Dropdown(
choices=[i.value.name for i in WeightType],
label="Weights type",
multiselect=False,
value=WeightType.Original.value.name,
interactive=False,
)
base_model_name_textbox = gr.Textbox(label="Base model (for delta or adapter weights)", interactive=False)
with gr.Row():
domain_specific_toggle = gr.Checkbox(
label="Domain specific",
value=False,
info="Is your model medically oriented?",
)
chat_template_toggle = gr.Checkbox(
label="Use chat template",
value=False,
info="Is your model a chat model?",
)
submit_button = gr.Button("Submit Eval")
submission_result = gr.Markdown()
submit_button.click(
add_new_eval,
[
model_name_textbox,
base_model_name_textbox,
revision_name_textbox,
model_type,
domain_specific_toggle,
chat_template_toggle,
precision,
weight_type
],
submission_result,
)
with gr.Row():
with gr.Accordion("πŸ“™ Citation", open=False):
citation_button = gr.Textbox(
value=CITATION_BUTTON_TEXT,
label=CITATION_BUTTON_LABEL,
lines=20,
elem_id="citation-button",
show_copy_button=True,
)
scheduler = BackgroundScheduler()
scheduler.add_job(restart_space, "interval", seconds=1800)
scheduler.start()
demo.queue(default_concurrency_limit=40).launch(allowed_paths=['./assets/'])