Luis Kalckstein commited on
Commit
eeb055e
·
unverified ·
1 Parent(s): 32e8dbc

Improving layout

Browse files
Files changed (2) hide show
  1. app.py +1 -1
  2. pii_leaderboard.py +36 -261
app.py CHANGED
@@ -8,7 +8,7 @@ from pii_leaderboard import create_app
8
  if __name__ == "__main__":
9
  demo = create_app()
10
  demo.launch(
11
- server_name="0.0.0.0",
12
  server_port=7860,
13
  share=False
14
  )
 
8
  if __name__ == "__main__":
9
  demo = create_app()
10
  demo.launch(
11
+ server_name="127.0.0.1",
12
  server_port=7860,
13
  share=False
14
  )
pii_leaderboard.py CHANGED
@@ -398,176 +398,6 @@ def create_pii_leaderboard():
398
 
399
  return card_html
400
 
401
- def download_performance_card(model_name):
402
- """Generate and return downloadable HTML file for the model performance card"""
403
- if not model_name:
404
- return None
405
-
406
- card_html = generate_performance_card(model_name)
407
-
408
- # Create a complete HTML document
409
- full_html = f"""
410
- <!DOCTYPE html>
411
- <html lang="en">
412
- <head>
413
- <meta charset="UTF-8">
414
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
415
- <title>{model_name} - Performance Card</title>
416
- <style>
417
- @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');
418
-
419
- :root {{
420
- --bg-primary: #1A1414;
421
- --bg-secondary: rgba(239, 235, 231, 0.03);
422
- --bg-card: rgba(239, 235, 231, 0.02);
423
- --border-subtle: rgba(239, 235, 231, 0.08);
424
- --text-primary: #EFEBE7;
425
- --text-secondary: #C2B8AE;
426
- --text-muted: #67594B;
427
- --accent-primary: #DE9DCC;
428
- --accent-secondary: #F25E45;
429
- --accent-tertiary: #6EB579;
430
- --accent-quaternary: #F0C968;
431
- --glow-primary: rgba(222, 157, 204, 0.4);
432
- }}
433
-
434
- body {{
435
- margin: 0;
436
- padding: 40px;
437
- background: var(--bg-primary);
438
- font-family: 'Inter', sans-serif;
439
- color: var(--text-primary);
440
- }}
441
-
442
- .performance-card {{
443
- background: linear-gradient(145deg, rgba(26, 20, 20, 0.98) 0%, rgba(222, 157, 204, 0.05) 100%);
444
- border: 2px solid var(--accent-primary);
445
- border-radius: 24px;
446
- padding: 32px;
447
- max-width: 700px;
448
- margin: 0 auto;
449
- box-shadow:
450
- 0 20px 40px rgba(0, 0, 0, 0.5),
451
- 0 0 80px rgba(222, 157, 204, 0.2);
452
- }}
453
-
454
- .card-header {{
455
- text-align: center;
456
- margin-bottom: 24px;
457
- }}
458
-
459
- .card-model-name {{
460
- font-size: 2rem;
461
- font-weight: 800;
462
- background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
463
- -webkit-background-clip: text;
464
- -webkit-text-fill-color: transparent;
465
- margin-bottom: 8px;
466
- line-height: 1.2;
467
- }}
468
-
469
- .card-stars {{
470
- font-size: 1.2rem;
471
- margin: 8px 0;
472
- }}
473
-
474
- .metrics-grid {{
475
- display: grid;
476
- grid-template-columns: repeat(2, 1fr);
477
- gap: 16px;
478
- margin: 24px 0;
479
- }}
480
-
481
- .metric-item {{
482
- display: flex;
483
- flex-direction: column;
484
- align-items: center;
485
- padding: 16px;
486
- background: rgba(239, 235, 231, 0.05);
487
- border-radius: 12px;
488
- border: 1px solid var(--border-subtle);
489
- }}
490
-
491
- .metric-icon {{
492
- font-size: 1.5rem;
493
- margin-bottom: 8px;
494
- }}
495
-
496
- .metric-label {{
497
- font-size: 0.85rem;
498
- color: var(--text-secondary);
499
- margin-bottom: 4px;
500
- text-align: center;
501
- }}
502
-
503
- .metric-value {{
504
- font-size: 1.1rem;
505
- font-weight: 700;
506
- color: var(--text-primary);
507
- text-align: center;
508
- }}
509
-
510
- .domains-section {{
511
- margin-top: 24px;
512
- }}
513
-
514
- .domains-title {{
515
- color: var(--text-primary);
516
- font-size: 1.2rem;
517
- margin-bottom: 16px;
518
- text-align: center;
519
- }}
520
-
521
- .domains-grid {{
522
- display: grid;
523
- grid-template-columns: repeat(5, 1fr);
524
- gap: 12px;
525
- }}
526
-
527
- .domain-item {{
528
- display: flex;
529
- flex-direction: column;
530
- align-items: center;
531
- padding: 12px;
532
- background: rgba(239, 235, 231, 0.03);
533
- border-radius: 8px;
534
- border: 1px solid var(--border-subtle);
535
- }}
536
-
537
- .domain-name {{
538
- font-size: 1.2rem;
539
- margin-bottom: 4px;
540
- }}
541
-
542
- .domain-score {{
543
- font-size: 0.9rem;
544
- font-weight: 600;
545
- }}
546
-
547
- .card-footer {{
548
- text-align: center;
549
- margin-top: 24px;
550
- padding-top: 16px;
551
- border-top: 1px solid var(--border-subtle);
552
- }}
553
-
554
- .card-url {{
555
- color: var(--text-secondary);
556
- font-size: 0.9rem;
557
- }}
558
- </style>
559
- </head>
560
- <body>
561
- {card_html}
562
- </body>
563
- </html>
564
- """
565
-
566
- # Create a temporary file
567
- with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix=f'_{model_name.replace(" ", "_")}_performance_card.html', encoding='utf-8') as f:
568
- f.write(full_html)
569
- return f.name
570
-
571
  # Load initial data
