Dyuti Dasmahapatra commited on
Commit
9bf5c2d
Β·
1 Parent(s): 816d43f

Validate tab functionality and resolve tab-related errors

Browse files
Files changed (1) hide show
  1. app.py +144 -17
app.py CHANGED
@@ -337,7 +337,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="ViT Auditing Toolk
337
  border: 1px solid rgba(99, 102, 241, 0.15);
338
  ">
339
  <h2 style="font-size: 1.75rem; font-weight: 700; color: #e0e7ff; margin-bottom: 1rem;">
340
- πŸ› οΈ About This Toolkit
341
  </h2>
342
 
343
  <p style="color: #94a3b8; line-height: 1.8; font-size: 1.05rem; margin-bottom: 1.5rem;">
@@ -383,6 +383,122 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="ViT Auditing Toolk
383
  """
384
  )
385
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
386
  # Model selection (shared across all tabs)
387
  with gr.Row():
388
  with gr.Column(scale=3):
@@ -393,16 +509,16 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="ViT Auditing Toolk
393
  info="Choose which Vision Transformer model to use"
394
  )
395
 
396
- with gr.Column(scale=1):
 
 
 
 
 
 
 
397
  load_btn = gr.Button("πŸ”„ Load Model", variant="primary", size="lg")
398
 
399
- with gr.Row():
400
- model_status = gr.Textbox(
401
- label="πŸ“‘ Model Status",
402
- interactive=False,
403
- placeholder="Select a model and click 'Load Model' to begin..."
404
- )
405
-
406
  load_btn.click(
407
  fn=lambda model: load_selected_model(SUPPORTED_MODELS[model]),
408
  inputs=[model_choice],
@@ -446,19 +562,23 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="ViT Auditing Toolk
446
  layer_index = gr.Slider(
447
  minimum=0, maximum=11, value=6, step=1,
448
  label="Layer Index",
449
- info="Which transformer layer to visualize"
450
  )
 
 
451
  head_index = gr.Slider(
452
  minimum=0, maximum=11, value=0, step=1,
453
  label="Head Index",
454
- info="Which attention head to visualize"
455
  )
456
 
457
  analyze_btn = gr.Button("πŸš€ Analyze Image", variant="primary", size="lg")
458
  status_output = gr.Textbox(
459
  label="πŸ“Š Analysis Status",
460
  interactive=False,
461
- placeholder="Upload an image and click 'Analyze Image' to start..."
 
 
462
  )
463
 
464
  with gr.Column(scale=2):
@@ -505,8 +625,9 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="ViT Auditing Toolk
505
  patch_size = gr.Slider(
506
  minimum=16, maximum=64, value=32, step=16,
507
  label="πŸ”² Patch Size",
508
- info="Size of perturbation patches (larger = fewer patches)"
509
  )
 
510
  perturbation_type = gr.Dropdown(
511
  choices=["blur", "blackout", "gray", "noise"],
512
  value="blur",
@@ -526,7 +647,9 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="ViT Auditing Toolk
526
  cf_status_output = gr.Textbox(
527
  label="πŸ“Š Analysis Status",
528
  interactive=False,
529
- placeholder="Upload an image and click to start counterfactual analysis..."
 
 
530
  )
531
 
532
  with gr.Column(scale=2):
@@ -574,7 +697,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="ViT Auditing Toolk
574
  n_bins = gr.Slider(
575
  minimum=5, maximum=20, value=10, step=1,
576
  label="πŸ“Š Number of Bins",
577
- info="Granularity of calibration analysis"
578
  )
579
 
580
  gr.Markdown("""
@@ -588,7 +711,9 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="ViT Auditing Toolk
588
  cal_status_output = gr.Textbox(
589
  label="πŸ“Š Analysis Status",
590
  interactive=False,
591
- placeholder="Upload an image and click to analyze calibration..."
 
 
592
  )
593
 
594
  with gr.Column(scale=2):
@@ -644,7 +769,9 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="ViT Auditing Toolk
644
  bias_status_output = gr.Textbox(
645
  label="πŸ“Š Analysis Status",
646
  interactive=False,
647
- placeholder="Upload an image and click to detect potential biases..."
 
 
648
  )
