Spaces:
AIR-Bench
/
Running on CPU Upgrade

File size: 20,382 Bytes
f766ce9
 
 
 
 
 
8a1daf9
f766ce9
36c5a0c
f766ce9
df659d0
 
f766ce9
77ded94
a0c2cea
8e1f9af
9002757
f766ce9
 
 
 
 
df659d0
9002757
e089630
 
 
 
 
 
 
 
f766ce9
1a2dba5
8a1daf9
 
32ebf18
8a1daf9
32ebf18
8a1daf9
f30cbcc
 
 
8a1daf9
4959887
ee1f0b7
 
af8395f
77ded94
2edd122
f30cbcc
ee1f0b7
 
 
77ded94
f766ce9
5808d8f
 
 
 
 
 
 
77ded94
 
5808d8f
77ded94
f30cbcc
df659d0
f30cbcc
 
 
 
 
 
77ded94
 
f30cbcc
77ded94
f766ce9
 
3bab3e9
 
 
 
 
 
77ded94
 
3bab3e9
77ded94
3bab3e9
 
 
 
 
 
 
 
77ded94
 
3bab3e9
77ded94
3bab3e9
 
f766ce9
 
 
 
 
 
8ec7973
f766ce9
 
32ebf18
2c23c13
 
 
 
 
 
 
f766ce9
 
6013e06
f766ce9
 
6013e06
f766ce9
32ebf18
 
 
 
 
 
 
 
 
 
9002757
 
 
 
 
 
32ebf18
8ec7973
 
32ebf18
 
8ec7973
 
 
 
e8879cc
f766ce9
e8879cc
 
 
 
 
f766ce9
 
e8879cc
 
2edd122
e8879cc
 
 
 
2edd122
e8879cc
 
af8395f
 
 
 
 
 
77ded94
 
 
 
 
 
f766ce9
 
8a1daf9
df659d0
f766ce9
 
 
 
 
 
f8b3d0f
af8395f
df659d0
f8b3d0f
 
5808d8f
 
61eca2d
3bab3e9
 
 
 
 
 
 
 
 
 
 
 
77ded94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5808d8f
 
61eca2d
3bab3e9
61eca2d
f8b3d0f
 
 
 
 
 
 
 
af8395f
f8b3d0f
 
 
 
f766ce9
5808d8f
 
 
 
 
 
 
 
 
af8395f
5808d8f
 
 
 
 
9002757
 
 
 
 
f30cbcc
 
 
2c23c13
 
 
 
 
 
 
f30cbcc
 
6013e06
 
f30cbcc
 
 
32ebf18
 
 
 
 
 
 
 
 
 
9002757
 
 
 
 
f30cbcc
32ebf18
 
 
 
 
 
 
 
 
f30cbcc
 
 
 
 
 
 
 
 
 
 
2edd122
f30cbcc
 
 
 
2edd122
f30cbcc
 
ee1f0b7
 
 
 
 
 
77ded94
 
 
 
 
 
f30cbcc
 
 
df659d0
f30cbcc
 
 
 
 
 
 
ee1f0b7
df659d0
f30cbcc
 
 
 
 
3bab3e9
 
 
 
 
 
 
 
77ded94
3bab3e9
 
 
 
77ded94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f30cbcc
 
 
3bab3e9
f30cbcc
 
 
 
 
 
 
 
 
ee1f0b7
77ded94
f30cbcc
 
 
 
 
 
 
 
 
 
 
 
 
 
ee1f0b7
77ded94
f30cbcc
 
 
 
8ec7973
9002757
 
 
 
 
36c5a0c
 
 
 
 
 
a30a228
 
6013e06
a30a228
6013e06
240d9ce
4cf5eb9
240d9ce
 
 
 
 
4cf5eb9
240d9ce
 
 
 
 
 
69a9e46
 
 
 
 
 
4a6f9cd
d00fb74
2c777fc
36c5a0c
d00fb74
9400714
d00fb74
 
 
2c777fc
4a6f9cd
 
 
9f44d20
 
 
 
 
 
