Spaces:
Running
Running
File size: 10,161 Bytes
6204efe bcdb701 872fcfa bf46203 872fcfa 6204efe 872fcfa 6204efe 872fcfa 6204efe 872fcfa 6204efe 872fcfa 6204efe |
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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
import gradio as gr
import pandas as pd
import os
from huggingface_hub import snapshot_download, login
from apscheduler.schedulers.background import BackgroundScheduler
from src.display.about import (
CITATION_BUTTON_LABEL,
CITATION_BUTTON_TEXT,
CONTACT_TEXT,
EVALUATION_QUEUE_TEXT,
INTRODUCTION_TEXT,
LLM_BENCHMARKS_TEXT,
TITLE,
SUB_TITLE,
)
from src.display.css_html_js import custom_css
from src.envs import API
from src.leaderboard.load_results import load_data
def restart_space():
API.restart_space(repo_id="Auto-Arena/Leaderboard")
csv_path = f"./src/results/auto-arena-llms-results-20241007.csv"
csv_path_chinese = f"./src/results/auto-arena-llms-results-chinese-20240531.csv"
df_results = load_data(csv_path).sort_values(by="Rank")
df_results_chinese = load_data(csv_path_chinese)
all_columns = ['Rank', 'Model', 'From', 'Open?', 'Params(B)', 'Cost', 'Score']
show_columns = ['Rank', 'Model', 'From', 'Open?', 'Params(B)', 'Cost', 'Score']
TYPES = ['number', 'markdown', 'str', 'str', 'str', 'str', 'number']
df_results_init = df_results.copy()[show_columns]
df_results_chinese_init = df_results_chinese.copy()[show_columns]
def update_table(
hidden_df: pd.DataFrame,
# columns: list,
#type_query: list,
open_query: list,
# precision_query: str,
# size_query: list,
# show_deleted: bool,
query: str,
):
# filtered_df = filter_models(hidden_df, type_query, size_query, precision_query, show_deleted)
# filtered_df = filter_queries(query, filtered_df)
# df = select_columns(filtered_df, columns)
filtered_df = hidden_df.copy()
# filtered_df = filtered_df[filtered_df['type'].isin(type_query)]
map_open = {'open': 'Yes', 'closed': 'No'}
filtered_df = filtered_df[filtered_df['Open?'].isin([map_open[o] for o in open_query])]
filtered_df = filter_queries(query, filtered_df)
# filtered_df = filtered_df[[map_columns[k] for k in columns]]
# deduplication
# df = df.drop_duplicates(subset=["Model"])
df = filtered_df.drop_duplicates()
df = df[show_columns]
return df
def search_table(df: pd.DataFrame, query: str) -> pd.DataFrame:
return df[(df['Model'].str.contains(query, case=False))]
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)
return filtered_df
demo = gr.Blocks(css=custom_css)
with demo:
gr.HTML(TITLE)
gr.HTML(SUB_TITLE)
gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
with gr.Tabs(elem_classes="tab-buttons") as tabs:
# the first tab
with gr.TabItem("English", elem_id="llm-benchmark-Sum", id=0):
# meta-info
with gr.Row():
with gr.Column():
search_bar = gr.Textbox(
placeholder=" π Search for models you are interested in (separate multiple models with `;`) and press ENTER...",
show_label=False,
elem_id="search-bar",
)
# with gr.Row():
# with gr.Column():
# type_query = gr.CheckboxGroup(
# choices=["π’ base", "πΆ chat"],
# value=["πΆ chat" ],
# label="model types to show",
# elem_id="type-select",
# interactive=True,
# )
with gr.Column():
open_query = gr.CheckboxGroup(
choices=["open", "closed"],
value=["open", "closed"],
label="open-source OR closed-source models?",
elem_id="open-select",
interactive=True,
)
leaderboard_table = gr.components.Dataframe(
value = df_results,
datatype = TYPES,
elem_id = "leaderboard-table",
interactive = False,
visible=True,
# column_widths=["20%", "6%", "8%", "6%", "8%", "8%", "6%", "6%", "6%", "6%", "6%"],
)
gr.Markdown("The \"Cost\" column is calculated as USD / Million tokens of output.")
hidden_leaderboard_table_for_search = gr.components.Dataframe(
value=df_results_init,
# elem_id="leaderboard-table",
interactive=False,
visible=False,
)
search_bar.submit(
update_table,
[
# df_avg,
hidden_leaderboard_table_for_search,
# shown_columns,
#type_query,
open_query,
# filter_columns_type,
# filter_columns_precision,
# filter_columns_size,
# deleted_models_visibility,
search_bar,
],
leaderboard_table,
)
#for selector in [type_query, open_query]:
for selector in [open_query]:
selector.change(
update_table,
[
# df_avg,
hidden_leaderboard_table_for_search,
# shown_columns,
#type_query,
open_query,
# filter_columns_type,
# filter_columns_precision,
# filter_columns_size,
# deleted_models_visibility,
search_bar,
],
leaderboard_table,
)
with gr.TabItem("Chinese", elem_id="llm-benchmark-Sum", id=1):
# meta-info
with gr.Row():
with gr.Column():
search_bar = gr.Textbox(
placeholder=" π Search for models you are interested in (separate multiple models with `;`) and press ENTER...",
show_label=False,
elem_id="search-bar",
)
# with gr.Row():
# with gr.Column():
# type_query = gr.CheckboxGroup(
# choices=["π’ base", "πΆ chat"],
# value=["πΆ chat" ],
# label="model types to show",
# elem_id="type-select",
# interactive=True,
# )
with gr.Column():
open_query = gr.CheckboxGroup(
choices=["open", "closed"],
value=["open", "closed"],
label="open-source OR closed-source models?",
elem_id="open-select",
interactive=True,
)
leaderboard_table = gr.components.Dataframe(
value = df_results_chinese,
datatype = TYPES,
elem_id = "leaderboard-table",
interactive = False,
visible=True,
# column_widths=["20%", "6%", "8%", "6%", "8%", "8%", "6%", "6%", "6%", "6%", "6%"],
)
gr.Markdown("The \"Cost\" column is calculated as USD / Million tokens of output.")
hidden_leaderboard_table_for_search = gr.components.Dataframe(
value=df_results_chinese_init,
# elem_id="leaderboard-table",
interactive=False,
visible=False,
)
search_bar.submit(
update_table,
[
# df_avg,
hidden_leaderboard_table_for_search,
# shown_columns,
#type_query,
open_query,
# filter_columns_type,
# filter_columns_precision,
# filter_columns_size,
# deleted_models_visibility,
search_bar,
],
leaderboard_table,
)
#for selector in [type_query, open_query]:
for selector in [open_query]:
selector.change(
update_table,
[
# df_avg,
hidden_leaderboard_table_for_search,
# shown_columns,
#type_query,
open_query,
# filter_columns_type,
# filter_columns_precision,
# filter_columns_size,
# deleted_models_visibility,
search_bar,
],
leaderboard_table,
)
# with gr.TabItem("π About", elem_id="llm-benchmark-tab-table", id=1):
# gr.Markdown(LLM_BENCHMARKS_TEXT, elem_classes="markdown-text")
# 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,
# )
gr.Markdown(CONTACT_TEXT, elem_classes="markdown-text")
demo.launch()
scheduler = BackgroundScheduler()
scheduler.add_job(restart_space, "interval", seconds=1800)
scheduler.start()
demo.queue(default_concurrency_limit=40).launch(share=True)
|