649
 
650
  with gr.Column(scale=2):
 
337
  border: 1px solid rgba(99, 102, 241, 0.15);
338
  ">
339
  <h2 style="font-size: 1.75rem; font-weight: 700; color: #e0e7ff; margin-bottom: 1rem;">
340
+ �️ About This Toolkit
341
  </h2>
342
 
343
  <p style="color: #94a3b8; line-height: 1.8; font-size: 1.05rem; margin-bottom: 1.5rem;">
 
383
  """
384
  )
385
 
386
+ # Quick Start Guide
387
+ gr.HTML(
388
+ """
389
+ <div style="
390
+ background: rgba(99, 102, 241, 0.1);
391
+ border-radius: 16px;
392
+ padding: 2rem;
393
+ margin-bottom: 2rem;
394
+ border: 1px solid rgba(99, 102, 241, 0.25);
395
+ ">
396
+ <h2 style="font-size: 1.5rem; font-weight: 700; color: #e0e7ff; margin-bottom: 1.5rem;">
397
+ πŸš€ Quick Start Guide
398
+ </h2>
399
+
400
+ <div style="display: grid; gap: 1rem;">
401
+ <div style="display: flex; align-items: start; gap: 1rem;">
402
+ <div style="
403
+ background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
404
+ border-radius: 50%;
405
+ width: 32px;
406
+ height: 32px;
407
+ display: flex;
408
+ align-items: center;
409
+ justify-content: center;
410
+ font-weight: 700;
411
+ color: white;
412
+ flex-shrink: 0;
413
+ ">1</div>
414
+ <div>
415
+ <strong style="color: #c4b5fd; font-size: 1.05rem;">Select a Model</strong>
416
+ <p style="color: #94a3b8; margin-top: 0.25rem; line-height: 1.6;">
417
+ Choose a Vision Transformer model from the dropdown and click "Load Model" button
418
+ </p>
419
+ </div>
420
+ </div>
421
+
422
+ <div style="display: flex; align-items: start; gap: 1rem;">
423
+ <div style="
424
+ background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
425
+ border-radius: 50%;
426
+ width: 32px;
427
+ height: 32px;
428
+ display: flex;
429
+ align-items: center;
430
+ justify-content: center;
431
+ font-weight: 700;
432
+ color: white;
433
+ flex-shrink: 0;
434
+ ">2</div>
435
+ <div>
436
+ <strong style="color: #c4b5fd; font-size: 1.05rem;">Upload Your Image</strong>
437
+ <p style="color: #94a3b8; margin-top: 0.25rem; line-height: 1.6;">
438
+ Navigate to any tab and upload an image you want to analyze
439
+ </p>
440
+ </div>
441
+ </div>
442
+
443
+ <div style="display: flex; align-items: start; gap: 1rem;">
444
+ <div style="
445
+ background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
446
+ border-radius: 50%;
447
+ width: 32px;
448
+ height: 32px;
449
+ display: flex;
450
+ align-items: center;
451
+ justify-content: center;
452
+ font-weight: 700;
453
+ color: white;
454
+ flex-shrink: 0;
455
+ ">3</div>
456
+ <div>
457
+ <strong style="color: #c4b5fd; font-size: 1.05rem;">Choose Analysis Type</strong>
458
+ <p style="color: #94a3b8; margin-top: 0.25rem; line-height: 1.6;">
459
+ Select from 4 tabs: Basic Explainability, Counterfactual Analysis, Confidence Calibration, or Bias Detection
460
+ </p>
461
+ </div>
462
+ </div>
463
+
464
+ <div style="display: flex; align-items: start; gap: 1rem;">
465
+ <div style="
466
+ background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
467
+ border-radius: 50%;
468
+ width: 32px;
469
+ height: 32px;
470
+ display: flex;
471
+ align-items: center;
472
+ justify-content: center;
473
+ font-weight: 700;
474
+ color: white;
475
+ flex-shrink: 0;
476
+ ">4</div>
477
+ <div>
478
+ <strong style="color: #c4b5fd; font-size: 1.05rem;">Run Analysis</strong>
479
+ <p style="color: #94a3b8; margin-top: 0.25rem; line-height: 1.6;">
480
+ Adjust settings if needed, then click the analysis button to see results and visualizations
481
+ </p>
482
+ </div>
483
+ </div>
484
+ </div>
485
+
486
+ <div style="
487
+ margin-top: 1.5rem;
488
+ padding: 1rem;
489
+ background: rgba(139, 92, 246, 0.1);
490
+ border-radius: 12px;
491
+ border-left: 4px solid #8b5cf6;
492
+ ">
493
+ <p style="color: #c4b5fd; margin: 0; font-size: 0.95rem;">
494
+ πŸ’‘ <strong>Tip:</strong> Start with "Basic Explainability" to understand what your model sees,
495
+ then explore advanced auditing features in other tabs.
496
+ </p>
497
+ </div>
498
+ </div>
499
+ """
500
+ )
501
+
502
  # Model selection (shared across all tabs)
503
  with gr.Row():
504
  with gr.Column(scale=3):
 
509
  info="Choose which Vision Transformer model to use"
510
  )
511
 
512
+ with gr.Column(scale=3):
513
+ model_status = gr.Textbox(
514
+ label="πŸ“‘ Model Status",
515
+ interactive=False,
516
+ placeholder="Select a model and click 'Load Model' to begin..."
517
+ )
518
+
519
+ with gr.Column(scale=2):
520
  load_btn = gr.Button("πŸ”„ Load Model", variant="primary", size="lg")
521
 
 
 
 
 
 
 
 
522
  load_btn.click(
523
  fn=lambda model: load_selected_model(SUPPORTED_MODELS[model]),
524
  inputs=[model_choice],
 
562
  layer_index = gr.Slider(
563
  minimum=0, maximum=11, value=6, step=1,
564
  label="Layer Index",
565
+ info="Which transformer layer to visualize (0-11)"
566
  )
567
+
568
+ with gr.Row():
569
  head_index = gr.Slider(
570
  minimum=0, maximum=11, value=0, step=1,
571
  label="Head Index",
572
+ info="Which attention head to visualize (0-11)"
573
  )
574
 
575
  analyze_btn = gr.Button("πŸš€ Analyze Image", variant="primary", size="lg")
576
  status_output = gr.Textbox(
577
  label="πŸ“Š Analysis Status",
578
  interactive=False,
579
+ placeholder="Upload an image and click 'Analyze Image' to start...",
580
+ lines=4,
581
+ max_lines=6
582
  )
583
 
584
  with gr.Column(scale=2):
 
625
  patch_size = gr.Slider(
626
  minimum=16, maximum=64, value=32, step=16,
627
  label="πŸ”² Patch Size",
628
+ info="Size of perturbation patches - 16, 32, 48, or 64 pixels"
629
  )
630
+
631
  perturbation_type = gr.Dropdown(
632
  choices=["blur", "blackout", "gray", "noise"],
633
  value="blur",
 
647
  cf_status_output = gr.Textbox(
648
  label="πŸ“Š Analysis Status",
649
  interactive=False,
650
+ placeholder="Upload an image and click to start counterfactual analysis...",
651
+ lines=5,
652
+ max_lines=8
653
  )
654
 
655
  with gr.Column(scale=2):
 
697
  n_bins = gr.Slider(
698
  minimum=5, maximum=20, value=10, step=1,
699
  label="πŸ“Š Number of Bins",
700
+ info="Granularity of calibration analysis (5-20)"
701
  )
702
 
703
  gr.Markdown("""
 
711
  cal_status_output = gr.Textbox(
712
  label="πŸ“Š Analysis Status",
713
  interactive=False,
714
+ placeholder="Upload an image and click to analyze calibration...",
715
+ lines=5,
716
+ max_lines=8
717
  )
718
 
719
  with gr.Column(scale=2):
 
769
  bias_status_output = gr.Textbox(
770
  label="πŸ“Š Analysis Status",
771
  interactive=False,
772
+ placeholder="Upload an image and click to detect potential biases...",
773
+ lines=6,
774
+ max_lines=10
775
  )
776
 
777
  with gr.Column(scale=2):