4a6f9cd
 
 
 
 
d00fb74
240d9ce
 
d00fb74
9400714
4a6f9cd
 
 
 
36c5a0c
8a1daf9
 
f766ce9
 
 
 
57ca843
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
import gradio as gr
from apscheduler.schedulers.background import BackgroundScheduler
from huggingface_hub import snapshot_download

from src.about import (
    INTRODUCTION_TEXT,
    BENCHMARKS_TEXT,
    TITLE,
    EVALUATION_QUEUE_TEXT
)
from src.benchmarks import DOMAIN_COLS_QA, LANG_COLS_QA, DOMAIN_COLS_LONG_DOC, LANG_COLS_LONG_DOC, METRIC_LIST, \
    DEFAULT_METRIC
from src.display.css_html_js import custom_css
from src.display.utils import COL_NAME_IS_ANONYMOUS, COL_NAME_REVISION, COL_NAME_TIMESTAMP
from src.envs import API, EVAL_RESULTS_PATH, REPO_ID, RESULTS_REPO, TOKEN
from src.read_evals import get_raw_eval_results, get_leaderboard_df
from src.utils import update_table, update_metric, update_table_long_doc, upload_file, get_default_cols, submit_results, clear_reranking_selections


def restart_space():
    API.restart_space(repo_id=REPO_ID)



try:
    snapshot_download(
        repo_id=RESULTS_REPO, local_dir=EVAL_RESULTS_PATH, repo_type="dataset", tqdm_class=None, etag_timeout=30,
        token=TOKEN
    )
except Exception as e:
    print(f'failed to download')
    restart_space()

raw_data = get_raw_eval_results(f"{EVAL_RESULTS_PATH}/AIR-Bench_24.04")

original_df_qa = get_leaderboard_df(
    raw_data, task='qa', metric=DEFAULT_METRIC)
original_df_long_doc = get_leaderboard_df(
    raw_data, task='long-doc', metric=DEFAULT_METRIC)
print(f'raw data: {len(raw_data)}')
print(f'QA data loaded: {original_df_qa.shape}')
print(f'Long-Doc data loaded: {len(original_df_long_doc)}')

leaderboard_df_qa = original_df_qa.copy()
# leaderboard_df_qa = leaderboard_df_qa[has_no_nan_values(df, _benchmark_cols)]
shown_columns_qa, types_qa = get_default_cols(
    'qa', leaderboard_df_qa.columns, add_fix_cols=True)
leaderboard_df_qa = leaderboard_df_qa[~leaderboard_df_qa[COL_NAME_IS_ANONYMOUS]][shown_columns_qa]
leaderboard_df_qa.drop([COL_NAME_REVISION, COL_NAME_TIMESTAMP], axis=1, inplace=True)

leaderboard_df_long_doc = original_df_long_doc.copy()
shown_columns_long_doc, types_long_doc = get_default_cols(
    'long-doc', leaderboard_df_long_doc.columns, add_fix_cols=True)
leaderboard_df_long_doc = leaderboard_df_long_doc[~leaderboard_df_long_doc[COL_NAME_IS_ANONYMOUS]][shown_columns_long_doc]
leaderboard_df_long_doc.drop([COL_NAME_REVISION, COL_NAME_TIMESTAMP], axis=1, inplace=True)


def update_metric_qa(
        metric: str,
        domains: list,
        langs: list,
        reranking_model: list,
        query: str,
        show_anonymous: bool,
        show_revision_and_timestamp,
):
    return update_metric(raw_data, 'qa', metric, domains, langs, reranking_model, query, show_anonymous, show_revision_and_timestamp)


def update_metric_long_doc(
        metric: str,
        domains: list,
        langs: list,
        reranking_model: list,
        query: str,
        show_anonymous: bool,
        show_revision_and_timestamp,
):
    return update_metric(raw_data, "long-doc", metric, domains, langs, reranking_model, query, show_anonymous, show_revision_and_timestamp)