572
  initial_df = load_leaderboard_data()
573
  initial_table = filter_and_sort_data("All", "All", "Overall Accuracy", "Descending")
@@ -575,39 +405,38 @@ def create_pii_leaderboard():
575
  # Display header
576
  gr.HTML(HEADER_CONTENT)
577
 
578
- # Document type filter section
579
  gr.HTML("""
580
  <div class="dark-container" style="margin-bottom: 32px;">
581
  <div class="section-header">
582
- <span class="section-icon" style="color: var(--accent-primary);">📄</span>
583
  <h3 style="margin: 0; color: var(--text-primary); font-size: 1.5rem; font-family: 'Inter', sans-serif; font-weight: 700;">
584
- Document Type Analysis
585
  </h3>
586
  </div>
587
  <p style="color: var(--text-secondary); margin-bottom: 20px; font-size: 1.1rem; font-family: 'Inter', sans-serif;">
588
- Select a document type to see specialized PII detection performance
589
  </p>
 
 
 
 
590
  """)
591
 
592
- with gr.Row():
593
- document_type_filter = gr.Radio(
594
- choices=["All", "Healthcare", "Financial", "Government", "Legal", "Personal"],
595
- value="All",
596
- label="",
597
- interactive=True,
598
- elem_classes=["document-type-radio"]
599
- )
600
-
601
- gr.HTML("</div>")
602
 
603
- # Filter controls
604
  gr.HTML("""
605
- <div class="dark-container" style="margin-bottom: 24px;">
606
- <div class="section-header">
607
- <span class="section-icon" style="color: var(--accent-secondary);">🔍</span>
608
- <h3 style="margin: 0; color: var(--text-primary); font-size: 1.5rem; font-family: 'Inter', sans-serif; font-weight: 700;">
609
- Filters & Sorting
610
- </h3>
611
  </div>
612
  """)
613
 
@@ -636,43 +465,39 @@ def create_pii_leaderboard():
636
  elem_classes=["compact-radio"]
637
  )
638
 
639
- gr.HTML("</div>")
640
-
641
- # Main leaderboard table
642
  gr.HTML("""
643
- <div class="dark-container" style="margin-bottom: 24px;">
644
- <div class="section-header">
645
- <span class="section-icon" style="color: var(--accent-primary);">📈</span>
646
- <h3 style="margin: 0; color: var(--text-primary); font-size: 1.5rem; font-family: 'Inter', sans-serif; font-weight: 700;">
647
- PII Detection Performance Leaderboard
648
- </h3>
649
- </div>
650
- <div class="dataframe-container">
651
  """)
