SVBench / app.py
yzy666's picture
update
7262dff
__all__ = ['block', 'make_clickable_model', 'make_clickable_user', 'get_submissions']
import os
import gradio as gr
import pandas as pd
from constants import *
global data_component, filter_component
def get_baseline_df():
df = pd.read_csv(CSV_DIR)
df['Average'] = ((df['Streaming_OS'] + df['Dialogue_OS']) / 2).round(2)
df = df.sort_values(by="Average", ascending=False)
present_columns = ['Model'] + checkbox_group.value
df = df[present_columns]
return df
def get_all_df():
df = pd.read_csv(CSV_DIR)
df['Average'] = ((df['Streaming_OS'] + df['Dialogue_OS']) / 2).round(2)
df = df.sort_values(by="Average", ascending=False)
return df
def on_filter_model_size_method_change(selected_columns):
updated_data = get_all_df()
# columns:
selected_columns = [item for item in TASK_INFO if item in selected_columns]
present_columns = ['Model'] + selected_columns
updated_data = updated_data[present_columns]
updated_data = updated_data.sort_values(by=selected_columns[0], ascending=False)
updated_headers = present_columns
update_datatype = [DATA_TITILE_TYPE[COLUMN_NAMES.index(x)] for x in updated_headers]
filter_component = gr.components.Dataframe(
value=updated_data,
headers=updated_headers,
type="pandas",
datatype=update_datatype,
interactive=False,
visible=True,
)
return filter_component
def search_model(query):
df = get_all_df()
filtered_df = df[df['Model'].str.contains(query, case=False)]
return filtered_df
block = gr.Blocks()
with block:
gr.Markdown(
LEADERBORAD_INTRODUCTION
)
with gr.Tabs(elem_classes="tab-buttons") as tabs:
with gr.TabItem("πŸ“Š SVBench", elem_id="svbench-tab-table", id=1):
with gr.Accordion("Citation", open=False):
citation_button = gr.Textbox(
value=CITATION_BUTTON_TEXT,
label=CITATION_BUTTON_LABEL,
elem_id="citation-button",
lines=10,
)
gr.Markdown(
TABLE_INTRODUCTION
)
# selection for column part:
checkbox_group = gr.CheckboxGroup(
choices=TASK_INFO,
value=AVG_INFO,
label="Evaluation Dimension",
interactive=True,
)
search_box = gr.Textbox(
label="Search Model",
placeholder="Enter model name",
interactive=True,
)
data_component = gr.components.Dataframe(
value=get_baseline_df,
headers=['Model', 'Type', 'Size'] + AVG_INFO,
type="pandas",
datatype=DATA_TITILE_TYPE,
interactive=False,
visible=True,
)
checkbox_group.change(fn=on_filter_model_size_method_change, inputs=[checkbox_group], outputs=data_component)
search_box.change(fn=search_model, inputs=[search_box], outputs=data_component)
# table 2
with gr.TabItem("πŸ“ About", elem_id="svbench-tab-table", id=2):
gr.Markdown(LEADERBORAD_INFO, elem_classes="markdown-text")
# table 3
with gr.TabItem("πŸš€ Submit here! ", elem_id="-tab-table", id=3):
gr.Markdown(SUBMIT_INTRODUCTION, elem_classes="markdown-text")
def refresh_data():
value1 = get_baseline_df()
return value1
with gr.Row():
data_run = gr.Button("Refresh")
with gr.Row():
result_download = gr.Button("Download Leaderboard")
file_download = gr.File(label="download the csv of leaderboard.", visible=False)
data_run.click(on_filter_model_size_method_change, inputs=[checkbox_group], outputs=data_component)
result_download.click(lambda: (CSV_DIR, gr.update(visible=True)), inputs=None, outputs=[file_download, file_download])
block.launch()