def update_table_without_ranking(
        hidden_df,
        domains,
        langs,
        reranking_query,
        query,
        show_anonymous,
        show_revision_and_timestamp,
):
    return update_table(hidden_df, domains, langs, reranking_query, query, show_anonymous, reset_ranking=False, show_revision_and_timestamp=show_revision_and_timestamp)


def update_table_without_ranking_long_doc(
        hidden_df,
        domains,
        langs,
        reranking_query,
        query,
        show_anonymous,
        show_revision_and_timestamp,
):
    return update_table_long_doc(hidden_df, domains, langs, reranking_query, query, show_anonymous, reset_ranking=False, show_revision_and_timestamp=show_revision_and_timestamp)


demo = gr.Blocks(css=custom_css)
with demo:
    gr.HTML(TITLE)
    gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")

    with gr.Tabs(elem_classes="tab-buttons") as tabs:
        with gr.TabItem("QA", elem_id="qa-benchmark-tab-table", id=0):
            with gr.Row():
                with gr.Column():
                    # search retrieval models
                    with gr.Row():
                        selected_version = gr.Dropdown(
                            choices=["AIR-Bench_24.04",],
                            value="AIR-Bench_24.04",
                            label="Select the version of AIR-Bench",
                            interactive = True
                        )
                    with gr.Row():
                        search_bar = gr.Textbox(
                            placeholder=" 🔍 Search for retrieval methods (separate multiple queries with `;`) and press ENTER...",
                            show_label=False,
                            elem_id="search-bar",
                            info="Search the retrieval methods"
                        )
                    # select reranking model
                    reranking_models = list(frozenset([eval_result.reranking_model for eval_result in raw_data]))
                    with gr.Row():
                        selected_rerankings = gr.CheckboxGroup(
                            choices=reranking_models,
                            value=reranking_models,
                            label="Select the reranking models",
                            elem_id="reranking-select",
                            interactive=True
                        )
                    with gr.Row():
                        select_noreranker_only_btn = gr.ClearButton(
                            selected_rerankings,
                            value="Only show results without ranking models",
                        )

                with gr.Column(min_width=320):
                    # select the metric
                    selected_metric = gr.Dropdown(
                        choices=METRIC_LIST,
                        value=DEFAULT_METRIC,
                        label="Select the metric",
                        interactive=True,
                        elem_id="metric-select",
                    )
                    # select domain
                    with gr.Row():
                        selected_domains = gr.CheckboxGroup(
                            choices=DOMAIN_COLS_QA,
                            value=DOMAIN_COLS_QA,
                            label="Select the domains",
                            elem_id="domain-column-select",
                            interactive=True,
                        )
                    # select language
                    with gr.Row():
                        selected_langs = gr.Dropdown(
                            choices=LANG_COLS_QA,
                            value=LANG_COLS_QA,
                            label="Select the languages",
                            elem_id="language-column-select",
                            multiselect=True,
                            interactive=True
                        )
                    with gr.Row():
                        show_anonymous = gr.Checkbox(
                            label="Show anonymous submissions",
                            value=False,
                            info="The anonymous submissions might have invalid model information."
                        )
                    with gr.Row():
                        show_revision_and_timestamp = gr.Checkbox(
                            label="Show submission details",
                            value=False,
                            info="Show the revision and timestamp information of submissions"
                        )

            leaderboard_table = gr.components.Dataframe(
                value=leaderboard_df_qa,
                datatype=types_qa,
                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=original_df_qa,
                datatype=types_qa,
                visible=False,
            )

            # Set search_bar listener
            search_bar.submit(
                update_table_without_ranking,
                [
                    hidden_leaderboard_table_for_search,
                    selected_domains,
                    selected_langs,
                    selected_rerankings,
                    search_bar,
                    show_anonymous,
                ],
                leaderboard_table,
            )

            for selector in [show_revision_and_timestamp, selected_rerankings]:
                selector.change(
                    update_table_without_ranking,
                    [
                        hidden_leaderboard_table_for_search,
                        selected_domains,
                        selected_langs,
                        selected_rerankings,
                        search_bar,
                        show_anonymous,
                        show_revision_and_timestamp
                    ],
                    leaderboard_table,
                    queue=True
                )

            # Set column-wise listener
            for selector in [
                selected_domains, selected_langs, show_anonymous
            ]:
                selector.change(
                    update_table,
                    [
                        hidden_leaderboard_table_for_search,
                        selected_domains,
                        selected_langs,
                        selected_rerankings,
                        search_bar,
                        show_anonymous,
                    ],
                    leaderboard_table,
                    queue=True,
                )

            # set metric listener
            selected_metric.change(
                update_metric_qa,
                [
                    selected_metric,
                    selected_domains,
                    selected_langs,
                    selected_rerankings,
                    search_bar,
                    show_anonymous,
                ],
                leaderboard_table,
                queue=True
            )

            select_noreranker_only_btn.click(
                clear_reranking_selections,
                outputs=selected_rerankings
            )

        with gr.TabItem("Long Doc", elem_id="long-doc-benchmark-tab-table", id=1):
            with gr.Row():
                with gr.Column():
                    with gr.Row():
                        selected_version = gr.Dropdown(
                            choices=["AIR-Bench_24.04",],
                            value="AIR-Bench_24.04",
                            label="Select the version of AIR-Bench",
                            interactive=True
                        )
                    with gr.Row():
                        search_bar = gr.Textbox(
                            info="Search the retrieval methods",
                            placeholder=" 🔍 Search for retrieval methods (separate multiple queries with `;`) and press ENTER...",
                            show_label=False,
                            elem_id="search-bar-long-doc",
                        )
                    # select reranking model
                    reranking_models = list(frozenset([eval_result.reranking_model for eval_result in raw_data]))
                    with gr.Row():
                        selected_rerankings = gr.CheckboxGroup(
                            choices=reranking_models,
                            value=reranking_models,
                            label="Select the reranking models",
                            elem_id="reranking-select-long-doc",
                            interactive=True
                        )
                    with gr.Row():
                        select_noreranker_only_btn = gr.ClearButton(
                            selected_rerankings,
                            value="Only show results without ranking models",
                        )
                with gr.Column(min_width=320):
                    # select the metric
                    with gr.Row():
                        selected_metric = gr.Dropdown(
                            choices=METRIC_LIST,
                            value=DEFAULT_METRIC,
                            label="Select the metric",
                            interactive=True,
                            elem_id="metric-select-long-doc",
                        )
                    # select domain
                    with gr.Row():
                        selected_domains = gr.CheckboxGroup(
                            choices=DOMAIN_COLS_LONG_DOC,
                            value=DOMAIN_COLS_LONG_DOC,
                            label="Select the domains",
                            elem_id="domain-column-select-long-doc",
                            interactive=True,
                        )
                    # select language
                    with gr.Row():
                        selected_langs = gr.Dropdown(
                            choices=LANG_COLS_LONG_DOC,
                            value=LANG_COLS_LONG_DOC,
                            label="Select the languages",
                            elem_id="language-column-select-long-doc",
                            multiselect=True,
                            interactive=True
                        )
                    with gr.Row():
                        show_anonymous = gr.Checkbox(
                            label="Show anonymous submissions",
                            value=False,
                            info="The anonymous submissions might have invalid model information."
                        )
                    with gr.Row():
                        show_revision_and_timestamp = gr.Checkbox(
                            label="Show submission details",
                            value=False,
                            info="Show the revision and timestamp information of submissions"
                        )

            leaderboard_table_long_doc = gr.components.Dataframe(
                value=leaderboard_df_long_doc,
                datatype=types_long_doc,
                elem_id="leaderboard-table-long-doc",
                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=original_df_long_doc,
                datatype=types_long_doc,
                visible=False,
            )

            # Set search_bar listener
            search_bar.submit(
                update_table_without_ranking_long_doc,
                [
                    hidden_leaderboard_table_for_search,
                    selected_domains,
                    selected_langs,
                    selected_rerankings,
                    search_bar,
                    show_anonymous,
                    show_revision_and_timestamp
                ],
                leaderboard_table_long_doc,
            )

            for selector in [show_revision_and_timestamp, selected_rerankings]:
                selector.change(
                    update_table_without_ranking_long_doc,
                    [
                        hidden_leaderboard_table_for_search,
                        selected_domains,
                        selected_langs,
                        selected_rerankings,
                        search_bar,
                        show_anonymous,
                        show_revision_and_timestamp
                    ],
                    leaderboard_table_long_doc,
                    queue=True,
                )

            # Set column-wise listener
            for selector in [
                selected_domains, selected_langs, show_anonymous
            ]:
                selector.change(
                    update_table_long_doc,
                    [
                        hidden_leaderboard_table_for_search,
                        selected_domains,
                        selected_langs,
                        selected_rerankings,
                        search_bar,
                        show_anonymous,
                        show_revision_and_timestamp
                    ],
                    leaderboard_table_long_doc,
                    queue=True,
                )

            # set metric listener
            selected_metric.change(
                update_metric_long_doc,
                [
                    selected_metric,
                    selected_domains,
                    selected_langs,
                    selected_rerankings,
                    search_bar,
                    show_anonymous,
                    show_revision_and_timestamp
                ],
                leaderboard_table_long_doc,
                queue=True
            )

            select_noreranker_only_btn.click(
                clear_reranking_selections,
                outputs=selected_rerankings
            )

        with gr.TabItem("🚀Submit here!", elem_id="submit-tab-table", id=2):
            with gr.Column():
                with gr.Row():
                    gr.Markdown(EVALUATION_QUEUE_TEXT, elem_classes="markdown-text")
                with gr.Row():
                    gr.Markdown("## ✉️Submit your model here!", elem_classes="markdown-text")
                with gr.Row():
                    with gr.Column():
                        model_name = gr.Textbox(label="Retrieval Method name")
                    with gr.Column():
                        model_url = gr.Textbox(label="Retrieval Method URL")
                with gr.Row():
                    with gr.Column():
                        reranking_model_name = gr.Textbox(
                            label="Reranking Model name",
                            info="Optional",
                            value="NoReranker"
                        )
                    with gr.Column():
                        reranking_model_url = gr.Textbox(
                            label="Reranking Model URL",
                            info="Optional",
                            value=""
                        )
                with gr.Row():
                    with gr.Column():
                        benchmark_version = gr.Dropdown(
                            ["AIR-Bench_24.04", ],
                            value="AIR-Bench_24.04",
                            interactive=True,
                            label="AIR-Bench Version")
                with gr.Row():
                    upload_button = gr.UploadButton("Click to upload search results", file_count="single")
                with gr.Row():
                    file_output = gr.File()
                with gr.Row():
                    is_anonymous = gr.Checkbox(
                        label="Nope. I want to submit anonymously 🥷",
                        value=False,
                        info="Do you want to shown on the leaderboard by default?")
                with gr.Row():
                    submit_button = gr.Button("Submit")
                with gr.Row():
                    submission_result = gr.Markdown()
                upload_button.upload(
                    upload_file,
                    [
                        upload_button,
                    ],
                    file_output)
                submit_button.click(
                    submit_results,
                    [
                        file_output,
                        model_name,
                        model_url,
                        reranking_model_name,
                        reranking_model_url,
                        benchmark_version,
                        is_anonymous
                    ],
                    submission_result,
                    show_progress="hidden"
                )

        with gr.TabItem("📝 About", elem_id="llm-benchmark-tab-table", id=3):
            gr.Markdown(BENCHMARKS_TEXT, elem_classes="markdown-text")

scheduler = BackgroundScheduler()
scheduler.add_job(restart_space, "interval", seconds=1800)
scheduler.start()
demo.queue(default_concurrency_limit=40).launch()