petter2025 commited on
Commit
aa90f50
Β·
verified Β·
1 Parent(s): 0c25605

Delete hf_demo_backup.py

Browse files
Files changed (1) hide show
  1. hf_demo_backup.py +0 -1470
hf_demo_backup.py DELETED
@@ -1,1470 +0,0 @@
1
- """
2
- ARF 3.3.9 - Enterprise AI Execution Authority Demo
3
- GROUNDED IN REALISTIC BUSINESS METRICS & ENTERPRISE VALUE
4
- FIXED: Now correctly shows "REAL ARF OSS 3.3.9" when real ARF is installed
5
- """
6
-
7
- import gradio as gr
8
- import time
9
- import random
10
- import json
11
- import uuid
12
- import subprocess
13
- import sys
14
- import importlib
15
- from datetime import datetime, timedelta
16
- from typing import Dict, List, Optional, Tuple, Any, Union
17
- import numpy as np
18
- import pandas as pd
19
-
20
- # ============== ENTERPRISE-GRADE ARF DETECTION (FIXED) ==============
21
- print("=" * 80)
22
- print("πŸš€ ARF 3.3.9 - ENTERPRISE EXECUTION AUTHORITY DEMO")
23
- print("πŸ” ENHANCED DETECTION: Unified ARF Status with Single Source of Truth")
24
- print("=" * 80)
25
-
26
- class UnifiedARFDetector:
27
- """Unified ARF detector that fixes the "SIMULATED" display bug"""
28
-
29
- def __init__(self):
30
- self.detection_log = []
31
- self._unified_status = None
32
-
33
- def get_unified_arf_status(self) -> Dict[str, Any]:
34
- """
35
- Unified ARF status detection - SINGLE SOURCE OF TRUTH
36
- This fixes the bug where UI shows "SIMULATED" despite real ARF
37
- """
38
- print("\nπŸ” INITIATING UNIFIED ARF DETECTION...")
39
-
40
- # Priority 1: Check for REAL ARF OSS 3.3.9
41
- real_detection = self._detect_real_arf_oss()
42
-
43
- if real_detection['found']:
44
- print(f"βœ… CONFIRMED: REAL ARF OSS {real_detection.get('version', '3.3.9')}")
45
- print(f"πŸ“¦ Source: {real_detection['source']}")
46
- print(f"πŸ”§ Components: {list(real_detection['components'].keys())}")
47
-
48
- return {
49
- 'status': 'REAL_OSS',
50
- 'is_real': True,
51
- 'version': real_detection.get('version', '3.3.9'),
52
- 'source': real_detection['source'],
53
- 'components': real_detection['components'],
54
- 'display_text': f"βœ… REAL OSS {real_detection.get('version', '3.3.9')}",
55
- 'badge_class': 'arf-real-badge',
56
- 'badge_css': 'arf-real',
57
- 'detection_time': time.time(),
58
- 'enterprise_ready': True,
59
- 'license_gated': True,
60
- 'unified_truth': True # Critical flag for UI
61
- }
62
-
63
- # Priority 2: Check pip installation (requirements.txt ensures this)
64
- pip_detection = self._check_pip_installation()
65
- if pip_detection['installed']:
66
- print(f"βœ… PIP INSTALLATION: ARF {pip_detection['version']} detected")
67
-
68
- return {
69
- 'status': 'PIP_INSTALLED',
70
- 'is_real': True, # Real installation via pip
71
- 'version': pip_detection['version'],
72
- 'source': 'pip_installation',
73
- 'components': self._create_enterprise_components(pip_detection['version']),
74
- 'display_text': f"βœ… REAL OSS {pip_detection['version']} (pip)",
75
- 'badge_class': 'arf-real-badge',
76
- 'badge_css': 'arf-real',
77
- 'detection_time': time.time(),
78
- 'enterprise_ready': True,
79
- 'license_gated': True,
80
- 'unified_truth': True
81
- }
82
-
83
- # Fallback: Enhanced simulation (shouldn't happen with requirements.txt)
84
- print("⚠️ Using enhanced enterprise simulation")
85
-
86
- return {
87
- 'status': 'ENHANCED_SIMULATION',
88
- 'is_real': False,
89
- 'version': '3.3.9',
90
- 'source': 'enhanced_simulation',
91
- 'components': self._create_enterprise_components('3.3.9'),
92
- 'display_text': '⚠️ ENTERPRISE SIMULATION 3.3.9',
93
- 'badge_class': 'arf-sim-badge',
94
- 'badge_css': 'arf-sim',
95
- 'detection_time': time.time(),
96
- 'enterprise_ready': True,
97
- 'license_gated': True,
98
- 'unified_truth': True
99
- }
100
-
101
- def _detect_real_arf_oss(self) -> Dict[str, Any]:
102
- """Detect REAL ARF OSS with proper component validation"""
103
- detection_paths = [
104
- ("agentic_reliability_framework", None), # Primary from requirements.txt
105
- ("arf", None), # Short name
106
- ("agentic_reliability_framework.core", ["ExecutionLadder", "RiskEngine"]),
107
- ("arf.oss", ["ExecutionLadder", "RiskEngine"]),
108
- ("arf.core", ["ExecutionLadder", "RiskEngine"]),
109
- ]
110
-
111
- for module_path, target_components in detection_paths:
112
- try:
113
- print(f"πŸ” Attempting import: {module_path}")
114
- module = importlib.import_module(module_path)
115
-
116
- # Enhanced validation for real ARF
117
- is_real_arf = self._validate_real_arf(module, module_path)
118
-
119
- if not is_real_arf:
120
- continue
121
-
122
- components = {'module': module, '__real_arf': True}
123
-
124
- # Import specific components
125
- if target_components:
126
- for comp_name in target_components:
127
- try:
128
- comp = getattr(module, comp_name, None)
129
- if comp:
130
- components[comp_name] = comp
131
- components[f'__has_{comp_name}'] = True
132
- except AttributeError:
133
- # Try deeper imports for enterprise structure
134
- try:
135
- sub_path = f"{module_path}.{comp_name.lower()}"
136
- submodule = importlib.import_module(sub_path)
137
- comp = getattr(submodule, comp_name)
138
- components[comp_name] = comp
139
- components[f'__has_{comp_name}'] = True
140
- except:
141
- components[f'__has_{comp_name}'] = False
142
-
143
- # Get version - critical for display
144
- version = '3.3.9'
145
- if hasattr(module, '__version__'):
146
- version = module.__version__
147
- elif hasattr(module, 'VERSION'):
148
- version = module.VERSION
149
- elif '__version__' in dir(module):
150
- version = module.__version__
151
-
152
- components['__version__'] = version
153
- components['__detection_path'] = module_path
154
-
155
- print(f"βœ… REAL ARF VALIDATED: {module_path} v{version}")
156
-
157
- return {
158
- 'found': True,
159
- 'source': module_path,
160
- 'version': version,
161
- 'components': components,
162
- 'validation_score': 95
163
- }
164
-
165
- except ImportError as e:
166
- self.detection_log.append(f"{module_path}: {str(e)}")
167
- continue
168
- except Exception as e:
169
- print(f"⚠️ Import error for {module_path}: {e}")
170
- continue
171
-
172
- return {'found': False, 'source': None, 'components': {}, 'validation_score': 0}
173
-
174
- def _validate_real_arf(self, module, module_path: str) -> bool:
175
- """Enhanced validation that this is REAL ARF OSS"""
176
- validation_checks = []
177
-
178
- # Check 1: Module name contains ARF indicators
179
- name_checks = [
180
- 'arf' in str(module.__name__).lower(),
181
- 'agentic' in str(module.__name__).lower() and 'reliability' in str(module.__name__).lower(),
182
- 'agentic_reliability_framework' in str(module.__name__),
183
- ]
184
- validation_checks.append(any(name_checks))
185
-
186
- # Check 2: Has ARF-specific attributes
187
- attribute_checks = [
188
- hasattr(module, '__version__'),
189
- hasattr(module, 'ExecutionLadder') or hasattr(module, 'RiskEngine'),
190
- hasattr(module, 'PolicyEngine') or hasattr(module, 'ActionValidator'),
191
- ]
192
- validation_checks.append(any(attribute_checks))
193
-
194
- # Check 3: Version check (if available)
195
- if hasattr(module, '__version__'):
196
- version = str(getattr(module, '__version__'))
197
- version_checks = [
198
- '3.3' in version,
199
- '3.3.9' in version,
200
- version.startswith('3.'),
201
- ]
202
- validation_checks.append(any(version_checks))
203
-
204
- # Final validation: Must pass at least 2 checks
205
- passed_checks = sum(validation_checks)
206
- is_valid = passed_checks >= 2
207
-
208
- if is_valid:
209
- print(f"βœ… ARF Validation: {passed_checks}/3 checks passed for {module_path}")
210
-
211
- return is_valid
212
-
213
- def _check_pip_installation(self) -> Dict[str, Any]:
214
- """Check pip installation with enhanced validation"""
215
- try:
216
- print("πŸ” Checking pip installation (requirements.txt: agentic-reliability-framework>=3.3.9)")
217
-
218
- result = subprocess.run(
219
- [sys.executable, "-m", "pip", "show", "agentic-reliability-framework"],
220
- capture_output=True,
221
- text=True,
222
- timeout=5
223
- )
224
-
225
- if result.returncode == 0:
226
- version = "3.3.9"
227
- location = ""
228
-
229
- # Parse pip output
230
- for line in result.stdout.split('\n'):
231
- if line.startswith('Version:'):
232
- version = line.split(':')[1].strip()
233
- elif line.startswith('Location:'):
234
- location = line.split(':')[1].strip()
235
-
236
- print(f"βœ… Pip installation confirmed: {version} at {location}")
237
-
238
- return {
239
- 'installed': True,
240
- 'version': version,
241
- 'location': location,
242
- 'message': f"ARF {version} installed via pip"
243
- }
244
- except Exception as e:
245
- print(f"⚠️ Pip check error: {e}")
246
-
247
- return {'installed': False, 'message': 'Not installed via pip'}
248
-
249
- def _create_enterprise_components(self, version: str) -> Dict[str, Any]:
250
- """Create enterprise-grade components for simulation"""
251
- class EnhancedExecutionLadder:
252
- """Enhanced Execution Ladder with proper license gating"""
253
- def __init__(self):
254
- self.name = "EnhancedExecutionLadder"
255
- self.version = version
256
-
257
- def evaluate(self, action, context, license_tier='oss'):
258
- base_risk = 0.3
259
-
260
- if 'DROP' in action.upper() and 'DATABASE' in action.upper():
261
- base_risk = 0.85
262
- elif 'DELETE' in action.upper():
263
- base_risk = 0.65
264
- elif 'GRANT' in action.upper() or 'ADMIN' in action.upper():
265
- base_risk = 0.55
266
-
267
- # License enforcement
268
- if license_tier == 'oss':
269
- allowed = False
270
- level = 'ADVISORY_ONLY'
271
- elif license_tier == 'trial':
272
- allowed = base_risk < 0.6
273
- level = 'OPERATOR_REVIEW'
274
- elif license_tier == 'professional':
275
- allowed = base_risk < 0.7
276
- level = 'AUTONOMOUS_LOW'
277
- elif license_tier == 'enterprise':
278
- allowed = base_risk < 0.8
279
- level = 'AUTONOMOUS_HIGH'
280
- else:
281
- allowed = False
282
- level = 'ADVISORY_ONLY'
283
-
284
- return {
285
- 'risk_score': min(0.95, max(0.1, base_risk)),
286
- 'allowed': allowed,
287
- 'execution_level': level,
288
- 'license_tier': license_tier,
289
- 'mechanical_gates': self._calculate_gates(base_risk, license_tier),
290
- 'evaluation_source': f'ARF {version}'
291
- }
292
-
293
- def _calculate_gates(self, risk_score, license_tier):
294
- gates = []
295
-
296
- # Gate 1: Risk Assessment
297
- gates.append({
298
- 'name': 'Risk Assessment',
299
- 'passed': risk_score < 0.8,
300
- 'license_required': False
301
- })
302
-
303
- # Gate 2: License Validation
304
- gates.append({
305
- 'name': 'License Validation',
306
- 'passed': license_tier != 'oss',
307
- 'license_required': True
308
- })
309
-
310
- # Gate 3: Rollback Feasibility
311
- if license_tier in ['professional', 'enterprise']:
312
- gates.append({
313
- 'name': 'Rollback Feasibility',
314
- 'passed': risk_score < 0.7,
315
- 'license_required': True
316
- })
317
-
318
- return gates
319
-
320
- return {
321
- 'ExecutionLadder': EnhancedExecutionLadder(),
322
- '__version__': version,
323
- '__enterprise_simulation': True,
324
- '__license_gated': True,
325
- '__business_model': 'execution_authority'
326
- }
327
-
328
- # Initialize unified detector
329
- detector = UnifiedARFDetector()
330
- ARF_UNIFIED_STATUS = detector.get_unified_arf_status()
331
-
332
- # ============== DEMO STATE WITH UNIFIED STATUS ==============
333
- class UnifiedDemoState:
334
- """Demo state bound to unified ARF status"""
335
-
336
- def __init__(self, arf_status: Dict[str, Any]):
337
- # BIND to unified status - this fixes the display bug
338
- self.arf_status = arf_status
339
- self.stats = {
340
- 'actions_tested': 0,
341
- 'risks_prevented': 0,
342
- 'high_risk_blocked': 0,
343
- 'license_validations': 0,
344
- 'mechanical_gates_triggered': 0,
345
- 'trial_licenses': 0,
346
- 'enterprise_upgrades': 0,
347
- 'start_time': time.time(),
348
- # CRITICAL FIX: Use unified status directly
349
- 'real_arf_used': arf_status['is_real'],
350
- 'arf_version': arf_status['version'],
351
- 'arf_source': arf_status['source'],
352
- 'display_text': arf_status['display_text'],
353
- 'badge_class': arf_status['badge_class']
354
- }
355
- self.action_history = []
356
- self.license_state = {
357
- 'current_tier': 'oss',
358
- 'current_license': None,
359
- 'execution_level': 'ADVISORY_ONLY'
360
- }
361
-
362
- def update_license(self, license_key: Optional[str] = None):
363
- """Update license state"""
364
- if not license_key:
365
- self.license_state = {
366
- 'current_tier': 'oss',
367
- 'current_license': None,
368
- 'execution_level': 'ADVISORY_ONLY'
369
- }
370
- return
371
-
372
- key_upper = license_key.upper()
373
-
374
- if 'ARF-TRIAL' in key_upper:
375
- self.license_state = {
376
- 'current_tier': 'trial',
377
- 'current_license': license_key,
378
- 'execution_level': 'OPERATOR_REVIEW',
379
- 'trial_expiry': time.time() + (14 * 24 * 3600)
380
- }
381
- self.stats['trial_licenses'] += 1
382
- elif 'ARF-ENTERPRISE' in key_upper:
383
- self.license_state = {
384
- 'current_tier': 'enterprise',
385
- 'current_license': license_key,
386
- 'execution_level': 'AUTONOMOUS_HIGH'
387
- }
388
- self.stats['enterprise_upgrades'] += 1
389
- elif 'ARF-PRO' in key_upper:
390
- self.license_state = {
391
- 'current_tier': 'professional',
392
- 'current_license': license_key,
393
- 'execution_level': 'AUTONOMOUS_LOW'
394
- }
395
- else:
396
- self.license_state = {
397
- 'current_tier': 'oss',
398
- 'current_license': license_key,
399
- 'execution_level': 'ADVISORY_ONLY'
400
- }
401
-
402
- def add_action(self, action_data: Dict[str, Any]):
403
- """Add action to history"""
404
- self.action_history.insert(0, action_data)
405
- if len(self.action_history) > 10:
406
- self.action_history = self.action_history[:10]
407
-
408
- self.stats['actions_tested'] += 1
409
- if action_data.get('risk_score', 0) > 0.7:
410
- self.stats['high_risk_blocked'] += 1
411
- if action_data.get('license_tier') != 'oss':
412
- self.stats['license_validations'] += 1
413
-
414
- # Initialize demo state with unified status
415
- demo_state = UnifiedDemoState(ARF_UNIFIED_STATUS)
416
-
417
- print(f"\n{'='*80}")
418
- print(f"πŸ“Š UNIFIED ARF STATUS CONFIRMED:")
419
- print(f" Display: {ARF_UNIFIED_STATUS['display_text']}")
420
- print(f" Real ARF: {'βœ… YES' if ARF_UNIFIED_STATUS['is_real'] else '⚠️ SIMULATION'}")
421
- print(f" Version: {ARF_UNIFIED_STATUS['version']}")
422
- print(f" Source: {ARF_UNIFIED_STATUS['source']}")
423
- print(f" Unified Truth: {'βœ… ACTIVE' if ARF_UNIFIED_STATUS.get('unified_truth', False) else '❌ INACTIVE'}")
424
- print(f"{'='*80}\n")
425
-
426
- # ============== ENTERPRISE CSS ==============
427
- ENTERPRISE_CSS = """
428
- :root {
429
- /* Unified Color System */
430
- --arf-real-gradient: linear-gradient(135deg, #4CAF50 0%, #2E7D32 50%, #1B5E20 100%);
431
- --arf-sim-gradient: linear-gradient(135deg, #FF9800 0%, #F57C00 50%, #E65100 100%);
432
- --hf-orange: linear-gradient(135deg, #FF6B00 0%, #E65100 100%);
433
-
434
- /* License Tier Colors */
435
- --oss-blue: #1E88E5;
436
- --trial-gold: #FFB300;
437
- --starter-orange: #FF9800;
438
- --professional-dark: #FF6F00;
439
- --enterprise-red: #D84315;
440
- }
441
-
442
- /* ARF Status Badges - FIXED DISPLAY */
443
- .arf-real-badge {
444
- background: var(--arf-real-gradient);
445
- color: white;
446
- padding: 8px 16px;
447
- border-radius: 20px;
448
- font-size: 14px;
449
- font-weight: bold;
450
- display: inline-flex;
451
- align-items: center;
452
- gap: 8px;
453
- margin: 5px;
454
- box-shadow: 0 4px 12px rgba(76, 175, 80, 0.4);
455
- border: 2px solid rgba(255, 255, 255, 0.3);
456
- animation: pulse-success 2s infinite;
457
- }
458
-
459
- .arf-real-badge::before {
460
- content: "βœ…";
461
- font-size: 16px;
462
- filter: drop-shadow(0 2px 3px rgba(0,0,0,0.3));
463
- }
464
-
465
- .arf-sim-badge {
466
- background: var(--arf-sim-gradient);
467
- color: white;
468
- padding: 8px 16px;
469
- border-radius: 20px;
470
- font-size: 14px;
471
- font-weight: bold;
472
- display: inline-flex;
473
- align-items: center;
474
- gap: 8px;
475
- margin: 5px;
476
- box-shadow: 0 4px 12px rgba(255, 152, 0, 0.4);
477
- border: 2px solid rgba(255, 255, 255, 0.3);
478
- }
479
-
480
- .arf-sim-badge::before {
481
- content: "⚠️";
482
- font-size: 16px;
483
- filter: drop-shadow(0 2px 3px rgba(0,0,0,0.3));
484
- }
485
-
486
- .arf-real {
487
- background: var(--arf-real-gradient);
488
- color: white;
489
- }
490
-
491
- .arf-sim {
492
- background: var(--arf-sim-gradient);
493
- color: white;
494
- }
495
-
496
- /* Hugging Face Badge */
497
- .hf-badge {
498
- background: var(--hf-orange);
499
- color: white;
500
- padding: 8px 16px;
501
- border-radius: 20px;
502
- font-size: 14px;
503
- font-weight: bold;
504
- display: inline-flex;
505
- align-items: center;
506
- gap: 8px;
507
- margin: 5px;
508
- box-shadow: 0 4px 12px rgba(255, 107, 0, 0.4);
509
- border: 2px solid rgba(255, 255, 255, 0.3);
510
- }
511
-
512
- .hf-badge::before {
513
- content: "πŸ€—";
514
- font-size: 16px;
515
- filter: drop-shadow(0 2px 3px rgba(0,0,0,0.3));
516
- }
517
-
518
- /* License Cards */
519
- .license-card {
520
- border-radius: 12px;
521
- padding: 20px;
522
- margin: 10px 0;
523
- transition: all 0.3s ease;
524
- border-top: 4px solid;
525
- }
526
-
527
- .license-card:hover {
528
- transform: translateY(-3px);
529
- box-shadow: 0 8px 25px rgba(0,0,0,0.1);
530
- }
531
-
532
- .license-oss {
533
- border-top-color: var(--oss-blue);
534
- background: linear-gradient(to bottom, #E3F2FD, #FFFFFF);
535
- }
536
-
537
- .license-trial {
538
- border-top-color: var(--trial-gold);
539
- background: linear-gradient(to bottom, #FFF8E1, #FFFFFF);
540
- }
541
-
542
- .license-starter {
543
- border-top-color: var(--starter-orange);
544
- background: linear-gradient(to bottom, #FFF3E0, #FFFFFF);
545
- }
546
-
547
- .license-professional {
548
- border-top-color: var(--professional-dark);
549
- background: linear-gradient(to bottom, #FFEBEE, #FFFFFF);
550
- }
551
-
552
- .license-enterprise {
553
- border-top-color: var(--enterprise-red);
554
- background: linear-gradient(to bottom, #FBE9E7, #FFFFFF);
555
- }
556
-
557
- /* Mechanical Gates */
558
- .gate-container {
559
- display: flex;
560
- align-items: center;
561
- justify-content: space-between;
562
- margin: 20px 0;
563
- }
564
-
565
- .gate {
566
- width: 60px;
567
- height: 60px;
568
- border-radius: 50%;
569
- display: flex;
570
- align-items: center;
571
- justify-content: center;
572
- font-weight: bold;
573
- color: white;
574
- font-size: 20px;
575
- position: relative;
576
- box-shadow: 0 4px 8px rgba(0,0,0,0.2);
577
- z-index: 2;
578
- }
579
-
580
- .gate-passed {
581
- background: #4CAF50;
582
- animation: gate-success 0.6s ease-out;
583
- }
584
-
585
- .gate-failed {
586
- background: #F44336;
587
- animation: gate-fail 0.6s ease-out;
588
- }
589
-
590
- .gate-pending {
591
- background: #BDBDBD;
592
- }
593
-
594
- .gate-line {
595
- height: 6px;
596
- flex-grow: 1;
597
- background: #E0E0E0;
598
- z-index: 1;
599
- }
600
-
601
- /* Animations */
602
- @keyframes pulse-success {
603
- 0% {
604
- box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7),
605
- 0 4px 12px rgba(76, 175, 80, 0.4);
606
- }
607
- 70% {
608
- box-shadow: 0 0 0 12px rgba(76, 175, 80, 0),
609
- 0 4px 12px rgba(76, 175, 80, 0.4);
610
- }
611
- 100% {
612
- box-shadow: 0 0 0 0 rgba(76, 175, 80, 0),
613
- 0 4px 12px rgba(76, 175, 80, 0.4);
614
- }
615
- }
616
-
617
- @keyframes gate-success {
618
- 0% { transform: scale(0.7); opacity: 0.3; }
619
- 60% { transform: scale(1.15); }
620
- 100% { transform: scale(1); opacity: 1; }
621
- }
622
-
623
- @keyframes gate-fail {
624
- 0% { transform: scale(1); }
625
- 50% { transform: scale(0.85); }
626
- 100% { transform: scale(1); }
627
- }
628
-
629
- /* Risk Meter */
630
- .risk-meter {
631
- height: 24px;
632
- background: #E0E0E0;
633
- border-radius: 12px;
634
- margin: 15px 0;
635
- overflow: hidden;
636
- position: relative;
637
- }
638
-
639
- .risk-fill {
640
- height: 100%;
641
- border-radius: 12px;
642
- transition: width 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
643
- position: relative;
644
- }
645
-
646
- .risk-fill::after {
647
- content: '';
648
- position: absolute;
649
- top: 0;
650
- left: 0;
651
- right: 0;
652
- bottom: 0;
653
- background: linear-gradient(90deg,
654
- rgba(255,255,255,0.3) 0%,
655
- rgba(255,255,255,0.1) 50%,
656
- rgba(255,255,255,0.3) 100%);
657
- border-radius: 12px;
658
- }
659
-
660
- .risk-low { background: linear-gradient(90deg, #4CAF50, #66BB6A); }
661
- .risk-medium { background: linear-gradient(90deg, #FF9800, #FFB74D); }
662
- .risk-high { background: linear-gradient(90deg, #F44336, #EF5350); }
663
-
664
- /* ROI Calculator */
665
- .roi-calculator {
666
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
667
- color: white;
668
- padding: 25px;
669
- border-radius: 15px;
670
- margin: 25px 0;
671
- box-shadow: 0 8px 32px rgba(102, 126, 234, 0.3);
672
- }
673
-
674
- /* Responsive Design */
675
- @media (max-width: 768px) {
676
- .gate-container {
677
- flex-direction: column;
678
- height: 240px;
679
- }
680
- .gate-line {
681
- width: 6px;
682
- height: 40px;
683
- }
684
- .arf-real-badge, .arf-sim-badge, .hf-badge {
685
- padding: 6px 12px;
686
- font-size: 12px;
687
- }
688
- }
689
- """
690
-
691
- # ============== UTILITY FUNCTIONS ==============
692
- def generate_unified_trial_license() -> str:
693
- """Generate unified trial license"""
694
- segments = [str(uuid.uuid4()).replace('-', '').upper()[i:i+4] for i in range(0, 16, 4)]
695
- return f"ARF-TRIAL-{segments[0]}-{segments[1]}-{segments[2]}-{segments[3]}"
696
-
697
- def format_unified_risk(risk_score: float) -> str:
698
- """Format risk with unified styling"""
699
- if risk_score > 0.8:
700
- return f"<span style='color: #F44336; font-weight: bold;'>🚨 {risk_score*100:.0f}%</span>"
701
- elif risk_score > 0.6:
702
- return f"<span style='color: #FF9800; font-weight: bold;'>⚠️ {risk_score*100:.0f}%</span>"
703
- elif risk_score > 0.4:
704
- return f"<span style='color: #FFC107; font-weight: bold;'>πŸ”Ά {risk_score*100:.0f}%</span>"
705
- else:
706
- return f"<span style='color: #4CAF50; font-weight: bold;'>βœ… {risk_score*100:.0f}%</span>"
707
-
708
- def simulate_unified_gates(risk_score: float, license_tier: str) -> Dict[str, Any]:
709
- """Simulate unified mechanical gates"""
710
- gates = []
711
-
712
- # Gate 1: Risk Assessment
713
- gates.append({
714
- 'name': 'Risk Assessment',
715
- 'passed': risk_score < 0.8,
716
- 'required': True,
717
- 'license_required': False,
718
- 'description': 'Evaluate action risk against thresholds'
719
- })
720
-
721
- # Gate 2: License Validation
722
- license_valid = license_tier != 'oss'
723
- gates.append({
724
- 'name': 'License Validation',
725
- 'passed': license_valid,
726
- 'required': True,
727
- 'license_required': True,
728
- 'description': 'Validate enterprise license entitlement'
729
- })
730
-
731
- # Gate 3: Rollback Feasibility (Professional+)
732
- if license_tier in ['professional', 'enterprise']:
733
- gates.append({
734
- 'name': 'Rollback Feasibility',
735
- 'passed': risk_score < 0.7,
736
- 'required': True,
737
- 'license_required': True,
738
- 'description': 'Ensure action can be safely reversed'
739
- })
740
-
741
- # Gate 4: Admin Approval (Enterprise high-risk)
742
- if license_tier == 'enterprise' and risk_score > 0.6:
743
- gates.append({
744
- 'name': 'Admin Approval',
745
- 'passed': False, # Requires manual approval
746
- 'required': True,
747
- 'license_required': True,
748
- 'description': 'Executive approval for high-risk actions',
749
- 'approval_pending': True
750
- })
751
-
752
- passed = sum(1 for gate in gates if gate['passed'])
753
- total = len(gates)
754
-
755
- return {
756
- 'gates': gates,
757
- 'passed': passed,
758
- 'total': total,
759
- 'all_passed': passed == total,
760
- 'blocked': passed < total
761
- }
762
-
763
- # ============== GRADIO INTERFACE ==============
764
- def create_unified_demo():
765
- """Create unified demo interface with fixed ARF status"""
766
-
767
- # Get unified status for display
768
- arf_display = ARF_UNIFIED_STATUS['display_text']
769
- arf_badge_class = ARF_UNIFIED_STATUS['badge_class']
770
- arf_css_class = ARF_UNIFIED_STATUS['badge_css']
771
-
772
- with gr.Blocks(
773
- title=f"ARF {ARF_UNIFIED_STATUS['version']} - Enterprise Execution Authority",
774
- theme=gr.themes.Soft(
775
- primary_hue="blue",
776
- secondary_hue="orange",
777
- neutral_hue="gray"
778
- ),
779
- css=ENTERPRISE_CSS
780
- ) as demo:
781
-
782
- # ===== UNIFIED HEADER WITH FIXED ARF STATUS =====
783
- gr.Markdown(f"""
784
- <div style="background: linear-gradient(135deg, #1E88E5, #1565C0); color: white; padding: 25px; border-radius: 12px; margin-bottom: 25px; box-shadow: 0 6px 20px rgba(30, 136, 229, 0.3);">
785
- <h1 style="margin: 0; font-size: 2.8em; text-shadow: 0 2px 4px rgba(0,0,0,0.2);">πŸ€– ARF {ARF_UNIFIED_STATUS['version']}</h1>
786
- <h2 style="margin: 10px 0; font-weight: 300; font-size: 1.5em;">Agentic Reliability Framework</h2>
787
- <h3 style="margin: 5px 0; font-weight: 400; font-size: 1.2em; opacity: 0.95;">Mechanically Enforced AI Execution Authority</h3>
788
-
789
- <div style="display: flex; justify-content: center; align-items: center; gap: 15px; margin-top: 25px; flex-wrap: wrap;">
790
- <span class="{arf_badge_class}">{arf_display}</span>
791
- <span class="hf-badge">Hugging Face Spaces</span>
792
- <span style="background: linear-gradient(135deg, #667eea, #764ba2); color: white; padding: 8px 16px; border-radius: 20px; font-size: 14px; font-weight: bold; border: 2px solid rgba(255,255,255,0.3);">
793
- License-Gated Execution
794
- </span>
795
- </div>
796
-
797
- <p style="text-align: center; margin-top: 20px; font-size: 1.1em; opacity: 0.9; max-width: 800px; margin-left: auto; margin-right: auto;">
798
- From Advisory Warnings to Mechanically Enforced AI Execution Authority<br>
799
- <strong>Business Model:</strong> License-Gated Execution Authority β€’
800
- <strong>Market:</strong> Enterprise AI Infrastructure β€’
801
- <strong>Status:</strong> Production-Ready v{ARF_UNIFIED_STATUS['version']}
802
- </p>
803
- </div>
804
- """)
805
-
806
- # ===== ENTERPRISE METRICS =====
807
- with gr.Row():
808
- metrics = [
809
- ("92%", "Incident Prevention", "with Mechanical Gates", "#4CAF50"),
810
- ("$3.9M", "Avg. Breach Cost", "92% preventable with ARF", "#2196F3"),
811
- ("3.2 mo", "Payback Period", "Enterprise ROI", "#FF9800"),
812
- ("1K+", "Developers", "Using ARF for AI Safety", "#9C27B0")
813
- ]
814
-
815
- for value, title, subtitle, color in metrics:
816
- with gr.Column(scale=1):
817
- gr.HTML(f"""
818
- <div style="text-align: center; padding: 20px; background: #f8f9fa; border-radius: 12px; border-left: 4px solid {color}; box-shadow: 0 4px 12px rgba(0,0,0,0.08);">
819
- <div style="font-size: 32px; font-weight: bold; color: {color}; margin-bottom: 5px;">{value}</div>
820
- <div style="font-size: 14px; color: #333; font-weight: 500;">{title}</div>
821
- <div style="font-size: 12px; color: #666; margin-top: 4px;">{subtitle}</div>
822
- </div>
823
- """)
824
-
825
- # ===== EXECUTION AUTHORITY DEMO =====
826
- gr.Markdown("""
827
- ## πŸš€ Execution Authority Demo
828
- *Test how ARF's license-gated execution ladder prevents unsafe AI actions*
829
- """)
830
-
831
- with gr.Row():
832
- # Control Panel
833
- with gr.Column(scale=2):
834
- scenario = gr.Dropdown(
835
- label="🏒 Select Enterprise Scenario",
836
- choices=[
837
- "DROP DATABASE production",
838
- "DELETE FROM users WHERE status='active'",
839
- "GRANT admin TO new_intern",
840
- "SHUTDOWN production cluster",
841
- "UPDATE financial_records SET balance=0"
842
- ],
843
- value="DROP DATABASE production",
844
- interactive=True
845
- )
846
-
847
- context = gr.Textbox(
848
- label="πŸ“‹ Enterprise Context",
849
- value="Environment: production, User: junior_dev, Time: 2AM, Backup: 24h old, Compliance: PCI-DSS",
850
- interactive=False
851
- )
852
-
853
- license_key = gr.Textbox(
854
- label="πŸ” License Key (Mechanical Gate)",
855
- placeholder="Enter ARF-TRIAL-XXXX for 14-day trial or ARF-ENTERPRISE-XXXX",
856
- value=""
857
- )
858
-
859
- with gr.Row():
860
- test_btn = gr.Button("⚑ Test Execution Authority", variant="primary", scale=2)
861
- trial_btn = gr.Button("🎁 Generate Trial License", variant="secondary", scale=1)
862
-
863
- # License Display
864
- with gr.Column(scale=1):
865
- license_display = gr.HTML(f"""
866
- <div class="license-card license-oss">
867
- <h3 style="margin-top: 0; color: #1E88E5; display: flex; align-items: center;">
868
- <span>OSS Edition</span>
869
- <span style="margin-left: auto; font-size: 0.7em; background: #1E88E5; color: white; padding: 3px 10px; border-radius: 12px;">Advisory Only</span>
870
- </h3>
871
- <p style="color: #666; font-size: 0.9em; margin-bottom: 15px;">
872
- ⚠️ <strong>No Mechanical Enforcement</strong><br>
873
- AI recommendations only
874
- </p>
875
- <div style="background: rgba(30, 136, 229, 0.1); padding: 12px; border-radius: 8px; border-left: 3px solid #1E88E5;">
876
- <div style="font-size: 0.85em; color: #1565C0;">
877
- <strong>Execution Level:</strong> ADVISORY_ONLY<br>
878
- <strong>Risk Prevention:</strong> 0%<br>
879
- <strong>ARF Status:</strong> {arf_display}
880
- </div>
881
- </div>
882
- </div>
883
- """)
884
-
885
- # ===== RESULTS PANELS =====
886
- with gr.Row():
887
- # OSS Results
888
- with gr.Column(scale=1):
889
- oss_results = gr.HTML("""
890
- <div class="license-card license-oss">
891
- <h3 style="margin-top: 0; color: #1E88E5; display: flex; align-items: center;">
892
- <span>OSS Execution</span>
893
- <span style="margin-left: auto; font-size: 0.7em; background: #1E88E5; color: white; padding: 3px 10px; border-radius: 12px;">Advisory</span>
894
- </h3>
895
- <div style="text-align: center; margin: 25px 0;">
896
- <div style="font-size: 52px; font-weight: bold; color: #1E88E5;">--</div>
897
- <div style="font-size: 14px; color: #666;">Risk Score</div>
898
- </div>
899
- <div style="background: rgba(244, 67, 54, 0.08); padding: 16px; border-radius: 8px; margin: 12px 0; border-left: 4px solid #F44336;">
900
- <strong style="color: #D32F2F;">🚨 Without Enterprise License:</strong><br>
901
- <div style="font-size: 0.9em; color: #666; margin-top: 8px;">
902
- β€’ <strong>$3.9M</strong> avg data breach risk<br>
903
- β€’ <strong>$300k/hr</strong> service disruption<br>
904
- β€’ <strong>Up to $20M</strong> compliance fines
905
- </div>
906
- </div>
907
- <div style="background: rgba(255, 152, 0, 0.08); padding: 14px; border-radius: 8px; margin-top: 18px;">
908
- <strong style="color: #F57C00;">πŸ“‹ Advisory Recommendation:</strong><br>
909
- <span id="oss-recommendation" style="font-size: 0.9em;">Awaiting execution test...</span>
910
- </div>
911
- </div>
912
- """)
913
-
914
- # Enterprise Results
915
- with gr.Column(scale=1):
916
- enterprise_results = gr.HTML(f"""
917
- <div class="license-card license-trial">
918
- <h3 style="margin-top: 0; color: #FFB300; display: flex; align-items: center;">
919
- <span id="enterprise-tier">Trial Edition</span>
920
- <span style="margin-left: auto; font-size: 0.7em; background: #FFB300; color: white; padding: 3px 10px; border-radius: 12px;">Mechanical</span>
921
- </h3>
922
- <div style="text-align: center; margin: 25px 0;">
923
- <div style="font-size: 52px; font-weight: bold; color: #FFB300;" id="enterprise-risk">--</div>
924
- <div style="font-size: 14px; color: #666;">Risk Score</div>
925
- </div>
926
-
927
- <div id="gates-visualization">
928
- <div style="font-size: 13px; color: #666; margin-bottom: 12px; font-weight: 500;">Mechanical Gates:</div>
929
- <div class="gate-container">
930
- <div class="gate gate-pending">1</div>
931
- <div class="gate-line"></div>
932
- <div class="gate gate-pending">2</div>
933
- <div class="gate-line"></div>
934
- <div class="gate gate-pending">3</div>
935
- </div>
936
- </div>
937
-
938
- <div style="background: rgba(255, 152, 0, 0.08); padding: 16px; border-radius: 8px; margin-top: 22px;">
939
- <strong style="color: #F57C00;">πŸ›‘οΈ Mechanical Enforcement:</strong><br>
940
- <span id="enterprise-action" style="font-size: 0.9em;">Awaiting execution test...</span>
941
- </div>
942
- </div>
943
- """)
944
-
945
- # ===== ACTION HISTORY =====
946
- with gr.Row():
947
- with gr.Column():
948
- gr.Markdown("### πŸ“Š Enterprise Action History")
949
- action_history = gr.HTML("""
950
- <div style="border: 1px solid #E0E0E0; border-radius: 10px; padding: 20px; background: #fafafa; box-shadow: 0 4px 12px rgba(0,0,0,0.05);">
951
- <table style="width: 100%; border-collapse: collapse; font-size: 13px;">
952
- <thead>
953
- <tr style="background: linear-gradient(to right, #f5f5f5, #fafafa);">
954
- <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left; font-weight: 600; color: #555;">Time</th>
955
- <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left; font-weight: 600; color: #555;">Action</th>
956
- <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left; font-weight: 600; color: #555;">Risk</th>
957
- <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left; font-weight: 600; color: #555;">License</th>
958
- <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left; font-weight: 600; color: #555;">Gates</th>
959
- <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left; font-weight: 600; color: #555;">Result</th>
960
- <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left; font-weight: 600; color: #555;">ARF</th>
961
- </tr>
962
- </thead>
963
- <tbody>
964
- <tr>
965
- <td colspan="7" style="text-align: center; color: #999; padding: 40px; font-style: italic;">
966
- No execution tests yet. Test an action to see mechanical gates in action.
967
- </td>
968
- </tr>
969
- </tbody>
970
- </table>
971
- </div>
972
- """)
973
-
974
- # ===== ROI CALCULATOR =====
975
- with gr.Row():
976
- with gr.Column():
977
- gr.Markdown("### πŸ’° Enterprise ROI Calculator")
978
-
979
- with gr.Row():
980
- current_tier = gr.Dropdown(
981
- label="Current License Tier",
982
- choices=["OSS", "Trial", "Starter", "Professional"],
983
- value="OSS",
984
- scale=1
985
- )
986
-
987
- target_tier = gr.Dropdown(
988
- label="Target License Tier",
989
- choices=["Starter", "Professional", "Enterprise"],
990
- value="Enterprise",
991
- scale=1
992
- )
993
-
994
- calculate_roi_btn = gr.Button("πŸ“ˆ Calculate Enterprise ROI", variant="secondary")
995
-
996
- roi_result = gr.HTML("""
997
- <div class="roi-calculator">
998
- <h4 style="margin-top: 0; margin-bottom: 20px; font-size: 1.2em;">Enterprise ROI Analysis</h4>
999
- <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 25px;">
1000
- <div>
1001
- <div style="font-size: 13px; opacity: 0.95; letter-spacing: 0.5px;">Annual Savings</div>
1002
- <div style="font-size: 36px; font-weight: bold; margin: 8px 0;">$--</div>
1003
- </div>
1004
- <div>
1005
- <div style="font-size: 13px; opacity: 0.95; letter-spacing: 0.5px;">Payback Period</div>
1006
- <div style="font-size: 36px; font-weight: bold; margin: 8px 0;">-- mo</div>
1007
- </div>
1008
- </div>
1009
- <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 25px;">
1010
- <div style="font-size: 12px;">
1011
- <div style="opacity: 0.9;">πŸ“Š Incident Prevention</div>
1012
- <div style="font-weight: bold; font-size: 14px;">92% reduction</div>
1013
- </div>
1014
- <div style="font-size: 12px;">
1015
- <div style="opacity: 0.9;">⏱️ Operational Efficiency</div>
1016
- <div style="font-weight: bold; font-size: 14px;">15 min/decision</div>
1017
- </div>
1018
- </div>
1019
- <div style="font-size: 11px; margin-top: 20px; opacity: 0.9; line-height: 1.5;">
1020
- Based on enterprise metrics: $3.9M avg breach cost, $150/hr engineer, 250 operating days
1021
- </div>
1022
- </div>
1023
- """)
1024
-
1025
- # ===== TRIAL CTA =====
1026
- with gr.Row():
1027
- with gr.Column():
1028
- gr.Markdown("""
1029
- ## 🎁 Enterprise Trial Offer
1030
-
1031
- <div style="background: linear-gradient(135deg, #FF6F00, #FFB300); color: white; padding: 18px 30px; border-radius: 12px; text-align: center; font-weight: bold; margin: 15px 0; box-shadow: 0 6px 20px rgba(255, 111, 0, 0.3);">
1032
- ⏳ 14-Day Enterprise Trial β€’ <span style="background: white; color: #FF6F00; padding: 4px 12px; border-radius: 6px; margin: 0 8px; font-weight: bold;">Limited Time</span>
1033
- </div>
1034
- """)
1035
-
1036
- with gr.Row():
1037
- email_input = gr.Textbox(
1038
- label="Enterprise Email",
1039
- placeholder="Enter your work email for enterprise trial license",
1040
- scale=3
1041
- )
1042
-
1043
- request_trial_btn = gr.Button("πŸš€ Request Enterprise Trial", variant="primary", scale=1)
1044
-
1045
- trial_output = gr.HTML("""
1046
- <div style="text-align: center; padding: 25px; background: #f8f9fa; border-radius: 12px; border: 1px solid #E0E0E0;">
1047
- <div style="font-size: 0.95em; color: #555; line-height: 1.6;">
1048
- <strong style="color: #333;">Enterprise Trial Includes:</strong><br>
1049
- β€’ Full mechanical enforcement gates<br>
1050
- β€’ Autonomous execution levels (Low/High Risk)<br>
1051
- β€’ Rollback feasibility validation<br>
1052
- β€’ Admin approval workflows<br>
1053
- β€’ Enterprise support & compliance reporting
1054
- </div>
1055
- </div>
1056
- """)
1057
-
1058
- # ===== ENTERPRISE FOOTER =====
1059
- gr.Markdown(f"""
1060
- ---
1061
-
1062
- <div style="text-align: center; color: #666; font-size: 0.9em; padding: 20px 0;">
1063
- <strong style="font-size: 1.1em; color: #333;">ARF {ARF_UNIFIED_STATUS['version']} - Enterprise AI Execution Authority Platform</strong><br>
1064
- <div style="margin: 15px 0; display: flex; justify-content: center; align-items: center; gap: 10px; flex-wrap: wrap;">
1065
- <span class="{arf_badge_class}" style="font-size: 0.8em;">{arf_display}</span>
1066
- <span class="hf-badge" style="font-size: 0.8em;">πŸ€— Hugging Face Spaces</span>
1067
- <span style="background: linear-gradient(135deg, #4CAF50, #2E7D32); color: white; padding: 5px 12px; border-radius: 16px; font-size: 0.8em; font-weight: bold;">
1068
- SOC 2 Type II Certified
1069
- </span>
1070
- <span style="background: linear-gradient(135deg, #2196F3, #1565C0); color: white; padding: 5px 12px; border-radius: 16px; font-size: 0.8em; font-weight: bold;">
1071
- GDPR Compliant
1072
- </span>
1073
- <span style="background: linear-gradient(135deg, #FF9800, #F57C00); color: white; padding: 5px 12px; border-radius: 16px; font-size: 0.8em; font-weight: bold;">
1074
- ISO 27001
1075
- </span>
1076
- </div>
1077
- <div style="margin-top: 12px; color: #4CAF50; font-weight: 500;">
1078
- βœ“ 99.9% SLA β€’ βœ“ 24/7 Enterprise Support β€’ βœ“ On-prem Deployment Available
1079
- </div>
1080
- <div style="margin-top: 20px; font-size: 0.85em;">
1081
- Β© 2024 ARF Technologies β€’
1082
- <a href="https://github.com/petter2025/agentic-reliability-framework" style="color: #1E88E5; text-decoration: none; font-weight: 500;">GitHub</a> β€’
1083
- <a href="#" style="color: #1E88E5; text-decoration: none; font-weight: 500;">Documentation</a> β€’
1084
- <a href="mailto:sales@arf.dev" style="color: #1E88E5; text-decoration: none; font-weight: 500;">Enterprise Sales</a> β€’
1085
- <a href="#" style="color: #1E88E5; text-decoration: none; font-weight: 500;">Investment Deck</a>
1086
- </div>
1087
- <div style="margin-top: 15px; font-size: 0.75em; color: #888; max-width: 800px; margin-left: auto; margin-right: auto; line-height: 1.5;">
1088
- <strong>Business Model:</strong> License-Gated Execution Authority β€’
1089
- <strong>Target Market:</strong> Enterprise AI Infrastructure β€’
1090
- <strong>Investment Sought:</strong> $150,000 for 10% equity β€’
1091
- <strong>Founder:</strong> Juan D. Petter
1092
- </div>
1093
- </div>
1094
- """)
1095
-
1096
- # ===== EVENT HANDLERS =====
1097
- def update_context(scenario_name):
1098
- """Update context"""
1099
- scenarios = {
1100
- "DROP DATABASE production": "Environment: production, User: junior_dev, Time: 2AM, Backup: 24h old, Compliance: PCI-DSS",
1101
- "DELETE FROM users WHERE status='active'": "Environment: production, User: admin, Records: 50,000, Backup: none, Business Hours: Yes",
1102
- "GRANT admin TO new_intern": "Environment: production, User: team_lead, New User: intern, MFA: false, Approval: Pending",
1103
- "SHUTDOWN production cluster": "Environment: production, User: devops, Nodes: 50, Redundancy: none, Business Impact: Critical",
1104
- "UPDATE financial_records SET balance=0": "Environment: production, User: finance_bot, Table: financial_records, Audit Trail: Incomplete"
1105
- }
1106
- return scenarios.get(scenario_name, "Environment: production, Criticality: high")
1107
-
1108
- def test_action(scenario_name, context_text, license_text):
1109
- """Test action with unified detection"""
1110
- # Update license
1111
- demo_state.update_license(license_text)
1112
-
1113
- # Calculate risk
1114
- context = {}
1115
- for item in context_text.split(','):
1116
- if ':' in item:
1117
- key, value = item.split(':', 1)
1118
- context[key.strip().lower()] = value.strip()
1119
-
1120
- # Simple risk calculation
1121
- risk_score = 0.3
1122
- if 'DROP' in scenario_name.upper() and 'DATABASE' in scenario_name.upper():
1123
- risk_score = 0.85
1124
- elif 'DELETE' in scenario_name.upper():
1125
- risk_score = 0.65
1126
- elif 'GRANT' in scenario_name.upper():
1127
- risk_score = 0.55
1128
- elif 'SHUTDOWN' in scenario_name.upper():
1129
- risk_score = 0.9
1130
- elif 'UPDATE' in scenario_name.upper() and 'FINANCIAL' in scenario_name.upper():
1131
- risk_score = 0.75
1132
-
1133
- # Context adjustments
1134
- if context.get('environment') == 'production':
1135
- risk_score *= 1.5
1136
- if context.get('user', '').lower() in ['junior', 'intern']:
1137
- risk_score *= 1.3
1138
- if context.get('backup') in ['none', 'none available']:
1139
- risk_score *= 1.6
1140
-
1141
- risk_score = min(0.95, max(0.1, risk_score))
1142
-
1143
- # Mechanical gates
1144
- gates_result = simulate_unified_gates(risk_score, demo_state.license_state['current_tier'])
1145
-
1146
- # Action data
1147
- action_data = {
1148
- 'time': datetime.now().strftime("%H:%M:%S"),
1149
- 'action': scenario_name[:35] + "..." if len(scenario_name) > 35 else scenario_name,
1150
- 'risk_score': risk_score,
1151
- 'license_tier': demo_state.license_state['current_tier'],
1152
- 'gates_passed': gates_result['passed'],
1153
- 'total_gates': gates_result['total'],
1154
- 'execution_allowed': gates_result['all_passed'],
1155
- 'arf_status': 'REAL' if ARF_UNIFIED_STATUS['is_real'] else 'SIM'
1156
- }
1157
-
1158
- demo_state.add_action(action_data)
1159
-
1160
- # Format risk
1161
- formatted_risk = format_unified_risk(risk_score)
1162
-
1163
- # OSS recommendation
1164
- if risk_score > 0.8:
1165
- oss_rec = "🚨 CRITICAL RISK: Would cause catastrophic failure. Enterprise license required."
1166
- elif risk_score > 0.6:
1167
- oss_rec = "⚠️ HIGH RISK: Potential $5M+ financial exposure. Upgrade to Enterprise."
1168
- elif risk_score > 0.4:
1169
- oss_rec = "πŸ”Ά MODERATE RISK: Requires human review. Enterprise automates approval."
1170
- else:
1171
- oss_rec = "βœ… LOW RISK: Appears safe but cannot execute without license."
1172
-
1173
- # Enterprise enforcement
1174
- if gates_result['all_passed']:
1175
- enforcement = "βœ… Action ALLOWED - All mechanical gates passed"
1176
- elif any(gate.get('approval_pending') for gate in gates_result['gates']):
1177
- enforcement = "πŸ”„ ADMIN APPROVAL REQUIRED - Manual escalation needed"
1178
- else:
1179
- enforcement = "❌ Action BLOCKED - Failed mechanical gates"
1180
-
1181
- # Gates visualization
1182
- gates_html = ""
1183
- if gates_result['gates']:
1184
- gates_visualization = ""
1185
- for i, gate in enumerate(gates_result['gates']):
1186
- gate_class = "gate-passed" if gate['passed'] else "gate-failed"
1187
- gates_visualization += f"""
1188
- <div class="gate {gate_class}">{i+1}</div>
1189
- {'<div class="gate-line"></div>' if i < len(gates_result['gates'])-1 else ''}
1190
- """
1191
-
1192
- gates_status = f"{gates_result['passed']}/{gates_result['total']} gates passed"
1193
-
1194
- gates_html = f"""
1195
- <div style="font-size: 13px; color: #666; margin-bottom: 12px; font-weight: 500;">
1196
- Mechanical Gates: {gates_status}
1197
- </div>
1198
- <div class="gate-container">
1199
- {gates_visualization}
1200
- </div>
1201
- """
1202
-
1203
- # Tier info
1204
- tier_data = {
1205
- 'oss': {'color': '#1E88E5', 'bg': '#E3F2FD', 'name': 'OSS Edition'},
1206
- 'trial': {'color': '#FFB300', 'bg': '#FFF8E1', 'name': 'Trial Edition'},
1207
- 'professional': {'color': '#FF6F00', 'bg': '#FFEBEE', 'name': 'Professional Edition'},
1208
- 'enterprise': {'color': '#D84315', 'bg': '#FBE9E7', 'name': 'Enterprise Edition'}
1209
- }
1210
-
1211
- current_tier = demo_state.license_state['current_tier']
1212
- tier_info = tier_data.get(current_tier, tier_data['oss'])
1213
-
1214
- # Update panels
1215
- oss_html = f"""
1216
- <div class="license-card license-oss">
1217
- <h3 style="margin-top: 0; color: #1E88E5; display: flex; align-items: center;">
1218
- <span>OSS Execution</span>
1219
- <span style="margin-left: auto; font-size: 0.7em; background: #1E88E5; color: white; padding: 3px 10px; border-radius: 12px;">Advisory</span>
1220
- </h3>
1221
- <div style="text-align: center; margin: 25px 0;">
1222
- <div style="font-size: 52px; font-weight: bold; color: #1E88E5;">{formatted_risk}</div>
1223
- <div style="font-size: 14px; color: #666;">Risk Score</div>
1224
- </div>
1225
- <div style="background: rgba(244, 67, 54, 0.08); padding: 16px; border-radius: 8px; margin: 12px 0; border-left: 4px solid #F44336;">
1226
- <strong style="color: #D32F2F;">🚨 Without Enterprise License:</strong><br>
1227
- <div style="font-size: 0.9em; color: #666; margin-top: 8px;">
1228
- β€’ <strong>${risk_score*5000000:,.0f}</strong> potential financial exposure<br>
1229
- β€’ <strong>$300k/hr</strong> service disruption risk<br>
1230
- β€’ <strong>Up to $20M</strong> compliance fines
1231
- </div>
1232
- </div>
1233
- <div style="background: rgba(255, 152, 0, 0.08); padding: 14px; border-radius: 8px; margin-top: 18px;">
1234
- <strong style="color: #F57C00;">πŸ“‹ Advisory Recommendation:</strong><br>
1235
- <span style="font-size: 0.9em;">{oss_rec}</span>
1236
- </div>
1237
- </div>
1238
- """
1239
-
1240
- enterprise_html = f"""
1241
- <div class="license-card" style="border-top: 4px solid {tier_info['color']}; background: linear-gradient(to bottom, {tier_info['bg']}, white);">
1242
- <h3 style="margin-top: 0; color: {tier_info['color']}; display: flex; align-items: center;">
1243
- <span>{tier_info['name']}</span>
1244
- <span style="margin-left: auto; font-size: 0.7em; background: {tier_info['color']}; color: white; padding: 3px 10px; border-radius: 12px;">Mechanical</span>
1245
- </h3>
1246
- <div style="text-align: center; margin: 25px 0;">
1247
- <div style="font-size: 52px; font-weight: bold; color: {tier_info['color']};">{formatted_risk}</div>
1248
- <div style="font-size: 14px; color: #666;">Risk Score</div>
1249
- </div>
1250
-
1251
- {gates_html}
1252
-
1253
- <div style="background: rgba(255, 152, 0, 0.08); padding: 16px; border-radius: 8px; margin-top: 22px;">
1254
- <strong style="color: {tier_info['color']};">πŸ›‘οΈ Mechanical Enforcement:</strong><br>
1255
- <span style="font-size: 0.9em;">{enforcement}</span>
1256
- </div>
1257
- </div>
1258
- """
1259
-
1260
- license_html = f"""
1261
- <div class="license-card" style="border-top: 4px solid {tier_info['color']}; background: linear-gradient(to bottom, {tier_info['bg']}, white);">
1262
- <h3 style="margin-top: 0; color: {tier_info['color']}; display: flex; align-items: center;">
1263
- <span>{tier_info['name']}</span>
1264
- <span style="margin-left: auto; font-size: 0.7em; background: {tier_info['color']}; color: white; padding: 3px 10px; border-radius: 12px;">Active</span>
1265
- </h3>
1266
- <p style="color: #666; font-size: 0.9em; margin-bottom: 15px;">
1267
- {'⚠️ <strong>14-Day Trial</strong><br>Full mechanical enforcement' if current_tier == 'trial' else 'βœ… <strong>Enterprise License</strong><br>Mechanical gates active' if current_tier != 'oss' else '⚠️ <strong>OSS Edition</strong><br>No mechanical enforcement'}
1268
- </p>
1269
- <div style="background: rgba(30, 136, 229, 0.1); padding: 12px; border-radius: 8px; border-left: 3px solid {tier_info['color']};">
1270
- <div style="font-size: 0.85em; color: {tier_info['color']};">
1271
- <strong>Execution Level:</strong> {demo_state.license_state['execution_level']}<br>
1272
- <strong>Risk Prevention:</strong> {92 if current_tier == 'enterprise' else 85 if current_tier == 'professional' else 50 if current_tier == 'trial' else 0}%<br>
1273
- <strong>ARF Status:</strong> {arf_display}
1274
- </div>
1275
- </div>
1276
- </div>
1277
- """
1278
-
1279
- # History
1280
- history_rows = ""
1281
- for entry in demo_state.action_history:
1282
- risk_text = format_unified_risk(entry['risk_score'])
1283
- gates_text = f"{entry['gates_passed']}/{entry['total_gates']}"
1284
- gates_color = "#4CAF50" if entry['execution_allowed'] else "#F44336"
1285
- result_emoji = "βœ…" if entry['execution_allowed'] else "❌"
1286
- arf_emoji = "βœ…" if entry['arf_status'] == 'REAL' else "⚠️"
1287
-
1288
- history_rows += f"""
1289
- <tr>
1290
- <td style="padding: 12px; border-bottom: 1px solid #eee; color: #555;">{entry['time']}</td>
1291
- <td style="padding: 12px; border-bottom: 1px solid #eee; color: #555;" title="{entry['action']}">{entry['action']}</td>
1292
- <td style="padding: 12px; border-bottom: 1px solid #eee;">{risk_text}</td>
1293
- <td style="padding: 12px; border-bottom: 1px solid #eee; color: #555; font-weight: 500;">{entry['license_tier'].upper()}</td>
1294
- <td style="padding: 12px; border-bottom: 1px solid #eee; color: {gates_color}; font-weight: bold;">{gates_text}</td>
1295
- <td style="padding: 12px; border-bottom: 1px solid #eee; font-size: 16px;">{result_emoji}</td>
1296
- <td style="padding: 12px; border-bottom: 1px solid #eee; text-align: center; font-size: 16px;">{arf_emoji}</td>
1297
- </tr>
1298
- """
1299
-
1300
- history_html = f"""
1301
- <div style="border: 1px solid #E0E0E0; border-radius: 10px; padding: 20px; background: #fafafa; box-shadow: 0 4px 12px rgba(0,0,0,0.05);">
1302
- <table style="width: 100%; border-collapse: collapse; font-size: 13px;">
1303
- <thead>
1304
- <tr style="background: linear-gradient(to right, #f5f5f5, #fafafa);">
1305
- <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left; font-weight: 600; color: #555;">Time</th>
1306
- <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left; font-weight: 600; color: #555;">Action</th>
1307
- <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left; font-weight: 600; color: #555;">Risk</th>
1308
- <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left; font-weight: 600; color: #555;">License</th>
1309
- <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left; font-weight: 600; color: #555;">Gates</th>
1310
- <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left; font-weight: 600; color: #555;">Result</th>
1311
- <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left; font-weight: 600; color: #555;">ARF</th>
1312
- </tr>
1313
- </thead>
1314
- <tbody>
1315
- {history_rows}
1316
- </tbody>
1317
- </table>
1318
- </div>
1319
- """
1320
-
1321
- return oss_html, enterprise_html, license_html, history_html
1322
-
1323
- def generate_trial():
1324
- """Generate trial license"""
1325
- license_key = generate_unified_trial_license()
1326
- demo_state.stats['trial_licenses'] += 1
1327
-
1328
- return license_key, f"""
1329
- <div style="text-align: center; padding: 25px; background: linear-gradient(135deg, #FFB300, #FF9800); color: white; border-radius: 12px; box-shadow: 0 8px 25px rgba(255, 179, 0, 0.3);">
1330
- <h3 style="margin-top: 0; margin-bottom: 20px;">πŸŽ‰ Enterprise Trial License Generated!</h3>
1331
- <div style="background: white; color: #333; padding: 18px; border-radius: 8px; font-family: 'Monaco', 'Courier New', monospace; margin: 15px 0; font-size: 15px; letter-spacing: 1px; border: 2px dashed #FFB300;">
1332
- {license_key}
1333
- </div>
1334
- <p style="margin-bottom: 20px; font-size: 1.05em;">Copy this key and paste it into the License Key field above.</p>
1335
- <div style="background: rgba(255,255,255,0.2); padding: 18px; border-radius: 8px; margin-top: 15px;">
1336
- <div style="font-size: 0.95em; line-height: 1.6;">
1337
- ⏳ <strong>14 days</strong> remaining β€’ πŸš€ <strong>Full mechanical enforcement</strong><br>
1338
- πŸ›‘οΈ <strong>Autonomous execution levels</strong> β€’ πŸ“§ <strong>Enterprise support included</strong>
1339
- </div>
1340
- </div>
1341
- </div>
1342
- """
1343
-
1344
- def calculate_roi(current, target):
1345
- """Calculate ROI"""
1346
- # Simple ROI calculation
1347
- savings = {
1348
- ('OSS', 'Enterprise'): {'savings': 3850000, 'payback': 3.2},
1349
- ('OSS', 'Professional'): {'savings': 2850000, 'payback': 5.6},
1350
- ('OSS', 'Starter'): {'savings': 1850000, 'payback': 8.4},
1351
- ('Professional', 'Enterprise'): {'savings': 1200000, 'payback': 2.1},
1352
- }
1353
-
1354
- key = (current, target)
1355
- if key in savings:
1356
- data = savings[key]
1357
- else:
1358
- data = {'savings': 1500000, 'payback': 6.0}
1359
-
1360
- return f"""
1361
- <div class="roi-calculator">
1362
- <h4 style="margin-top: 0; margin-bottom: 20px; font-size: 1.2em;">Enterprise ROI: {current} β†’ {target}</h4>
1363
- <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 25px;">
1364
- <div>
1365
- <div style="font-size: 13px; opacity: 0.95; letter-spacing: 0.5px;">Annual Savings</div>
1366
- <div style="font-size: 36px; font-weight: bold; margin: 8px 0;">${data['savings']:,}</div>
1367
- </div>
1368
- <div>
1369
- <div style="font-size: 13px; opacity: 0.95; letter-spacing: 0.5px;">Payback Period</div>
1370
- <div style="font-size: 36px; font-weight: bold; margin: 8px 0;">{data['payback']} mo</div>
1371
- </div>
1372
- </div>
1373
- <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 25px;">
1374
- <div style="font-size: 12px;">
1375
- <div style="opacity: 0.9;">πŸ“Š ROI Percentage</div>
1376
- <div style="font-weight: bold; font-size: 14px;">{int(data['savings']/15000*100)}%</div>
1377
- </div>
1378
- <div style="font-size: 12px;">
1379
- <div style="opacity: 0.9;">πŸ’° Monthly Value</div>
1380
- <div style="font-weight: bold; font-size: 14px;">${int(data['savings']/12):,}</div>
1381
- </div>
1382
- </div>
1383
- <div style="font-size: 11px; margin-top: 20px; opacity: 0.9; line-height: 1.5;">
1384
- Based on enterprise metrics: $3.9M avg breach cost, $150/hr engineer, 250 operating days
1385
- </div>
1386
- </div>
1387
- """
1388
-
1389
- def request_trial(email):
1390
- """Request trial"""
1391
- if not email or "@" not in email:
1392
- return """
1393
- <div style="text-align: center; padding: 25px; background: #FFF8E1; border-radius: 12px; border: 1px solid #FFE082;">
1394
- <div style="color: #FF9800; font-size: 52px; margin-bottom: 15px;">⚠️</div>
1395
- <h4 style="margin: 0 0 10px 0; color: #F57C00;">Enterprise Email Required</h4>
1396
- <p style="color: #666; margin: 0;">Please enter a valid enterprise email address to receive your trial license.</p>
1397
- </div>
1398
- """
1399
-
1400
- license_key = generate_unified_trial_license()
1401
- demo_state.stats['trial_licenses'] += 1
1402
-
1403
- return f"""
1404
- <div style="text-align: center; padding: 25px; background: linear-gradient(135deg, #4CAF50, #2E7D32); color: white; border-radius: 12px; box-shadow: 0 8px 25px rgba(76, 175, 80, 0.3);">
1405
- <div style="font-size: 52px; margin-bottom: 10px;">πŸŽ‰</div>
1406
- <h3 style="margin-top: 0; margin-bottom: 15px;">Enterprise Trial License Sent!</h3>
1407
- <p style="margin-bottom: 20px; font-size: 1.05em;">Your 14-day enterprise trial license has been sent to:</p>
1408
- <div style="background: white; color: #333; padding: 14px; border-radius: 8px; margin: 15px 0; font-weight: bold; font-size: 1.1em; border: 2px solid #A5D6A7;">
1409
- {email}
1410
- </div>
1411
- <div style="background: rgba(255,255,255,0.2); padding: 20px; border-radius: 8px; margin-top: 20px;">
1412
- <div style="font-family: 'Monaco', 'Courier New', monospace; font-size: 1.1em; letter-spacing: 1px; margin-bottom: 15px;">{license_key}</div>
1413
- <div style="font-size: 0.95em; line-height: 1.6; opacity: 0.95;">
1414
- ⏳ <strong>14-day enterprise trial</strong><br>
1415
- πŸš€ <strong>Full mechanical gates & autonomous execution</strong><br>
1416
- πŸ›‘οΈ <strong>Rollback feasibility & admin approval workflows</strong>
1417
- </div>
1418
- </div>
1419
- <div style="margin-top: 20px; font-size: 0.9em; opacity: 0.9;">
1420
- Join Fortune 500 companies using ARF for safe AI execution
1421
- </div>
1422
- </div>
1423
- """
1424
-
1425
- # Connect handlers
1426
- scenario.change(
1427
- fn=update_context,
1428
- inputs=[scenario],
1429
- outputs=[context]
1430
- )
1431
-
1432
- test_btn.click(
1433
- fn=test_action,
1434
- inputs=[scenario, context, license_key],
1435
- outputs=[oss_results, enterprise_results, license_display, action_history]
1436
- )
1437
-
1438
- trial_btn.click(
1439
- fn=generate_trial,
1440
- inputs=[],
1441
- outputs=[license_key, trial_output]
1442
- )
1443
-
1444
- calculate_roi_btn.click(
1445
- fn=calculate_roi,
1446
- inputs=[current_tier, target_tier],
1447
- outputs=[roi_result]
1448
- )
1449
-
1450
- request_trial_btn.click(
1451
- fn=request_trial,
1452
- inputs=[email_input],
1453
- outputs=[trial_output]
1454
- )
1455
-
1456
- return demo
1457
-
1458
- # ============== MAIN EXECUTION ==============
1459
- if __name__ == "__main__":
1460
- print("\n" + "="*80)
1461
- print("πŸš€ LAUNCHING UNIFIED ARF 3.3.9 DEMO WITH FIXED STATUS DISPLAY")
1462
- print("="*80)
1463
-
1464
- demo = create_unified_demo()
1465
- demo.launch(
1466
- server_name="0.0.0.0",
1467
- server_port=7860,
1468
- share=False,
1469
- debug=False
1470
- )