652
 
653
  leaderboard_table = gr.HTML(initial_table)
654
 
655
  gr.HTML("""
 
656
  </div>
657
  </div>""")
658
 
 
 
 
 
 
 
 
659
  # Performance Card Section
660
  gr.HTML("""
661
  <div class="dark-container" style="margin-top: 32px;">
662
  <div class="section-header">
663
  <span class="section-icon" style="color: var(--accent-primary);">🎯</span>
664
  <h3 style="margin: 0; color: var(--text-primary); font-size: 1.5rem; font-family: 'Inter', sans-serif; font-weight: 700;">
665
- Model Performance Card
666
  </h3>
667
  </div>
668
- <p style="color: var(--text-secondary); margin-bottom: 20px; font-size: 1.1rem; font-family: 'Inter', sans-serif;">
669
- Comprehensive performance card for any model - perfect for presentations and reports
670
  </p>
671
-
672
- <div style="display: flex; gap: 24px; align-items: flex-start;">
673
- <div style="flex: 0 0 280px;">
674
- <div style="background: rgba(239, 235, 231, 0.03); border: 1px solid var(--border-subtle);
675
- border-radius: 16px; padding: 20px; position: sticky; top: 20px;">
676
  """)
677
 
678
  card_model_selector = gr.Dropdown(
@@ -687,7 +512,7 @@ def create_pii_leaderboard():
687
  </div>
688
  </div>
689
 
690
- <div style="flex: 1; min-width: 0;" id="card-display-container">
691
  """)
692
 
693
  # Card display area
@@ -695,20 +520,7 @@ def create_pii_leaderboard():
695
  initial_card_html = generate_performance_card(initial_model) if initial_model else ""
696
  card_display = gr.HTML(value=initial_card_html, elem_id="performance-card-html")
697
 
698
- # Download button below the card
699
- gr.HTML("""
700
- <div style="margin-top: 24px; text-align: center;">
701
- """)
702
-
703
- download_button = gr.DownloadButton(
704
- label="📥 Download Performance Card",
705
- value=None,
706
- variant="primary",
707
- elem_classes=["download-card-btn"]
708
- )
709
-
710
  gr.HTML("""
711
- </div>
712
  </div>
713
  </div>
714
  </div>""")
@@ -897,23 +709,6 @@ def create_pii_leaderboard():
897
  min-width: auto !important;
898
  max-width: 120px !important;
899
  }}
900
-
901
- .download-card-btn {{
902
- background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary)) !important;
903
- color: white !important;
904
- border: none !important;
905
- padding: 12px 24px !important;
906
- border-radius: 12px !important;
907
- font-weight: 600 !important;
908
- font-size: 0.95rem !important;
909
- transition: all 0.3s ease !important;
910
- box-shadow: 0 4px 16px rgba(222, 157, 204, 0.4) !important;
911
- }}
912
-
913
- .download-card-btn:hover {{
914
- transform: translateY(-2px) !important;
915
- box-shadow: 0 6px 20px rgba(222, 157, 204, 0.6) !important;
916
- }}
917
  </style>
918
  """)
919
 
@@ -940,26 +735,6 @@ def create_pii_leaderboard():
940
  inputs=[card_model_selector],
941
  outputs=[card_display]
942
  )
943
-
944
- # Download card functionality
945
- def update_download_button(model_name):
946
- if model_name:
947
- file_path = download_performance_card(model_name)
948
- return file_path
949
- return None
950
-
951
- card_model_selector.change(
952
- fn=update_download_button,
953
- inputs=[card_model_selector],
954
- outputs=[download_button]
955
- )
956
-
957
- # Methodology section
958
- gr.HTML(f"""
959
- <div class="dark-container" style="margin-top: 32px;">
960
- {METHODOLOGY}
961
- </div>
962
- """)
963
 
964
  def create_app():
965
  """Create the main Gradio application"""
 
398
 
399
  return card_html
