ACA050 commited on
Commit
b4a190b
·
verified ·
1 Parent(s): af6a4b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +98 -1661
app.py CHANGED
@@ -1,1661 +1,98 @@
1
- """
2
- AegisLM Dashboard Application
3
-
4
- Governance-grade analytics interface for evaluation results,
5
- benchmark comparisons, and model robustness visualization.
6
-
7
- Built with Gradio and Plotly.
8
- """
9
-
10
- import logging
11
- from typing import Any, Dict, List, Optional
12
-
13
- import gradio as gr
14
-
15
- from dashboard.components.attack_breakdown import (
16
- ATTACK_BREAKDOWN_HEADERS,
17
- create_attack_breakdown_table,
18
- create_attack_selector,
19
- format_breakdown_tooltip,
20
- get_attack_breakdown_details,
21
- get_breakdown_tooltip_explanation,
22
- get_small_sample_warning,
23
- log_attack_breakdown_view,
24
- update_attack_breakdown_table,
25
- update_attack_selector,
26
- )
27
- from dashboard.components.comparison_table import (
28
- create_comparison_table,
29
- update_comparison_table,
30
- update_delta_chart,
31
- )
32
- from dashboard.components.delta_bar_chart import (
33
- create_delta_bar_chart,
34
- create_empty_delta_chart,
35
- update_delta_bar_chart,
36
- )
37
- from dashboard.components.heatmap import create_heatmap_chart, update_heatmap_chart
38
- from dashboard.components.metrics_panel import (
39
- create_metrics_panel,
40
- update_metrics_panel,
41
- update_stat_display,
42
- )
43
- from dashboard.components.radar_chart import create_radar_chart, update_radar_chart
44
- from dashboard.components.ranking_table import (
45
- RANKING_HEADERS,
46
- create_ranking_table,
47
- update_ranking_table,
48
- )
49
- from dashboard.components.report_export import (
50
- create_export_panel,
51
- handle_export,
52
- get_export_info,
53
- )
54
- from dashboard.components.run_selector import create_run_selector
55
- from dashboard.components.stability_scatter import (
56
- create_stability_scatter,
57
- create_empty_stability_chart,
58
- update_stability_scatter,
59
- )
60
- from dashboard.components.monitoring_trends import (
61
- create_robustness_trend_chart,
62
- create_hallucination_trend_chart,
63
- create_toxicity_trend_chart,
64
- create_confidence_trend_chart,
65
- create_all_trends_chart,
66
- create_empty_trend_chart,
67
- update_robustness_trend,
68
- update_hallucination_trend,
69
- update_toxicity_trend,
70
- update_confidence_trend,
71
- get_sample_trend_data,
72
- )
73
- from dashboard.components.alert_panel import (
74
- format_alert_for_table,
75
- create_alert_summary_card,
76
- )
77
- from dashboard.data_loader import DashboardDataLoader
78
- from dashboard.schemas import (
79
- BenchmarkComparisonData,
80
- BenchmarkStats,
81
- ComparisonData,
82
- DeltaRobustnessData,
83
- RunSummary,
84
- )
85
- from dashboard.utils import (
86
- format_score,
87
- get_sample_heatmap_data,
88
- get_sample_radar_data,
89
- get_sample_run_summary,
90
- log_dashboard_event,
91
- )
92
-
93
- logger = logging.getLogger(__name__)
94
-
95
-
96
- # =============================================================================
97
- # Dashboard Application
98
- # =============================================================================
99
-
100
-
101
- class AegisLMDashboard:
102
- """
103
- AegisLM Dashboard Application.
104
-
105
- Main Gradio interface for governance-grade analytics.
106
- """
107
-
108
- def __init__(self, data_loader: Optional[DashboardDataLoader] = None):
109
- """
110
- Initialize dashboard.
111
-
112
- Args:
113
- data_loader: Optional data loader instance
114
- """
115
- self._data_loader = data_loader or DashboardDataLoader()
116
- self._current_run_id: Optional[str] = None
117
- self._current_summary: Optional[RunSummary] = None
118
-
119
- def load_run_data(self, run_id: str) -> Dict[str, Any]:
120
- """
121
- Load all data for a run.
122
-
123
- Args:
124
- run_id: Run ID to load
125
-
126
- Returns:
127
- Dictionary with all visualization data
128
- """
129
- self._current_run_id = run_id
130
-
131
- # Get run summary
132
- run_summary = self._data_loader.get_run_summary(run_id)
133
- self._current_summary = run_summary
134
-
135
- # Get radar data
136
- radar_data = self._data_loader.get_radar_data(run_id)
137
-
138
- # Get heatmap data
139
- heatmap_data = self._data_loader.get_attack_heatmap(run_id)
140
-
141
- # Get attack breakdown data
142
- attack_breakdown = self._data_loader.get_attack_breakdown(run_id)
143
-
144
- return {
145
- "run_summary": run_summary,
146
- "radar_data": radar_data,
147
- "heatmap_data": heatmap_data,
148
- "attack_breakdown": attack_breakdown,
149
- }
150
-
151
- def get_comparison_data(
152
- self,
153
- run_ids: List[str],
154
- ) -> tuple[ComparisonData, List[DeltaRobustnessData]]:
155
- """
156
- Get comparison data for multiple runs.
157
-
158
- Args:
159
- run_ids: List of run IDs to compare
160
-
161
- Returns:
162
- Tuple of (comparison_data, delta_data)
163
- """
164
- comparison_data = self._data_loader.get_model_comparison(run_ids)
165
- delta_data = self._data_loader.get_delta_robustness(run_ids)
166
-
167
- return comparison_data, delta_data
168
-
169
-
170
- def create_dashboard(
171
- data_loader: Optional[DashboardDataLoader] = None,
172
- demo_mode: bool = False,
173
- ) -> gr.Blocks:
174
- """
175
- Create the Gradio dashboard interface.
176
-
177
- Args:
178
- data_loader: Optional data loader instance
179
- demo_mode: Enable demo mode with sample data
180
-
181
- Returns:
182
- Gradio Blocks interface
183
- """
184
- # Initialize dashboard
185
- dashboard = AegisLMDashboard(data_loader or DashboardDataLoader(demo_mode=demo_mode))
186
-
187
- # =============================================================================
188
- # UI Layout
189
- # =============================================================================
190
-
191
- with gr.Blocks(
192
- title="AegisLM Dashboard",
193
- theme=gr.themes.Soft(),
194
- ) as app:
195
-
196
- # Header
197
- gr.Markdown("""
198
- # 🛡️ AegisLM Dashboard
199
-
200
- **Governance-Grade Analytics Interface**
201
-
202
- Multi-Agent Adversarial LLM Evaluation Framework
203
-
204
- ---
205
- """)
206
-
207
- # =============================================================================
208
- # Tab 1: Evaluation Runs
209
- # =============================================================================
210
-
211
- with gr.Tab("Evaluation Runs"):
212
- gr.Markdown("### Select and analyze evaluation runs")
213
-
214
- # Run selector
215
- with gr.Row():
216
- run_dropdown = gr.Dropdown(
217
- label="Select Evaluation Run",
218
- choices=[],
219
- interactive=True,
220
- allow_custom_value=True,
221
- )
222
- refresh_btn = gr.Button("🔄 Refresh", variant="secondary")
223
-
224
- # Run details
225
- with gr.Row():
226
- with gr.Column(scale=2):
227
- # Radar chart
228
- radar_plot = gr.Plot(label="Composite Robustness Radar")
229
- with gr.Column(scale=1):
230
- # Quick stats
231
- composite_score = gr.Number(label="Composite Score", interactive=False)
232
- vulnerability_index = gr.Number(label="Vulnerability Index", interactive=False)
233
- sample_count = gr.Number(label="Total Samples", interactive=False)
234
-
235
- # Heatmap
236
- with gr.Row():
237
- heatmap_plot = gr.Plot(label="Attack Vulnerability Heatmap")
238
-
239
- # Attack Breakdown Section
240
- gr.Markdown("### Per-Attack Metric Breakdown")
241
-
242
- with gr.Row():
243
- # Attack type selector dropdown
244
- attack_selector = gr.Dropdown(
245
- label="Select Attack Type",
246
- choices=[],
247
- interactive=True,
248
- allow_custom_value=True,
249
- )
250
-
251
- # Attack breakdown table
252
- with gr.Row():
253
- attack_breakdown_table = gr.Dataframe(
254
- headers=ATTACK_BREAKDOWN_HEADERS,
255
- label="Attack Breakdown Details",
256
- interactive=False,
257
- )
258
-
259
- # Metrics table
260
- with gr.Row():
261
- metrics_table = gr.DataFrame(
262
- headers=["Metric", "Mean", "Std Dev", "Min", "Max", "Count"],
263
- label="Metric Summary",
264
- interactive=False,
265
- )
266
-
267
- # =============================================================================
268
- # Tab 2: Benchmark Comparison
269
- # =============================================================================
270
-
271
- with gr.Tab("Benchmark Comparison"):
272
- gr.Markdown("### Cross-Model Benchmark Comparison")
273
-
274
- # Benchmark selector
275
- with gr.Row():
276
- benchmark_dropdown = gr.Dropdown(
277
- label="Select Benchmark",
278
- choices=[],
279
- interactive=True,
280
- allow_custom_value=True,
281
- )
282
- refresh_benchmarks_btn = gr.Button("🔄 Refresh", variant="secondary")
283
-
284
- # Charts row
285
- with gr.Row():
286
- with gr.Column(scale=1):
287
- # Delta bar chart
288
- delta_plot = gr.Plot(label="Delta Robustness (ΔR)")
289
- with gr.Column(scale=1):
290
- # Stability scatter plot
291
- stability_plot = gr.Plot(label="Robustness Stability")
292
-
293
- # Ranking table
294
- gr.Markdown("### Model Rankings")
295
- with gr.Row():
296
- ranking_table = gr.Dataframe(
297
- headers=RANKING_HEADERS,
298
- label="Model Rankings (Sorted by R_adv, then VI)",
299
- interactive=False,
300
- )
301
-
302
- # Statistical summary
303
- gr.Markdown("### Statistical Summary")
304
- with gr.Row():
305
- with gr.Column():
306
- mean_baseline = gr.Number(label="Mean R_base", interactive=False)
307
- mean_adversarial = gr.Number(label="Mean R_adv", interactive=False)
308
- mean_delta = gr.Number(label="Mean ΔR", interactive=False)
309
- with gr.Column():
310
- std_baseline = gr.Number(label="Std R_base", interactive=False)
311
- best_model = gr.Textbox(label="Best Model", interactive=False)
312
- most_stable = gr.Textbox(label="Most Stable", interactive=False)
313
- with gr.Column():
314
- mean_rsi = gr.Number(label="Mean RSI", interactive=False)
315
- most_vulnerable = gr.Textbox(label="Most Vulnerable", interactive=False)
316
- total_models = gr.Number(label="Total Models", interactive=False)
317
-
318
- # Formula explanation
319
- with gr.Accordion("Formulas", open=False):
320
- gr.Markdown("""
321
- **Delta Robustness**: ΔR = R_base - R_adv
322
-
323
- **RSI (Robustness Stability Index)**: RSI = R_adv / R_base
324
- - Closer to 1 = more stable
325
-
326
- **VI (Vulnerability Index)**: VI = ΔR / R_base
327
- - Higher = more fragile
328
-
329
- **Ranking**: Primary by R_adv (descending), Secondary by VI (ascending)
330
- """)
331
-
332
- # Legacy comparison section (for run-based comparison)
333
- gr.Markdown("---")
334
- gr.Markdown("### Run-Based Comparison (Legacy)")
335
- with gr.Row():
336
- model_multiselect = gr.Dropdown(
337
- label="Select Models to Compare",
338
- choices=[],
339
- interactive=True,
340
- multiselect=True,
341
- allow_custom_value=True,
342
- )
343
- compare_btn = gr.Button("Compare", variant="primary")
344
- refresh_models_btn = gr.Button("🔄 Refresh", variant="secondary")
345
-
346
- # Legacy comparison table
347
- with gr.Row():
348
- comparison_table = gr.DataFrame(
349
- headers=["Model", "Hallucination", "Toxicity", "Bias", "Confidence", "Composite Score", "Sample Count"],
350
- label="Model Comparison",
351
- interactive=False,
352
- )
353
-
354
- # =============================================================================
355
- # Tab 3: Model Ranking
356
- # =============================================================================
357
-
358
- with gr.Tab("Model Ranking"):
359
- gr.Markdown("### Model rankings by robustness")
360
-
361
- # Ranking table
362
- with gr.Row():
363
- ranking_table = gr.DataFrame(
364
- headers=["Rank", "Model", "Composite Score", "Delta"],
365
- label="Model Rankings",
366
- interactive=False,
367
- )
368
-
369
- # Info
370
- gr.Markdown("""
371
- **Formula**: R = w₁(1-H) + w₂(1-T) + w₃(1-B) + w₄*C
372
-
373
- Where:
374
- - H = Hallucination score
375
- - T = Toxicity score
376
- - B = Bias score
377
- - C = Confidence score
378
- - Weights: w₁ = w₂ = w₃ = w₄ = 0.25
379
- """)
380
-
381
- # =============================================================================
382
- # Tab 4: Export Reports
383
- # =============================================================================
384
-
385
- with gr.Tab("Export Reports"):
386
- gr.Markdown("### Export evaluation reports")
387
-
388
- # Export options
389
- with gr.Row():
390
- with gr.Column():
391
- export_format = gr.Dropdown(
392
- label="Export Format",
393
- choices=["json", "csv"],
394
- value="json",
395
- interactive=True,
396
- )
397
- with gr.Column():
398
- include_config = gr.Checkbox(
399
- label="Include Configuration",
400
- value=True,
401
- interactive=True,
402
- )
403
-
404
- # Export button
405
- export_btn = gr.Button("Export Report", variant="primary")
406
-
407
- # Export output
408
- export_output = gr.JSON(label="Export Output")
409
-
410
- # Export info
411
- with gr.Accordion("Export Information", open=False):
412
- gr.Markdown(get_export_info())
413
-
414
- # =============================================================================
415
- # Tab 5: Monitoring (Week 5 - Continuous Monitoring Mode)
416
- # =============================================================================
417
-
418
- with gr.Tab("Monitoring"):
419
- gr.Markdown("""
420
- # 🖥️ Continuous Monitoring Mode
421
-
422
- **Real-time AI Governance Infrastructure**
423
-
424
- Monitor model behavior in production with:
425
- - Real-time evaluation
426
- - Streaming risk scoring
427
- - Drift detection
428
- - Longitudinal robustness tracking
429
-
430
- ---
431
- """)
432
-
433
- # Monitoring status
434
- with gr.Row():
435
- with gr.Column():
436
- monitoring_status = gr.Textbox(
437
- label="Monitoring Status",
438
- value="Active",
439
- interactive=False,
440
- )
441
- with gr.Column():
442
- samples_processed = gr.Number(
443
- label="Samples Processed",
444
- value=0,
445
- interactive=False,
446
- )
447
-
448
- # Rolling metrics
449
- gr.Markdown("### Rolling Metrics (Last 100 samples)")
450
-
451
- with gr.Row():
452
- with gr.Column():
453
- rolling_hallucination = gr.Number(
454
- label="Hallucination (Rolling Avg)",
455
- value=0.0,
456
- interactive=False,
457
- )
458
- with gr.Column():
459
- rolling_toxicity = gr.Number(
460
- label="Toxicity (Rolling Avg)",
461
- value=0.0,
462
- interactive=False,
463
- )
464
- with gr.Column():
465
- rolling_bias = gr.Number(
466
- label="Bias (Rolling Avg)",
467
- value=0.0,
468
- interactive=False,
469
- )
470
-
471
- with gr.Row():
472
- with gr.Column():
473
- rolling_confidence = gr.Number(
474
- label="Confidence (Rolling Avg)",
475
- value=0.0,
476
- interactive=False,
477
- )
478
- with gr.Column():
479
- rolling_robustness = gr.Number(
480
- label="Robustness (Rolling Avg)",
481
- value=0.0,
482
- interactive=False,
483
- )
484
-
485
- # Monitoring Trend Charts
486
- gr.Markdown("### Real-Time Trends")
487
-
488
- with gr.Row():
489
- with gr.Column():
490
- robustness_trend_plot = gr.Plot(label="Robustness Trend")
491
- with gr.Column():
492
- hallucination_trend_plot = gr.Plot(label="Hallucination Trend")
493
-
494
- with gr.Row():
495
- with gr.Column():
496
- toxicity_trend_plot = gr.Plot(label="Toxicity Trend")
497
- with gr.Column():
498
- confidence_trend_plot = gr.Plot(label="Confidence Trend")
499
-
500
- # Drift status
501
- gr.Markdown("### Drift Detection Status")
502
-
503
- with gr.Row():
504
- hallucination_drift = gr.Textbox(
505
- label="Hallucination Drift",
506
- value="No drift",
507
- interactive=False,
508
- )
509
- toxicity_drift = gr.Textbox(
510
- label="Toxicity Drift",
511
- value="No drift",
512
- interactive=False,
513
- )
514
- bias_drift = gr.Textbox(
515
- label="Bias Drift",
516
- value="No drift",
517
- interactive=False,
518
- )
519
-
520
- with gr.Row():
521
- confidence_drift = gr.Textbox(
522
- label="Confidence Collapse",
523
- value="No drift",
524
- interactive=False,
525
- )
526
- robustness_drift = gr.Textbox(
527
- label="Robustness Collapse",
528
- value="No drift",
529
- interactive=False,
530
- )
531
-
532
- # Alerts panel
533
- gr.Markdown("### Active Alerts")
534
-
535
- with gr.Row():
536
- alert_critical = gr.Number(
537
- label="Critical",
538
- value=0,
539
- interactive=False,
540
- )
541
- alert_high = gr.Number(
542
- label="High",
543
- value=0,
544
- interactive=False,
545
- )
546
- alert_medium = gr.Number(
547
- label="Medium",
548
- value=0,
549
- interactive=False,
550
- )
551
- alert_low = gr.Number(
552
- label="Low",
553
- value=0,
554
- interactive=False,
555
- )
556
-
557
- # Recent alerts table
558
- gr.Markdown("### Recent Alerts")
559
- with gr.Row():
560
- alerts_table = gr.Dataframe(
561
- headers=["Type", "Severity", "Metric", "Baseline", "Current", "Drift", "Timestamp"],
562
- label="Recent Alerts",
563
- interactive=False,
564
- )
565
-
566
- # Refresh button
567
- refresh_monitoring_btn = gr.Button("🔄 Refresh Monitoring", variant="secondary")
568
-
569
- # Mathematical formulas
570
- with gr.Accordion("Formulas", open=False):
571
- gr.Markdown("""
572
- **Rolling Average**:
573
- \\bar{H}_t = \\frac{1}{W} \\sum_{i=t-W}^{t} H_i
574
-
575
- **Drift Magnitude**:
576
- Drift(H) = |\\bar{H}_{live} - \\bar{H}_{baseline}|
577
-
578
- **Alert Condition**:
579
- Drift(metric) > threshold
580
-
581
- **Robustness**:
582
- R = w₁(1-H) + w₂(1-T) + w₃(1-B) + w₄*C
583
- """)
584
-
585
- # =============================================================================
586
- # Tab 6: Governance (Week 7)
587
- # =============================================================================
588
-
589
- with gr.Tab("Governance"):
590
- gr.Markdown("""
591
- # ⚖️ Governance Controls
592
-
593
- **Policy Management & Threshold Controls**
594
-
595
- ---
596
- """)
597
-
598
- with gr.Row():
599
- with gr.Column():
600
- gr.Markdown("### Current Thresholds")
601
- threshold_hallucination = gr.Number(
602
- label="Hallucination Threshold",
603
- value=0.15,
604
- interactive=True,
605
- )
606
- threshold_toxicity = gr.Number(
607
- label="Toxicity Threshold",
608
- value=0.10,
609
- interactive=True,
610
- )
611
- with gr.Column():
612
- gr.Markdown("### Policy Status")
613
- policy_version = gr.Textbox(
614
- label="Policy Version",
615
- value="v1.0.0",
616
- interactive=False,
617
- )
618
- policy_status = gr.Textbox(
619
- label="Policy Status",
620
- value="Active",
621
- interactive=False,
622
- )
623
-
624
- gr.Markdown("### Governance Audit Log")
625
- audit_log = gr.Dataframe(
626
- headers=["Timestamp", "Action", "User", "Details", "Hash"],
627
- label="Audit Log",
628
- interactive=False,
629
- )
630
-
631
- gr.Markdown("### Threshold Change History")
632
- threshold_history = gr.Dataframe(
633
- headers=["Timestamp", "Old Value", "New Value", "Approved By"],
634
- label="Threshold Changes",
635
- interactive=False,
636
- )
637
-
638
- gr.Markdown("""
639
- ### Governance Formulas
640
-
641
- **Approval Required**: Threshold changes require admin approval
642
-
643
- **Audit Chain**: Each change is hash-linked to previous
644
- """)
645
-
646
- # =============================================================================
647
- # Tab 7: Certification (Week 8)
648
- # =============================================================================
649
-
650
- with gr.Tab("Certification"):
651
- gr.Markdown("""
652
- # 🏆 GSS Certification
653
-
654
- **Governance Scoring Standard (GSS) Certification**
655
-
656
- ---
657
- """)
658
-
659
- with gr.Row():
660
- with gr.Column():
661
- gr.Markdown("### Certification Levels")
662
- cert_badge = gr.Textbox(
663
- label="Current Badge",
664
- value="GSS-1",
665
- interactive=False,
666
- )
667
- cert_status = gr.Textbox(
668
- label="Status",
669
- value="Certified",
670
- interactive=False,
671
- )
672
- with gr.Column():
673
- gr.Markdown("### Scoring Weights")
674
- weight_h = gr.Number(label="Hallucination (w₁)", value=0.30, interactive=False)
675
- weight_t = gr.Number(label="Toxicity (w₂)", value=0.30, interactive=False)
676
- weight_b = gr.Number(label="Bias (w₃)", value=0.20, interactive=False)
677
- weight_c = gr.Number(label="Confidence (w₄)", value=0.20, interactive=False)
678
-
679
- gr.Markdown("### GSS Formula")
680
- gr.Markdown("""
681
- **Composite Score**: R = w₁(1-H) + w₂(1-T) + w₃(1-B) + w₄×C
682
-
683
- Where weights sum to 1.0
684
- """)
685
-
686
- gr.Markdown("### Certification Criteria")
687
- criteria_table = gr.Dataframe(
688
- headers=["Level", "Min Score", "Max Vulnerability", "Requirements"],
689
- label="Certification Levels",
690
- interactive=False,
691
- )
692
-
693
- gr.Markdown("### Certification History")
694
- cert_history = gr.Dataframe(
695
- headers=["Date", "Model", "Score", "Level", "Valid Until"],
696
- label="Certification History",
697
- interactive=False,
698
- )
699
-
700
- # =============================================================================
701
- # Tab 8: Enterprise (Week 9)
702
- # =============================================================================
703
-
704
- with gr.Tab("Enterprise"):
705
- gr.Markdown("""
706
- # 🏢 Enterprise SaaS
707
-
708
- **Multi-tenant Management & Billing**
709
-
710
- ---
711
- """)
712
-
713
- with gr.Row():
714
- with gr.Column():
715
- gr.Markdown("### Tenant Overview")
716
- tenant_count = gr.Number(
717
- label="Active Tenants",
718
- value=0,
719
- interactive=False,
720
- )
721
- active_users = gr.Number(
722
- label="Active Users",
723
- value=0,
724
- interactive=False,
725
- )
726
- with gr.Column():
727
- gr.Markdown("### Revenue Metrics")
728
- mrr = gr.Number(
729
- label="MRR ($)",
730
- value=0,
731
- interactive=False,
732
- )
733
- arr = gr.Number(
734
- label="ARR ($)",
735
- value=0,
736
- interactive=False,
737
- )
738
-
739
- gr.Markdown("### Subscription Plans")
740
- plan_breakdown = gr.Dataframe(
741
- headers=["Plan", "Tenants", "Price/Month", "Features"],
742
- label="Plan Distribution",
743
- interactive=False,
744
- )
745
-
746
- gr.Markdown("### Usage Metrics")
747
- with gr.Row():
748
- api_calls = gr.Number(label="API Calls (30d)", value=0, interactive=False)
749
- eval_runs = gr.Number(label="Eval Runs (30d)", value=0, interactive=False)
750
- data_processed = gr.Number(label="GB Processed", value=0, interactive=False)
751
-
752
- gr.Markdown("### Feature Flags")
753
- with gr.Row():
754
- ff_drift = gr.Checkbox(label="Drift Detection", value=True, interactive=False)
755
- ff_compliance = gr.Checkbox(label="Compliance Reports", value=True, interactive=False)
756
- ff_federation = gr.Checkbox(label="Federation", value=False, interactive=False)
757
-
758
- # =============================================================================
759
- # Tab 9: Compliance (Week 10)
760
- # =============================================================================
761
-
762
- with gr.Tab("Compliance"):
763
- gr.Markdown("""
764
- # 📋 Compliance
765
-
766
- **SOC2, EU AI Act, & Regulatory Compliance**
767
-
768
- ---
769
- """)
770
-
771
- with gr.Row():
772
- with gr.Column():
773
- gr.Markdown("### Compliance Status")
774
- soc2_status = gr.Textbox(
775
- label="SOC2 Type II",
776
- value="In Progress",
777
- interactive=False,
778
- )
779
- eu_ai_status = gr.Textbox(
780
- label="EU AI Act",
781
- value="Compliant",
782
- interactive=False,
783
- )
784
- with gr.Column():
785
- gr.Markdown("### Audit Status")
786
- last_audit = gr.Textbox(
787
- label="Last Audit",
788
- value="2024-01-15",
789
- interactive=False,
790
- )
791
- next_audit = gr.Textbox(
792
- label="Next Audit",
793
- value="2024-07-15",
794
- interactive=False,
795
- )
796
-
797
- gr.Markdown("### Control Mapping")
798
- control_table = gr.Dataframe(
799
- headers=["Control ID", "Description", "Status", "Evidence"],
800
- label="SOC2 Controls",
801
- interactive=False,
802
- )
803
-
804
- gr.Markdown("### EU AI Act Requirements")
805
- eu_table = gr.Dataframe(
806
- headers=["Requirement", "Category", "Status", "Implementation"],
807
- label="EU AI Act Compliance",
808
- interactive=False,
809
- )
810
-
811
- gr.Markdown("### Evidence Repository")
812
- evidence_btn = gr.Button("📁 View Evidence", variant="secondary")
813
-
814
- with gr.Accordion("Compliance Formulas", open=False):
815
- gr.Markdown("""
816
- **Control Effectiveness**: (Passing Controls / Total Controls) × 100%
817
-
818
- **Risk Score**: Impact × Likelihood
819
- """)
820
-
821
- # =============================================================================
822
- # Tab 10: Ecosystem (Week 11)
823
- # =============================================================================
824
-
825
- with gr.Tab("Ecosystem"):
826
- gr.Markdown("""
827
- # 🌐 Federation & Ecosystem
828
-
829
- **Multi-Authority Certification & Marketplace**
830
-
831
- ---
832
- """)
833
-
834
- with gr.Row():
835
- with gr.Column():
836
- gr.Markdown("### Partner Authorities")
837
- authority_count = gr.Number(
838
- label="Active Authorities",
839
- value=3,
840
- interactive=False,
841
- )
842
- pending_certs = gr.Number(
843
- label="Pending Certifications",
844
- value=0,
845
- interactive=False,
846
- )
847
- with gr.Column():
848
- gr.Markdown("### Marketplace")
849
- plugin_count = gr.Number(
850
- label="Published Plugins",
851
- value=0,
852
- interactive=False,
853
- )
854
- avg_rating = gr.Number(
855
- label="Average Rating",
856
- value=0.0,
857
- interactive=False,
858
- )
859
-
860
- gr.Markdown("### Partner Certification Authorities")
861
- authority_table = gr.Dataframe(
862
- headers=["Authority", "Region", "Certifications", "Status"],
863
- label="Certification Partners",
864
- interactive=False,
865
- )
866
-
867
- gr.Markdown("### Cross-Border Verification")
868
- gr.Markdown("Verify certifications across jurisdictions")
869
-
870
- with gr.Row():
871
- verify_input = gr.Textbox(
872
- label="Certificate ID",
873
- placeholder="Enter certificate ID to verify",
874
- )
875
- verify_btn = gr.Button("🔍 Verify", variant="primary")
876
-
877
- verify_output = gr.JSON(label="Verification Result")
878
-
879
- gr.Markdown("### Plugin Marketplace")
880
- plugin_table = gr.Dataframe(
881
- headers=["Plugin", "Author", "Category", "Rating", "Downloads"],
882
- label="Available Plugins",
883
- interactive=False,
884
- )
885
-
886
- # =============================================================================
887
- # Tab 11: Deployment (Week 12)
888
- # =============================================================================
889
-
890
- with gr.Tab("Deployment"):
891
- gr.Markdown("""
892
- # 🚀 Production Deployment
893
-
894
- **Infrastructure & Operations**
895
-
896
- ---
897
- """)
898
-
899
- with gr.Row():
900
- with gr.Column():
901
- gr.Markdown("### System Status")
902
- uptime = gr.Textbox(
903
- label="Uptime",
904
- value="99.9%",
905
- interactive=False,
906
- )
907
- version = gr.Textbox(
908
- label="Version",
909
- value="1.0.0",
910
- interactive=False,
911
- )
912
- with gr.Column():
913
- gr.Markdown("### Health Metrics")
914
- db_status = gr.Textbox(label="Database", value="Healthy", interactive=False)
915
- redis_status = gr.Textbox(label="Redis", value="Healthy", interactive=False)
916
-
917
- gr.Markdown("### Deployment Checklist")
918
- checklist = gr.Dataframe(
919
- headers=["Check", "Status", "Notes"],
920
- label="Go/No-Go Checklist",
921
- interactive=False,
922
- )
923
-
924
- gr.Markdown("### Recent Deployments")
925
- deploy_history = gr.Dataframe(
926
- headers=["Date", "Version", "Status", "Duration"],
927
- label="Deployment History",
928
- interactive=False,
929
- )
930
-
931
- with gr.Accordion("Production Metrics", open=False):
932
- gr.Markdown("""
933
- - **P99 Latency**: < 200ms
934
- - **Throughput**: > 1000 req/s
935
- - **Error Rate**: < 0.1%
936
- """)
937
-
938
- # =============================================================================
939
- # Footer
940
- # =============================================================================
941
-
942
- gr.Markdown("""
943
- ---
944
-
945
- **AegisLM** - Multi-Agent Adversarial LLM Evaluation Framework
946
-
947
- **12-Week Implementation**: Complete governance-grade AI evaluation system
948
-
949
- Version 1.0.0
950
- """)
951
-
952
- # =============================================================================
953
- # Event Handlers
954
- # =============================================================================
955
-
956
- def load_runs() -> List[str]:
957
- """Load available runs."""
958
- try:
959
- runs = dashboard._data_loader.get_all_runs()
960
- choices = [run["id"] for run in runs]
961
- return choices
962
- except Exception as e:
963
- logger.error(f"Error loading runs: {e}")
964
- return []
965
-
966
- def load_model_names() -> List[str]:
967
- """Load available model names for comparison dropdown."""
968
- try:
969
- runs = dashboard._data_loader.get_all_runs()
970
- # Return unique model names - handle case where model_name might not exist
971
- model_names = set()
972
- for run in runs:
973
- # Try model_name first, fall back to id if not available
974
- model_name = run.get("model_name") or run.get("id", "")
975
- if model_name:
976
- model_names.add(model_name)
977
- return sorted(model_names)
978
- except Exception as e:
979
- logger.error(f"Error loading model names: {e}")
980
- return []
981
-
982
- def on_run_select(run_id):
983
- """Handle run selection."""
984
- # Handle both string and list inputs from Gradio
985
- if isinstance(run_id, list):
986
- if not run_id:
987
- return (
988
- create_empty_radar(),
989
- 0.0, 0.0, 0,
990
- create_empty_heatmap(),
991
- [], # attack_selector choices
992
- [["N/A", "0", "0.000", "0.000", "0.000", "0.000", "0.000", "0.000"]], # attack_breakdown_table
993
- [["N/A", "N/A", "N/A", "N/A", "N/A", "0"]], # metrics_table
994
- )
995
- # Take the first run_id from the list
996
- run_id = run_id[0]
997
-
998
- if not run_id:
999
- return (
1000
- create_empty_radar(),
1001
- 0.0, 0.0, 0,
1002
- create_empty_heatmap(),
1003
- [], # attack_selector choices
1004
- [["N/A", "0", "0.000", "0.000", "0.000", "0.000", "0.000", "0.000"]], # attack_breakdown_table
1005
- [["N/A", "N/A", "N/A", "N/A", "N/A", "0"]], # metrics_table
1006
- )
1007
-
1008
- log_dashboard_event("DASHBOARD_VIEW_RUN", run_id=run_id)
1009
-
1010
- # Load data
1011
- data = dashboard.load_run_data(run_id)
1012
-
1013
- run_summary = data["run_summary"]
1014
- radar_data = data["radar_data"]
1015
- heatmap_data = data["heatmap_data"]
1016
- attack_breakdown = data.get("attack_breakdown")
1017
-
1018
- # Log heatmap view
1019
- if heatmap_data:
1020
- log_dashboard_event("DASHBOARD_VIEW_HEATMAP", run_id=run_id)
1021
-
1022
- # Get updates
1023
- radar_fig = update_radar_chart(radar_data)
1024
- heatmap_fig = update_heatmap_chart(heatmap_data)
1025
-
1026
- # Get stats
1027
- stats = update_stat_display(run_summary)
1028
-
1029
- # Get attack breakdown data
1030
- attack_selector_choices = update_attack_selector(attack_breakdown)
1031
- attack_table_data = update_attack_breakdown_table(attack_breakdown)
1032
-
1033
- # Get metrics table
1034
- table_data, _ = update_metrics_panel(run_summary)
1035
-
1036
- return (
1037
- radar_fig,
1038
- stats[0], stats[1], stats[2],
1039
- heatmap_fig,
1040
- attack_selector_choices,
1041
- attack_table_data,
1042
- table_data,
1043
- )
1044
-
1045
- def on_refresh():
1046
- """Handle refresh button."""
1047
- return load_runs()
1048
-
1049
- def on_compare(model_names: List[str]):
1050
- """Handle compare button - accepts model names and converts to run IDs."""
1051
- if not model_names or len(model_names) < 2:
1052
- return (
1053
- [["N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "0"]],
1054
- create_empty_delta(),
1055
- )
1056
-
1057
- # Map model names to run IDs
1058
- run_ids = []
1059
- for model_name in model_names:
1060
- for run in dashboard._data_loader.get_all_runs():
1061
- if run.get("model_name") == model_name:
1062
- run_ids.append(run["id"])
1063
- break
1064
-
1065
- if len(run_ids) < 2:
1066
- return (
1067
- [["N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "0"]],
1068
- create_empty_delta(),
1069
- )
1070
-
1071
- log_dashboard_event("DASHBOARD_COMPARE_MODELS", extra={"count": len(run_ids)})
1072
-
1073
- comparison_data, delta_data = dashboard.get_comparison_data(run_ids)
1074
-
1075
- table_data = update_comparison_table(comparison_data)
1076
- delta_fig = update_delta_chart(delta_data)
1077
-
1078
- return table_data, delta_fig
1079
-
1080
- def on_refresh_models():
1081
- """Handle refresh models button."""
1082
- return load_model_names()
1083
-
1084
- def on_export(run_id, format: str, include_config: bool):
1085
- """Handle export button."""
1086
- # Handle case where run_id might be a list (from Gradio dropdown)
1087
- if isinstance(run_id, list):
1088
- run_id = run_id[0] if run_id else None
1089
-
1090
- if not run_id:
1091
- return {"error": "No run selected", "content": ""}
1092
-
1093
- summary = dashboard._data_loader.get_run_summary(run_id)
1094
-
1095
- if summary is None:
1096
- return {"error": "Run not found", "content": ""}
1097
-
1098
- result = handle_export(summary, format, include_config)
1099
-
1100
- # Handle tuple return (output, filename)
1101
- if isinstance(result, tuple):
1102
- output, filename = result
1103
- # For CSV format, wrap in a dict that JSON can handle
1104
- if format == "csv":
1105
- return {
1106
- "format": "csv",
1107
- "filename": filename,
1108
- "content": output if output else ""
1109
- }
1110
- return {"content": output, "filename": filename}
1111
- return result
1112
-
1113
- def load_benchmarks() -> List[str]:
1114
- """Load available benchmarks."""
1115
- try:
1116
- benchmarks = dashboard._data_loader.list_benchmarks()
1117
- choices = [b.benchmark_id for b in benchmarks]
1118
- return choices
1119
- except Exception as e:
1120
- logger.error(f"Error loading benchmarks: {e}")
1121
- return []
1122
-
1123
- def on_benchmark_select(benchmark_id):
1124
- """Handle benchmark selection."""
1125
- # Handle both string and list inputs from Gradio
1126
- if isinstance(benchmark_id, list):
1127
- if not benchmark_id:
1128
- return (
1129
- create_empty_delta_chart("Select a benchmark"),
1130
- create_empty_stability_chart("Select a benchmark"),
1131
- [["N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "0"]],
1132
- 0.0, 0.0, 0.0,
1133
- "N/A", "N/A",
1134
- 0.0, "N/A", "N/A", 0,
1135
- )
1136
- # Take the first benchmark_id from the list
1137
- benchmark_id = benchmark_id[0]
1138
-
1139
- if not benchmark_id:
1140
- return (
1141
- create_empty_delta_chart("Select a benchmark"),
1142
- create_empty_stability_chart("Select a benchmark"),
1143
- [["N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "0"]],
1144
- 0.0, 0.0, 0.0,
1145
- "N/A", "N/A",
1146
- 0.0, "N/A", "N/A", 0,
1147
- )
1148
-
1149
- log_dashboard_event("DASHBOARD_VIEW_BENCHMARK", extra={"benchmark_id": benchmark_id})
1150
-
1151
- # Load benchmark comparison data
1152
- comparison = dashboard._data_loader.get_benchmark_comparison(benchmark_id)
1153
- stats = dashboard._data_loader.get_benchmark_stats(benchmark_id)
1154
-
1155
- if comparison is None or stats is None:
1156
- return (
1157
- create_empty_delta_chart("Benchmark not found"),
1158
- create_empty_stability_chart("Benchmark not found"),
1159
- [["N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "0"]],
1160
- 0.0, 0.0, 0.0,
1161
- "N/A", "N/A",
1162
- 0.0, "N/A", "N/A", 0,
1163
- )
1164
-
1165
- # Generate charts
1166
- delta_fig = update_delta_bar_chart(comparison)
1167
- stability_fig = update_stability_scatter(comparison)
1168
- ranking_data = update_ranking_table(comparison)
1169
-
1170
- return (
1171
- delta_fig,
1172
- stability_fig,
1173
- ranking_data,
1174
- stats.mean_baseline,
1175
- stats.mean_adversarial,
1176
- stats.mean_delta,
1177
- stats.std_baseline,
1178
- stats.best_model,
1179
- stats.most_stable,
1180
- stats.mean_rsi,
1181
- stats.most_vulnerable,
1182
- stats.total_models,
1183
- )
1184
-
1185
- def on_refresh_benchmarks():
1186
- """Handle refresh benchmarks button."""
1187
- return load_benchmarks()
1188
-
1189
- def on_refresh_monitoring():
1190
- """
1191
- Handle monitoring refresh button.
1192
-
1193
- Loads latest monitoring data and updates all dashboard components.
1194
- """
1195
- try:
1196
- log_dashboard_event("DASHBOARD_REFRESH_MONITORING")
1197
-
1198
- # Get monitoring trends
1199
- trends_data = dashboard._data_loader.get_monitoring_trends(window_size=50)
1200
-
1201
- # Get active alerts
1202
- alerts_data = dashboard._data_loader.get_active_alerts()
1203
-
1204
- # Get drift status
1205
- drift_data = dashboard._data_loader.get_drift_status()
1206
-
1207
- # Get config
1208
- config_data = dashboard._data_loader.get_monitoring_config()
1209
-
1210
- # Extract values for charts
1211
- timestamps = trends_data.get("timestamps", [])
1212
- robustness_values = trends_data.get("robustness", [])
1213
- hallucination_values = trends_data.get("hallucination", [])
1214
- toxicity_values = trends_data.get("toxicity", [])
1215
- confidence_values = trends_data.get("confidence", [])
1216
-
1217
- # Get rolling averages
1218
- rolling_h = trends_data.get("rolling_hallucination", 0.0)
1219
- rolling_t = trends_data.get("rolling_toxicity", 0.0)
1220
- rolling_b = trends_data.get("rolling_bias", 0.0)
1221
- rolling_c = trends_data.get("rolling_confidence", 0.0)
1222
- rolling_r = trends_data.get("rolling_robustness", 0.0)
1223
-
1224
- # Get sample count (from pipeline if available)
1225
- sample_count = 0
1226
- try:
1227
- from backend.monitoring.pipeline import get_monitoring_pipeline
1228
- pipeline = get_monitoring_pipeline()
1229
- sample_count = pipeline.get_sample_count()
1230
- except Exception:
1231
- pass
1232
-
1233
- # Create trend charts
1234
- baseline_r = config_data.get("robustness_threshold", 0.75)
1235
- robustness_fig = create_robustness_trend_chart(
1236
- robustness_values,
1237
- timestamps,
1238
- baseline=baseline_r,
1239
- )
1240
-
1241
- h_threshold = config_data.get("hallucination_threshold", 0.08)
1242
- hallucination_fig = create_hallucination_trend_chart(
1243
- hallucination_values,
1244
- timestamps,
1245
- threshold=h_threshold,
1246
- )
1247
-
1248
- t_threshold = config_data.get("toxicity_threshold", 0.05)
1249
- toxicity_fig = create_toxicity_trend_chart(
1250
- toxicity_values,
1251
- timestamps,
1252
- threshold=t_threshold,
1253
- )
1254
-
1255
- c_threshold = config_data.get("confidence_threshold", 0.15)
1256
- confidence_fig = create_confidence_trend_chart(
1257
- confidence_values,
1258
- timestamps,
1259
- min_confidence=c_threshold,
1260
- )
1261
-
1262
- # Get drift status values
1263
- h_drift = drift_data.get("hallucination", {})
1264
- t_drift = drift_data.get("toxicity", {})
1265
- b_drift = drift_data.get("bias", {})
1266
- c_drift = drift_data.get("confidence", {})
1267
- r_drift = drift_data.get("robustness", {})
1268
-
1269
- h_drift_status = f"Drift: {h_drift.get('magnitude', 0.0):.3f}" if h_drift.get("is_drift") else "No drift"
1270
- t_drift_status = f"Drift: {t_drift.get('magnitude', 0.0):.3f}" if t_drift.get("is_drift") else "No drift"
1271
- b_drift_status = f"Drift: {b_drift.get('magnitude', 0.0):.3f}" if b_drift.get("is_drift") else "No drift"
1272
- c_drift_status = f"Collapse: {c_drift.get('magnitude', 0.0):.3f}" if c_drift.get("is_drift") else "No drift"
1273
- r_drift_status = f"Collapse: {r_drift.get('magnitude', 0.0):.3f}" if r_drift.get("is_drift") else "No drift"
1274
-
1275
- # Get alert counts - convert to strings for Gradio compatibility
1276
- alerts = alerts_data.get("alerts", [])
1277
- total_alerts = alerts_data.get("total", 0)
1278
-
1279
- critical_count = sum(1 for a in alerts if a.get("severity") == "critical")
1280
- high_count = sum(1 for a in alerts if a.get("severity") == "high")
1281
- medium_count = sum(1 for a in alerts if a.get("severity") == "medium")
1282
- low_count = sum(1 for a in alerts if a.get("severity") == "low")
1283
-
1284
- # Format alerts for table - ensure it's a proper 2D array
1285
- alert_rows = format_alert_for_table(alerts)
1286
-
1287
- # Ensure alert_rows is a list of lists (2D array for DataFrame)
1288
- if not alert_rows or not isinstance(alert_rows, list):
1289
- alert_rows = [["No alerts", "-", "-", "-", "-", "-", "-"]]
1290
- elif not isinstance(alert_rows[0], list):
1291
- alert_rows = [alert_rows]
1292
-
1293
- return (
1294
- sample_count, # samples_processed
1295
- rolling_h, # rolling_hallucination
1296
- rolling_t, # rolling_toxicity
1297
- rolling_b, # rolling_bias
1298
- rolling_c, # rolling_confidence
1299
- rolling_r, # rolling_robustness
1300
- robustness_fig, # robustness_trend_plot
1301
- hallucination_fig, # hallucination_trend_plot
1302
- toxicity_fig, # toxicity_trend_plot
1303
- confidence_fig, # confidence_trend_plot
1304
- h_drift_status, # hallucination_drift
1305
- t_drift_status, # toxicity_drift
1306
- b_drift_status, # bias_drift
1307
- c_drift_status, # confidence_drift
1308
- r_drift_status, # robustness_drift
1309
- str(total_alerts), # alert_critical (convert to string)
1310
- str(critical_count), # alert_high (convert to string)
1311
- str(high_count), # alert_medium (convert to string)
1312
- str(medium_count), # alert_low (convert to string)
1313
- alert_rows, # alerts_table
1314
- )
1315
-
1316
- except Exception as e:
1317
- logger.error(f"Error refreshing monitoring: {e}")
1318
- # Return current values on error
1319
- return (
1320
- 0, 0.0, 0.0, 0.0, 0.0, 0.0,
1321
- create_empty_trend_chart("Robustness", "Error loading"),
1322
- create_empty_trend_chart("Hallucination", "Error loading"),
1323
- create_empty_trend_chart("Toxicity", "Error loading"),
1324
- create_empty_trend_chart("Confidence", "Error loading"),
1325
- "Error", "Error", "Error", "Error", "Error",
1326
- 0, 0, 0, 0, 0,
1327
- [["Error", "-", "-", "-", "-", "-", "-"]],
1328
- )
1329
-
1330
- # Bind events
1331
- run_dropdown.change(
1332
- fn=on_run_select,
1333
- inputs=[run_dropdown],
1334
- outputs=[
1335
- radar_plot,
1336
- composite_score, vulnerability_index, sample_count,
1337
- heatmap_plot,
1338
- attack_selector,
1339
- attack_breakdown_table,
1340
- metrics_table,
1341
- ],
1342
- )
1343
-
1344
- refresh_btn.click(
1345
- fn=on_refresh,
1346
- inputs=[],
1347
- outputs=[run_dropdown],
1348
- )
1349
-
1350
- compare_btn.click(
1351
- fn=on_compare,
1352
- inputs=[model_multiselect],
1353
- outputs=[comparison_table, delta_plot],
1354
- )
1355
-
1356
- refresh_models_btn.click(
1357
- fn=on_refresh_models,
1358
- inputs=[],
1359
- outputs=[model_multiselect],
1360
- )
1361
-
1362
- export_btn.click(
1363
- fn=on_export,
1364
- inputs=[run_dropdown, export_format, include_config],
1365
- outputs=[export_output],
1366
- )
1367
-
1368
- # Benchmark events
1369
- benchmark_dropdown.change(
1370
- fn=on_benchmark_select,
1371
- inputs=[benchmark_dropdown],
1372
- outputs=[
1373
- delta_plot,
1374
- stability_plot,
1375
- ranking_table,
1376
- mean_baseline,
1377
- mean_adversarial,
1378
- mean_delta,
1379
- std_baseline,
1380
- best_model,
1381
- most_stable,
1382
- mean_rsi,
1383
- most_vulnerable,
1384
- total_models,
1385
- ],
1386
- )
1387
-
1388
- refresh_benchmarks_btn.click(
1389
- fn=on_refresh_benchmarks,
1390
- inputs=[],
1391
- outputs=[benchmark_dropdown],
1392
- )
1393
-
1394
- # Monitoring events
1395
- refresh_monitoring_btn.click(
1396
- fn=on_refresh_monitoring,
1397
- inputs=[],
1398
- outputs=[
1399
- samples_processed,
1400
- rolling_hallucination,
1401
- rolling_toxicity,
1402
- rolling_bias,
1403
- rolling_confidence,
1404
- rolling_robustness,
1405
- robustness_trend_plot,
1406
- hallucination_trend_plot,
1407
- toxicity_trend_plot,
1408
- confidence_trend_plot,
1409
- hallucination_drift,
1410
- toxicity_drift,
1411
- bias_drift,
1412
- confidence_drift,
1413
- robustness_drift,
1414
- alert_critical,
1415
- alert_high,
1416
- alert_medium,
1417
- alert_low,
1418
- alerts_table,
1419
- ],
1420
- )
1421
-
1422
- # Load demo data on app start for all tabs
1423
- def load_demo_data():
1424
- """Load demo data for all tabs on startup."""
1425
- # Monitoring data - get 20 values (not 21!)
1426
- monitoring_data = on_refresh_monitoring()
1427
- # monitoring_data has 20 values:
1428
- # (sample_count, rolling_h, rolling_t, rolling_b, rolling_c, rolling_r,
1429
- # robustness_fig, hallucination_fig, toxicity_fig, confidence_fig,
1430
- # h_drift_status, t_drift_status, b_drift_status, c_drift_status, r_drift_status,
1431
- # total_alerts, critical_count, high_count, medium_count, low_count, alert_rows)
1432
-
1433
- # Governance data
1434
- governance_data = [
1435
- ["2024-01-15 10:30:00", "threshold_update", "admin", "Updated hallucination threshold to 0.15", "abc123"],
1436
- ["2024-01-16 14:20:00", "policy_change", "admin", "Activated new safety policy v1.1", "def456"],
1437
- ["2024-01-17 09:15:00", "audit_review", "auditor", "Quarterly compliance audit completed", "ghi789"],
1438
- ]
1439
-
1440
- threshold_history_data = [
1441
- ["2024-01-15", "0.12", "0.15", "admin"],
1442
- ["2024-01-20", "0.15", "0.18", "admin"],
1443
- ["2024-02-01", "0.18", "0.16", "admin"],
1444
- ]
1445
-
1446
- # Certification data
1447
- criteria_data = [
1448
- ["GSS-1", "0.85", "0.15", "Basic certification"],
1449
- ["GSS-2", "0.90", "0.10", "Advanced certification"],
1450
- ["GSS-3", "0.95", "0.05", "Expert certification"],
1451
- ]
1452
-
1453
- cert_history_data = [
1454
- ["2024-01-15", "gpt-4", "0.87", "GSS-1", "2025-01-15"],
1455
- ["2024-01-20", "claude-3", "0.91", "GSS-2", "2025-01-20"],
1456
- ["2024-02-01", "llama-2", "0.82", "GSS-1", "2025-02-01"],
1457
- ]
1458
-
1459
- # Enterprise data
1460
- plan_data = [
1461
- ["Free", "10", "$0/month", "Basic evaluation"],
1462
- ["Basic", "50", "$99/month", "Advanced metrics"],
1463
- ["Pro", "200", "$299/month", "Full governance"],
1464
- ["Enterprise", "Unlimited", "$999/month", "Custom deployment"],
1465
- ]
1466
-
1467
- # Compliance data
1468
- control_data = [
1469
- ["CC1.1", "Access Control", "Pass", "User authentication implemented"],
1470
- ["CC2.2", "Encryption", "Pass", "AES-256 encryption at rest"],
1471
- ["CC3.3", "Logging", "Pass", "Structured JSON logging"],
1472
- ["CC4.4", "Monitoring", "Pass", "Real-time drift detection"],
1473
- ]
1474
-
1475
- eu_data = [
1476
- ["Article 10", "Data Governance", "Compliant", "Data quality monitoring"],
1477
- ["Article 14", "Transparency", "Compliant", "Model cards provided"],
1478
- ["Article 15", "Human Oversight", "Compliant", "Human-in-the-loop"],
1479
- ]
1480
-
1481
- # Ecosystem data
1482
- authority_data = [
1483
- ["US NIST", "North America", "45", "Active"],
1484
- ["EU ENISA", "Europe", "32", "Active"],
1485
- ["UK NCSC", "Europe", "28", "Active"],
1486
- ]
1487
-
1488
- plugin_data = [
1489
- ["Toxicity Detector", "AegisLM", "Safety", "4.8", "1250"],
1490
- ["Bias Analyzer", "AegisLM", "Fairness", "4.6", "980"],
1491
- ["Hallucination Checker", "AegisLM", "Accuracy", "4.9", "2100"],
1492
- ]
1493
-
1494
- # Deployment data
1495
- checklist_data = [
1496
- ["Database", "Pass", "PostgreSQL configured"],
1497
- ["Redis", "Pass", "Rate limiting active"],
1498
- ["Security", "Pass", "All controls implemented"],
1499
- ["Monitoring", "Pass", "Dashboards operational"],
1500
- ]
1501
-
1502
- deploy_data = [
1503
- ["2024-01-15", "v1.0.0", "Success", "2m 30s"],
1504
- ["2024-01-20", "v1.0.1", "Success", "1m 45s"],
1505
- ["2024-02-01", "v1.1.0", "Success", "3m 15s"],
1506
- ]
1507
-
1508
- return (
1509
- # Runs and benchmarks
1510
- load_runs(), load_model_names(), load_benchmarks(),
1511
- # Monitoring
1512
- *monitoring_data,
1513
- # Governance
1514
- governance_data, threshold_history_data,
1515
- # Certification
1516
- criteria_data, cert_history_data,
1517
- # Enterprise
1518
- 15, 120, 4500, 18000, plan_data, 1250, 45, 2.3,
1519
- # Compliance
1520
- control_data, eu_data,
1521
- # Ecosystem
1522
- authority_data, plugin_data,
1523
- # Deployment
1524
- checklist_data, deploy_data,
1525
- )
1526
-
1527
- # Load demo data on app start
1528
- app.load(
1529
- fn=load_demo_data,
1530
- inputs=[],
1531
- outputs=[
1532
- run_dropdown, model_multiselect, benchmark_dropdown,
1533
- # Monitoring outputs
1534
- samples_processed, rolling_hallucination, rolling_toxicity, rolling_bias,
1535
- rolling_confidence, rolling_robustness, robustness_trend_plot,
1536
- hallucination_trend_plot, toxicity_trend_plot, confidence_trend_plot,
1537
- hallucination_drift, toxicity_drift, bias_drift, confidence_drift,
1538
- robustness_drift, alert_critical, alert_high, alert_medium, alert_low, alerts_table,
1539
- # Governance outputs
1540
- audit_log, threshold_history,
1541
- # Certification outputs
1542
- criteria_table, cert_history,
1543
- # Enterprise outputs
1544
- tenant_count, active_users, mrr, arr, plan_breakdown, api_calls, eval_runs, data_processed,
1545
- # Compliance outputs
1546
- control_table, eu_table,
1547
- # Ecosystem outputs
1548
- authority_table, plugin_table,
1549
- # Deployment outputs
1550
- checklist, deploy_history,
1551
- ],
1552
- )
1553
-
1554
- return app
1555
-
1556
-
1557
- # =============================================================================
1558
- # Helper Functions
1559
- # =============================================================================
1560
-
1561
-
1562
- def create_empty_radar():
1563
- """Create empty radar chart."""
1564
- import plotly.graph_objects as go
1565
-
1566
- fig = go.Figure()
1567
- fig.update_layout(
1568
- title="Select a run to view radar chart",
1569
- polar=dict(
1570
- radialaxis=dict(visible=True, range=[0, 1]),
1571
- ),
1572
- height=400,
1573
- width=400,
1574
- )
1575
- return fig
1576
-
1577
-
1578
- def create_empty_heatmap():
1579
- """Create empty heatmap."""
1580
- import plotly.graph_objects as go
1581
-
1582
- fig = go.Figure()
1583
- fig.update_layout(
1584
- title="Select a run to view vulnerability heatmap",
1585
- xaxis=dict(title="Metrics"),
1586
- yaxis=dict(title="Attack Types"),
1587
- height=400,
1588
- width=600,
1589
- )
1590
- return fig
1591
-
1592
-
1593
- def create_empty_delta():
1594
- """Create empty delta chart."""
1595
- import plotly.graph_objects as go
1596
-
1597
- fig = go.Figure()
1598
- fig.update_layout(
1599
- title="Select models to compare",
1600
- xaxis=dict(title="Model"),
1601
- yaxis=dict(title="Delta Robustness"),
1602
- height=400,
1603
- width=600,
1604
- )
1605
- return fig
1606
-
1607
-
1608
- # =============================================================================
1609
- # Main Entry Point
1610
- # =============================================================================
1611
-
1612
-
1613
- def main():
1614
- """Main entry point for the dashboard."""
1615
- import argparse
1616
-
1617
- parser = argparse.ArgumentParser(description="AegisLM Dashboard")
1618
- parser.add_argument(
1619
- "--host",
1620
- type=str,
1621
- default="0.0.0.0",
1622
- help="Host to bind to",
1623
- )
1624
- parser.add_argument(
1625
- "--port",
1626
- type=int,
1627
- default=7860,
1628
- help="Port to bind to",
1629
- )
1630
- parser.add_argument(
1631
- "--demo",
1632
- action="store_true",
1633
- help="Enable demo mode with sample data",
1634
- )
1635
- parser.add_argument(
1636
- "--debug",
1637
- action="store_true",
1638
- help="Enable debug mode",
1639
- )
1640
-
1641
- args = parser.parse_args()
1642
-
1643
- # Setup logging
1644
- logging.basicConfig(
1645
- level=logging.DEBUG if args.debug else logging.INFO,
1646
- format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
1647
- )
1648
-
1649
- # Create dashboard
1650
- app = create_dashboard(demo_mode=args.demo)
1651
-
1652
- # Launch
1653
- app.launch(
1654
- server_name=args.host,
1655
- server_port=args.port,
1656
- share=args.debug, # Share in debug mode for testing
1657
- )
1658
-
1659
-
1660
- if __name__ == "__main__":
1661
- main()
 
1
+ """
2
+ AegisLM - HuggingFace Spaces Deployment
3
+ ======================================
4
+
5
+ Simplified entry point that works in Docker container.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+
11
+ # CRITICAL: Add the app directory to Python path first
12
+ # In Docker, the app runs from /app
13
+ APP_DIR = "/app"
14
+ if APP_DIR not in sys.path:
15
+ sys.path.insert(0, APP_DIR)
16
+
17
+ # Also add current working directory as fallback
18
+ CWD = os.getcwd()
19
+ if CWD not in sys.path:
20
+ sys.path.insert(0, CWD)
21
+
22
+ import logging
23
+
24
+ # Configure logging
25
+ logging.basicConfig(
26
+ level=logging.INFO,
27
+ format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
28
+ )
29
+ logger = logging.getLogger(__name__)
30
+
31
+ logger.info(f"Python path: {sys.path[:3]}")
32
+ logger.info(f"Current directory: {os.getcwd()}")
33
+ logger.info(f"Files in current dir: {os.listdir('.')}")
34
+
35
+
36
+ def main():
37
+ """Main entry point."""
38
+ import gradio as gr
39
+
40
+ # Determine port from environment (HF Spaces sets this)
41
+ port = int(os.getenv("PORT", "7860"))
42
+ host = os.getenv("HOST", "0.0.0.0")
43
+
44
+ # Check if demo mode is enabled
45
+ demo_mode = os.getenv("DEMO_MODE", "true").lower() == "true"
46
+ logger.info(f"Starting in {'demo' if demo_mode else 'production'} mode")
47
+
48
+ try:
49
+ # Try importing from dashboard package
50
+ from dashboard.app import create_dashboard
51
+ logger.info("Successfully imported dashboard.app")
52
+
53
+ # Create the dashboard
54
+ app = create_dashboard(demo_mode=demo_mode)
55
+ logger.info("Created Gradio app successfully")
56
+
57
+ except ImportError as e:
58
+ logger.error(f"Failed to import dashboard: {e}")
59
+ logger.error(f"Current sys.path: {sys.path}")
60
+
61
+ # Try importing directly from app.py in dashboard folder
62
+ try:
63
+ # List what's in the dashboard folder
64
+ dashboard_path = os.path.join(APP_DIR, "dashboard")
65
+ if os.path.exists(dashboard_path):
66
+ logger.info(f"Files in dashboard: {os.listdir(dashboard_path)}")
67
+ else:
68
+ logger.error(f"Dashboard folder not found at: {dashboard_path}")
69
+
70
+ # Try to import the module differently
71
+ import importlib.util
72
+ spec = importlib.util.spec_from_file_location(
73
+ "dashboard_app",
74
+ os.path.join(dashboard_path, "app.py")
75
+ )
76
+ if spec and spec.loader:
77
+ dashboard_module = importlib.util.module_from_spec(spec)
78
+ spec.loader.exec_module(dashboard_module)
79
+ app = dashboard_module.create_dashboard(demo_mode=demo_mode)
80
+ logger.info("Loaded dashboard directly")
81
+ else:
82
+ raise ImportError("Could not load dashboard module")
83
+
84
+ except Exception as e2:
85
+ logger.error(f"Failed to load dashboard directly: {e2}")
86
+ raise
87
+
88
+ # Launch the app
89
+ logger.info(f"Launching on {host}:{port}")
90
+ app.launch(
91
+ server_name=host,
92
+ server_port=port,
93
+ share=False,
94
+ )
95
+
96
+
97
+ if __name__ == "__main__":
98
+ main()