Spaces:
Running
Running
File size: 13,897 Bytes
65c6479 441cdc8 0e06db3 97d7225 65c6479 9c1b957 35957e0 9c1b957 60867e4 9c1b957 97d7225 541cf85 9c1b957 e608ddc 0e06db3 85b9042 e608ddc 65c6479 97d7225 85b9042 97d7225 d31b48d c69a5b0 541cf85 0e06db3 1e647ba c69a5b0 d31b48d c69a5b0 441cdc8 d31b48d a55b227 d31b48d a55b227 8baedda d31b48d 040103b d31b48d a55b227 8baedda a55b227 8baedda a55b227 9c1b957 60867e4 a55b227 60867e4 9c1b957 541cf85 a55b227 d31b48d 040103b 19ae77b d31b48d a55b227 9c1b957 d31b48d 9c1b957 c69a5b0 4fa4bc0 9c1b957 c69a5b0 d31b48d 9c1b957 74fdd72 9c1b957 3b28608 7bd7d77 3b28608 7bd7d77 d31b48d 7bd7d77 d31b48d cc86cb5 7157d11 c69a5b0 7157d11 cfb8d80 c69a5b0 cfb8d80 c69a5b0 cfb8d80 7157d11 c69a5b0 7157d11 c69a5b0 7157d11 cc86cb5 6c84d42 c69a5b0 6c84d42 cfb8d80 c69a5b0 cfb8d80 c69a5b0 cfb8d80 6c84d42 c69a5b0 6c84d42 c69a5b0 040103b cfb8d80 4d3390f 35957e0 441cdc8 9c1b957 97d7225 cfb8d80 97d7225 653c0f4 |
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 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
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
# clone / pull the lmeh eval data
TOKEN = os.environ.get("TOKEN", None)
login(token=TOKEN)
RESULTS_REPO = f"SeaLLMs/SeaExam-results"
CACHE_PATH=os.getenv("HF_HOME", ".")
EVAL_RESULTS_PATH = os.path.join(CACHE_PATH, "eval-results")
print(EVAL_RESULTS_PATH)
snapshot_download(
repo_id=RESULTS_REPO, local_dir=EVAL_RESULTS_PATH, repo_type="dataset",
token=TOKEN
)
def restart_space():
API.restart_space(repo_id="SeaLLMs/SeaExam_leaderboard", token=TOKEN)
all_columns = ['R','type', 'Model','open?', 'avg_sea β¬οΈ', 'en', 'zh', 'id', 'th', 'vi', 'avg', 'params(B)']
show_columns = ['R', 'Model','type','open?','params(B)', 'avg_sea β¬οΈ', 'en', 'zh', 'id', 'th', 'vi', 'avg', ]
TYPES = ['number', 'markdown', 'str', 'str', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number']
# Load the data from the csv file
csv_path = f'{EVAL_RESULTS_PATH}/SeaExam_results_20240425.csv'
df_m3exam, df_mmlu, df_avg = load_data(csv_path)
# df_m3exam = df_m3exam.copy()[show_columns]
# df_mmlu = df_mmlu.copy()[show_columns]
df_avg_init = df_avg.copy()[df_avg['type'] == 'πΆ chat'][show_columns]
df_m3exam_init = df_m3exam.copy()[df_m3exam['type'] == 'πΆ chat'][show_columns]
df_mmlu_init = df_mmlu.copy()[df_mmlu['type'] == 'πΆ chat'][show_columns]
# data_types = ['number', 'str', 'markdown','str', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number']
# map_columns = {'rank':'R','type':'type', 'Model':'Model','open?':'open?', 'avg_sea':'avg_sea β¬οΈ', 'en':'en', 'zh':'zh', 'id':'id', 'th':'th', 'vi':'vi', 'avg':'avg', 'params':'params(B)'}
# map_types = {'rank': 'number', 'type': 'str', 'Model': 'markdown', 'open?': 'str', 'avg_sea': 'number', 'en': 'number', 'zh': 'number', 'id': 'number', 'th': 'number', 'vi': 'number', 'avg': 'number', 'params': 'number'}
# Searching and filtering
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': 'Y', 'closed': 'N'}
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:
with gr.TabItem("π
Overall", elem_id="llm-benchmark-Sum", 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():
# with gr.Column():
# shown_columns = gr.CheckboxGroup(
# choices=["rank","type", "Model","open?", "avg_sea", "en", "zh", "id", "th", "vi", "avg", "params"],
# value=["rank", "type", "Model", "avg_sea", "en", "zh", "id", "th", "vi", "avg", "params"],
# label="Select model types to show",
# elem_id="column-select",
# interactive=True,
# )
# 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_avg_init,
# [[map_columns[k] for k in shown_columns.value]],
# value=leaderboard_df[
# [c.name for c in fields(AutoEvalColumn) if c.never_hidden]
# + shown_columns.value
# + [AutoEvalColumn.dummy.name]
# ],
# headers=[c.name for c in fields(AutoEvalColumn) if c.never_hidden] + shown_columns.value,
datatype=TYPES,
elem_id="leaderboard-table",
interactive=False,
# datatype=['number', 'str', 'markdown', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number'],
# datatype=[map_types[k] for k in shown_columns.value],
visible=True,
# column_widths=["20%", "6%", "8%", "6%", "8%", "8%", "6%", "6%", "6%", "6%", "6%"],
)
hidden_leaderboard_table_for_search = gr.components.Dataframe(
value=df_avg,
# 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]:
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("M3Exam", elem_id="llm-benchmark-M3Exam", id=1):
with gr.Row():
with gr.Column():
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.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_m3exam_init,
interactive=False,
visible=True,
# datatype=['number', 'str', 'markdown', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number'],
datatype=TYPES,
)
hidden_leaderboard_table_for_search = gr.components.Dataframe(
value=df_m3exam,
interactive=False,
visible=False,
)
search_bar.submit(
update_table,
[
hidden_leaderboard_table_for_search,
type_query,
open_query,
search_bar,
],
leaderboard_table,
)
for selector in [type_query, open_query]:
selector.change(
update_table,
[
hidden_leaderboard_table_for_search,
type_query,
open_query,
search_bar,
],
leaderboard_table,
)
with gr.TabItem("MMLU", elem_id="llm-benchmark-MMLU", id=2):
with gr.Row():
with gr.Column():
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.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_mmlu_init,
interactive=False,
visible=True,
# datatype=['number', 'str', 'markdown', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number'],
datatype=TYPES,
)
hidden_leaderboard_table_for_search = gr.components.Dataframe(
value=df_mmlu,
interactive=False,
visible=False,
)
search_bar.submit(
update_table,
[
hidden_leaderboard_table_for_search,
type_query,
open_query,
search_bar,
],
leaderboard_table,
)
for selector in [type_query, open_query]:
selector.change(
update_table,
[
hidden_leaderboard_table_for_search,
type_query,
open_query,
search_bar,
],
leaderboard_table,
)
with gr.TabItem("π About", elem_id="llm-benchmark-tab-table", id=3):
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)
|