400
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
401
  # Load initial data
402
  initial_df = load_leaderboard_data()
403
  initial_table = filter_and_sort_data("All", "All", "Overall Accuracy", "Descending")
 
405
  # Display header
406
  gr.HTML(HEADER_CONTENT)
407
 
408
+ # Main leaderboard section with all filters
409
  gr.HTML("""
410
  <div class="dark-container" style="margin-bottom: 32px;">
411
  <div class="section-header">
412
+ <span class="section-icon" style="color: var(--accent-primary);">📈</span>
413
  <h3 style="margin: 0; color: var(--text-primary); font-size: 1.5rem; font-family: 'Inter', sans-serif; font-weight: 700;">
414
+ PII Detection Performance Leaderboard
415
  </h3>
416
  </div>
417
  <p style="color: var(--text-secondary); margin-bottom: 20px; font-size: 1.1rem; font-family: 'Inter', sans-serif;">
418
+ Filter by document type, model access, and sort by any metric to explore performance
419
  </p>
420
+
421
+ <!-- Document Type Filter -->
422
+ <div style="margin-bottom: 24px;">
423
+ <h4 style="color: var(--text-primary); margin-bottom: 12px; font-size: 1rem;">📄 Document Type</h4>
424
  """)
425
 
426
+ document_type_filter = gr.Radio(
427
+ choices=["All", "Healthcare", "Financial", "Government", "Legal", "Personal"],
428
+ value="All",
429
+ label="",
430
+ interactive=True,
431
+ elem_classes=["document-type-radio"]
432
+ )
 
 
 
433
 
 
434
  gr.HTML("""
435
+ </div>
436
+
437
+ <!-- Other Filters -->
438
+ <div style="margin-bottom: 24px;">
439
+ <h4 style="color: var(--text-primary); margin-bottom: 12px; font-size: 1rem;">🔍 Filters & Sorting</h4>
 
440
  </div>
441
  """)
442
 
 
465
  elem_classes=["compact-radio"]
466
  )
467
 
 
 
 
468
  gr.HTML("""
469
+ <!-- Leaderboard Table -->
470
+ <div style="margin-top: 24px;">
471
+ <div class="dataframe-container">
 
 
 
 
 
472
  """)
473
 
474
  leaderboard_table = gr.HTML(initial_table)
475
 
476
  gr.HTML("""
477
+ </div>
478
  </div>
479
  </div>""")
480
 
481
+ # Methodology section
482
+ gr.HTML(f"""
483
+ <div class="dark-container" style="margin-top: 32px;">
484
+ {METHODOLOGY}
485
+ </div>
486
+ """)
487
+
488
  # Performance Card Section
489
  gr.HTML("""
490
  <div class="dark-container" style="margin-top: 32px;">
491
  <div class="section-header">
492
  <span class="section-icon" style="color: var(--accent-primary);">🎯</span>
493
  <h3 style="margin: 0; color: var(--text-primary); font-size: 1.5rem; font-family: 'Inter', sans-serif; font-weight: 700;">
494
+ Model Performance Cards
495
  </h3>
496
  </div>
497
+ <p style="color: var(--text-secondary); margin-bottom: 20px; font-size: 1.1rem; font-family: 'Inter', sans-serif; text-align: center;">
498
+ Dive deep into individual model performance across all metrics and document types
499
  </p>
500
+
 
 
 
 
501
  """)
502
 
503
  card_model_selector = gr.Dropdown(
 
512
  </div>
513
  </div>
514
 
515
+ <div style="width: 100%;">
516
  """)
517
 
518
  # Card display area
 
520
  initial_card_html = generate_performance_card(initial_model) if initial_model else ""
521
  card_display = gr.HTML(value=initial_card_html, elem_id="performance-card-html")
522
 
 
 
 
 
 
 
 
 
 
 
 
 
523
  gr.HTML("""
 
524
  </div>
525
  </div>
526
  </div>""")
 
709
  min-width: auto !important;
710
  max-width: 120px !important;
711
  }}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
712
  </style>
713
  """)
714
 
 
735
  inputs=[card_model_selector],
736
  outputs=[card_display]
737
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
738
 
739
  def create_app():
740
  """Create the main Gradio application"""