idolezal commited on
Commit
5212908
1 Parent(s): b4d14b9

Reduced global variables

Browse files
Files changed (1) hide show
  1. app.py +221 -217
app.py CHANGED
@@ -291,239 +291,243 @@ tr.row_odd {
291
 
292
  """
293
 
294
- with gr.Blocks(theme=gr.themes.Soft(text_size=text_md), css=custom_css) as main:
295
- gr.Markdown(HEADER_MARKDOWN)
 
296
 
297
- with gr.Tabs():
298
- with leaderboard_server.var_lock.ro:
299
- submission_ids_and_titles = get_submission_ids_and_titles()
300
-
301
- with gr.TabItem('Leaderboard'):
302
- with gr.Column():
303
- gr.Markdown(LEADERBOARD_TAB_TITLE_MARKDOWN)
304
-
305
- with gr.Row():
306
- category_of_tasks = gr.Dropdown(
307
- choices=[leaderboard_server.TASKS_CATEGORY_OVERALL] + sorted(leaderboard_server.TASKS_CATEGORIES),
308
- value=leaderboard_server.TASKS_CATEGORY_OVERALL,
309
- label="Category of benchmarks",
310
- interactive=True,
311
- )
312
-
313
- with gr.Row():
314
- leaderboard_table = gr.DataFrame(
315
- leaderboard_server.get_leaderboard(category=leaderboard_server.TASKS_CATEGORY_OVERALL),
316
- interactive=False,
317
- label=None,
318
- visible=True,
319
- datatype="markdown",
320
- elem_classes="leaderboard-table",
321
- )
322
-
323
- with gr.Row():
324
- leaderboard_table_legend = gr.DataFrame(
325
- value=None,
326
- headers=[
327
- "Abbr.", # "task abbreviation"
328
- "Name",
329
- "URL",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
330
  ],
331
- column_widths=["150px"],
332
- datatype="markdown",
333
- label="Descriptions of the tasks",
334
- visible=False,
335
- interactive=False,
336
- elem_classes="leaderboard-table-legend",
337
- )
338
-
339
- with gr.Row():
340
- tournament_results_title = gr.Markdown(
341
- value="## Tournament results for selected model",
342
- visible=False,
343
- )
344
-
345
- with gr.Row():
346
- tournament_results_dropdown = gr.Dropdown(
347
- value=None,
348
- choices=submission_ids_and_titles,
349
- label="Select model",
350
- visible=False,
351
- interactive=True,
352
  )
353
-
354
- with gr.Row():
355
- model_tournament_results_table = gr.DataFrame(
356
- value=None,
357
- datatype="markdown",
358
- label="The model won against…",
359
- visible=False,
360
- interactive=False,
361
- elem_classes="leaderboard-table-model-details",
362
  )
 
 
 
363
 
364
- category_of_tasks.change(
365
- fn=change_leaderboard_category,
366
- inputs=[
367
- category_of_tasks,
368
- tournament_results_dropdown,
369
- ],
370
- outputs=[
371
- leaderboard_table,
372
- leaderboard_table_legend,
373
- tournament_results_title,
374
- tournament_results_dropdown,
375
- model_tournament_results_table,
376
- ],
377
- )
378
-
379
- tournament_results_dropdown.change(
380
- fn=fetch_model_tournament_results_table,
381
- inputs=[
382
- tournament_results_dropdown,
383
- category_of_tasks,
384
- ],
385
- outputs=model_tournament_results_table,
386
  )
387
 
388
- with gr.TabItem('Model details'):
389
- gr.Markdown(MORE_DETAILS_MARKDOWN)
390
-
391
- detail_dropdown = gr.Dropdown(
392
- choices=submission_ids_and_titles,
393
- label="Select model",
394
- interactive=True,
395
- )
396
-
397
- with gr.Row():
398
- model_description = gr.Text(value='', label='Model description', visible=False, interactive=False)
399
- model_url = gr.Text(value='', label='Model url', visible=False, interactive=False)
400
 
401
- detail_dropdown.change(
402
- fn=fetch_model_detail,
403
- inputs=[detail_dropdown],
404
- outputs=[model_description, model_url],
405
- )
406
 
407
- with gr.TabItem('Submission'):
408
- with gr.Column():
409
- gr.Markdown(SUBMISSION_TAB_TITLE_MARKDOWN)
410
-
411
- submission_inputs = dict.fromkeys(SUBMISSION_INPUTS)
412
-
413
- with gr.Row():
414
- submission_inputs["team_name"] = gr.Textbox(label='Team name', type='text')
415
- submission_inputs["model_name"] = gr.Textbox(label='Model name', type='text')
416
- submission_inputs["model_type"] = gr.Dropdown(
417
- label="Model type",
418
- choices=("chat", "pretrained", "ensemble"),
419
- )
420
- submission_inputs["parameters"] = gr.Number(
421
- label='Parameters (B)',
422
- value=0.01,
423
- step=0.01,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
424
  )
425
 
426
- with gr.Row():
427
- submission_inputs["input_length"] = gr.Number(
428
- label='Input length (# tokens)',
429
- value=0,
430
- step=1,
431
- )
432
- submission_inputs["precision"] = gr.Dropdown(
433
- label="Precision",
434
- choices=("float32", "bfloat32", "float16", "bfloat16", "8bit", "4bit"),
435
  )
436
- submission_inputs["description"] = gr.Textbox(label='Description', type='text')
437
- submission_inputs["link_to_model"] = gr.Textbox(label='Link to model', type='text')
438
-
439
- submission_inputs["submission_file"] = gr.File(label='Upload your results', type='filepath')
440
-
441
- pre_submission_btn = gr.Button(value='Pre-submit model', interactive=True)
442
 
443
- submit_prompt = gr.Markdown(
444
- SUBMISSION_DETAILS_MARKDOWN,
445
- visible=False
446
- )
447
-
448
- pre_submit_info = gr.Markdown(
449
- RANKING_AFTER_SUBMISSION_MARKDOWN,
450
- visible=False
451
- )
452
-
453
- pre_submit_table = gr.DataFrame(pd.DataFrame(), interactive=False, label=None, visible=False)
454
-
455
- submission_btn_yes = gr.Button(value='Submit model', interactive=False, visible=False)
456
- submission_btn_no = gr.Button(value='Reverse process', interactive=False, visible=False)
457
-
458
- with Modal(visible=False) as modal_submit:
459
- gr.Markdown(MODAL_SUBMIT_MARKDOWN)
460
- modal_submit_yes = gr.Button("Yes", interactive=True)
461
- modal_submit_no = gr.Button("No", interactive=True)
462
-
463
- pre_submission_btn.click(
464
- fn=on_submit_pressed,
465
- outputs=[pre_submission_btn],
466
- ).then( # TODO: Zjistit proč to neběží konkurentně.
467
- fn=process_submission,
468
- inputs=list(submission_inputs.values()),
469
- outputs=[
470
- pre_submission_btn,
471
- submit_prompt,
472
- submission_btn_yes,
473
- submission_btn_no,
474
- pre_submit_info,
475
- pre_submit_table,
476
- ],
477
- )
478
 
479
- submission_btn_yes.click(
480
- fn=show_modal,
481
- outputs=[modal_submit]
482
- )
483
 
484
- modal_submit_yes.click(
485
- fn=submit_results,
486
- outputs=[
487
- pre_submission_btn,
488
- submission_btn_yes,
489
- submission_btn_no,
490
- submit_prompt,
491
- pre_submit_info,
492
- pre_submit_table,
493
- leaderboard_table,
494
- modal_submit,
495
- detail_dropdown,
496
- category_of_tasks,
497
- tournament_results_dropdown,
498
- ],
499
- )
500
 
501
- modal_submit_no.click(
502
- fn=hide_modal,
503
- outputs=[modal_submit]
504
- )
505
 
506
- submission_btn_no.click(
507
- fn=erase_pre_submit,
508
- outputs=[
509
- pre_submission_btn,
510
- submission_btn_yes,
511
- submission_btn_no,
512
- submit_prompt,
513
- pre_submit_info,
514
- pre_submit_table,
515
- ],
516
- )
 
 
 
 
 
 
 
 
 
 
 
517
 
518
- main.load(
519
- on_application_load,
520
- inputs=None,
521
- outputs=[
522
- leaderboard_table,
523
- detail_dropdown,
524
- category_of_tasks,
525
- tournament_results_dropdown,
526
- ]
527
- )
528
 
529
- main.launch()
 
 
291
 
292
  """
293
 
294
+ def gradio_app():
295
+ with gr.Blocks(theme=gr.themes.Soft(text_size=text_md), css=custom_css) as main:
296
+ gr.Markdown(HEADER_MARKDOWN)
297
 
298
+ with gr.Tabs():
299
+ with leaderboard_server.var_lock.ro:
300
+ submission_ids_and_titles = get_submission_ids_and_titles()
301
+
302
+ with gr.TabItem('Leaderboard'):
303
+ with gr.Column():
304
+ gr.Markdown(LEADERBOARD_TAB_TITLE_MARKDOWN)
305
+
306
+ with gr.Row():
307
+ category_of_tasks = gr.Dropdown(
308
+ choices=[leaderboard_server.TASKS_CATEGORY_OVERALL] + sorted(leaderboard_server.TASKS_CATEGORIES),
309
+ value=leaderboard_server.TASKS_CATEGORY_OVERALL,
310
+ label="Category of benchmarks",
311
+ interactive=True,
312
+ )
313
+
314
+ with gr.Row():
315
+ leaderboard_table = gr.DataFrame(
316
+ leaderboard_server.get_leaderboard(category=leaderboard_server.TASKS_CATEGORY_OVERALL),
317
+ interactive=False,
318
+ label=None,
319
+ visible=True,
320
+ datatype="markdown",
321
+ elem_classes="leaderboard-table",
322
+ )
323
+
324
+ with gr.Row():
325
+ leaderboard_table_legend = gr.DataFrame(
326
+ value=None,
327
+ headers=[
328
+ "Abbr.", # "task abbreviation"
329
+ "Name",
330
+ "URL",
331
+ ],
332
+ column_widths=["150px"],
333
+ datatype="markdown",
334
+ label="Descriptions of the tasks",
335
+ visible=False,
336
+ interactive=False,
337
+ elem_classes="leaderboard-table-legend",
338
+ )
339
+
340
+ with gr.Row():
341
+ tournament_results_title = gr.Markdown(
342
+ value="## Tournament results for selected model",
343
+ visible=False,
344
+ )
345
+
346
+ with gr.Row():
347
+ tournament_results_dropdown = gr.Dropdown(
348
+ value=None,
349
+ choices=submission_ids_and_titles,
350
+ label="Select model",
351
+ visible=False,
352
+ interactive=True,
353
+ )
354
+
355
+ with gr.Row():
356
+ model_tournament_results_table = gr.DataFrame(
357
+ value=None,
358
+ datatype="markdown",
359
+ label="The model won against…",
360
+ visible=False,
361
+ interactive=False,
362
+ elem_classes="leaderboard-table-model-details",
363
+ )
364
+
365
+ category_of_tasks.change(
366
+ fn=change_leaderboard_category,
367
+ inputs=[
368
+ category_of_tasks,
369
+ tournament_results_dropdown,
370
+ ],
371
+ outputs=[
372
+ leaderboard_table,
373
+ leaderboard_table_legend,
374
+ tournament_results_title,
375
+ tournament_results_dropdown,
376
+ model_tournament_results_table,
377
  ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
378
  )
379
+
380
+ tournament_results_dropdown.change(
381
+ fn=fetch_model_tournament_results_table,
382
+ inputs=[
383
+ tournament_results_dropdown,
384
+ category_of_tasks,
385
+ ],
386
+ outputs=model_tournament_results_table,
 
387
  )
388
+
389
+ with gr.TabItem('Model details'):
390
+ gr.Markdown(MORE_DETAILS_MARKDOWN)
391
 
392
+ detail_dropdown = gr.Dropdown(
393
+ choices=submission_ids_and_titles,
394
+ label="Select model",
395
+ interactive=True,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
396
  )
397
 
398
+ with gr.Row():
399
+ model_description = gr.Text(value='', label='Model description', visible=False, interactive=False)
400
+ model_url = gr.Text(value='', label='Model url', visible=False, interactive=False)
 
 
 
 
 
 
 
 
 
401
 
402
+ detail_dropdown.change(
403
+ fn=fetch_model_detail,
404
+ inputs=[detail_dropdown],
405
+ outputs=[model_description, model_url],
406
+ )
407
 
408
+ with gr.TabItem('Submission'):
409
+ with gr.Column():
410
+ gr.Markdown(SUBMISSION_TAB_TITLE_MARKDOWN)
411
+
412
+ submission_inputs = dict.fromkeys(SUBMISSION_INPUTS)
413
+
414
+ with gr.Row():
415
+ submission_inputs["team_name"] = gr.Textbox(label='Team name', type='text')
416
+ submission_inputs["model_name"] = gr.Textbox(label='Model name', type='text')
417
+ submission_inputs["model_type"] = gr.Dropdown(
418
+ label="Model type",
419
+ choices=("chat", "pretrained", "ensemble"),
420
+ )
421
+ submission_inputs["parameters"] = gr.Number(
422
+ label='Parameters (B)',
423
+ value=0.01,
424
+ step=0.01,
425
+ )
426
+
427
+ with gr.Row():
428
+ submission_inputs["input_length"] = gr.Number(
429
+ label='Input length (# tokens)',
430
+ value=0,
431
+ step=1,
432
+ )
433
+ submission_inputs["precision"] = gr.Dropdown(
434
+ label="Precision",
435
+ choices=("float32", "bfloat32", "float16", "bfloat16", "8bit", "4bit"),
436
+ )
437
+ submission_inputs["description"] = gr.Textbox(label='Description', type='text')
438
+ submission_inputs["link_to_model"] = gr.Textbox(label='Link to model', type='text')
439
+
440
+ submission_inputs["submission_file"] = gr.File(label='Upload your results', type='filepath')
441
+
442
+ pre_submission_btn = gr.Button(value='Pre-submit model', interactive=True)
443
+
444
+ submit_prompt = gr.Markdown(
445
+ SUBMISSION_DETAILS_MARKDOWN,
446
+ visible=False
447
  )
448
 
449
+ pre_submit_info = gr.Markdown(
450
+ RANKING_AFTER_SUBMISSION_MARKDOWN,
451
+ visible=False
 
 
 
 
 
 
452
  )
 
 
 
 
 
 
453
 
454
+ pre_submit_table = gr.DataFrame(pd.DataFrame(), interactive=False, label=None, visible=False)
455
+
456
+ submission_btn_yes = gr.Button(value='Submit model', interactive=False, visible=False)
457
+ submission_btn_no = gr.Button(value='Reverse process', interactive=False, visible=False)
458
+
459
+ with Modal(visible=False) as modal_submit:
460
+ gr.Markdown(MODAL_SUBMIT_MARKDOWN)
461
+ modal_submit_yes = gr.Button("Yes", interactive=True)
462
+ modal_submit_no = gr.Button("No", interactive=True)
463
+
464
+ pre_submission_btn.click(
465
+ fn=on_submit_pressed,
466
+ outputs=[pre_submission_btn],
467
+ ).then( # TODO: Zjistit proč to neběží konkurentně.
468
+ fn=process_submission,
469
+ inputs=list(submission_inputs.values()),
470
+ outputs=[
471
+ pre_submission_btn,
472
+ submit_prompt,
473
+ submission_btn_yes,
474
+ submission_btn_no,
475
+ pre_submit_info,
476
+ pre_submit_table,
477
+ ],
478
+ )
 
 
 
 
 
 
 
 
 
 
479
 
480
+ submission_btn_yes.click(
481
+ fn=show_modal,
482
+ outputs=[modal_submit]
483
+ )
484
 
485
+ modal_submit_yes.click(
486
+ fn=submit_results,
487
+ outputs=[
488
+ pre_submission_btn,
489
+ submission_btn_yes,
490
+ submission_btn_no,
491
+ submit_prompt,
492
+ pre_submit_info,
493
+ pre_submit_table,
494
+ leaderboard_table,
495
+ modal_submit,
496
+ detail_dropdown,
497
+ category_of_tasks,
498
+ tournament_results_dropdown,
499
+ ],
500
+ )
501
 
502
+ modal_submit_no.click(
503
+ fn=hide_modal,
504
+ outputs=[modal_submit]
505
+ )
506
 
507
+ submission_btn_no.click(
508
+ fn=erase_pre_submit,
509
+ outputs=[
510
+ pre_submission_btn,
511
+ submission_btn_yes,
512
+ submission_btn_no,
513
+ submit_prompt,
514
+ pre_submit_info,
515
+ pre_submit_table,
516
+ ],
517
+ )
518
+
519
+ main.load(
520
+ on_application_load,
521
+ inputs=None,
522
+ outputs=[
523
+ leaderboard_table,
524
+ detail_dropdown,
525
+ category_of_tasks,
526
+ tournament_results_dropdown,
527
+ ]
528
+ )
529
 
530
+ return main
 
 
 
 
 
 
 
 
 
531
 
532
+ app = gradio_app()
533
+ app.launch()