petter2025 commited on
Commit
8767cd1
ยท
verified ยท
1 Parent(s): 954d9ca

Update hf_demo.py

Browse files
Files changed (1) hide show
  1. hf_demo.py +222 -812
hf_demo.py CHANGED
@@ -1,9 +1,9 @@
1
- """
2
- ARF 3.3.9 - Enterprise Demo with Enhanced Psychology & Mathematics
3
- FIXED: Shows "REAL ARF OSS 3.3.9" when real ARF is installed
4
- ADDED: PhD-level mathematical sophistication with Bayesian confidence
5
- ADDED: Prospect Theory psychological optimization
6
- """
7
 
8
  import gradio as gr
9
  import time
@@ -16,7 +16,6 @@ import importlib
16
  from datetime import datetime, timedelta
17
  from typing import Dict, List, Optional, Tuple, Any, Union
18
  import numpy as np
19
- import pandas as pd
20
 
21
  # Import enhanced engines
22
  try:
@@ -29,7 +28,7 @@ except ImportError as e:
29
  print("๐Ÿ“ Creating fallback engines...")
30
  ARF_ENGINE_ENHANCED = False
31
 
32
- # Fallback classes (simplified versions)
33
  class EnhancedARFEngine:
34
  def __init__(self):
35
  self.arf_status = "SIMULATION"
@@ -45,25 +44,21 @@ except ImportError as e:
45
  def generate_comprehensive_insights(self, *args, **kwargs):
46
  return {"psychological_summary": "Basic psychological framing"}
47
 
48
- # ============== UNIFIED ARF DETECTION (FIXED) ==============
49
  print("=" * 80)
50
  print("๐Ÿš€ ARF 3.3.9 ENHANCED DEMO INITIALIZATION")
51
  print("๐Ÿ” UNIFIED DETECTION: Single Source of Truth")
52
  print("=" * 80)
53
 
54
  def detect_unified_arf() -> Dict[str, Any]:
55
- """
56
- Unified ARF detection that FIXES the "SIMULATED" display bug
57
- Returns a single source of truth for the entire demo
58
- """
59
  print("\n๐Ÿ” INITIATING UNIFIED ARF DETECTION...")
60
 
61
- # Try REAL ARF OSS 3.3.9 first (from requirements.txt)
62
  try:
63
  print("๐Ÿ” Attempting import: agentic_reliability_framework")
64
  import agentic_reliability_framework as arf
65
 
66
- # Verify this is real ARF
67
  version = getattr(arf, '__version__', '3.3.9')
68
  print(f"โœ… REAL ARF OSS {version} DETECTED")
69
 
@@ -139,171 +134,13 @@ print(f" Display: {ARF_UNIFIED_STATUS['display_text']}")
139
  print(f" Real ARF: {'โœ… YES' if ARF_UNIFIED_STATUS['is_real'] else 'โš ๏ธ SIMULATION'}")
140
  print(f" Version: {ARF_UNIFIED_STATUS['version']}")
141
  print(f" Source: {ARF_UNIFIED_STATUS['source']}")
142
- print(f" Unified Truth: {'โœ… ACTIVE' if ARF_UNIFIED_STATUS.get('unified_truth', False) else 'โŒ INACTIVE'}")
143
  print(f"{'='*80}\n")
144
 
145
- # ============== INITIALIZE ENHANCED ENGINES ==============
146
  arf_engine = EnhancedARFEngine()
147
  psychology_engine = EnhancedPsychologyEngine()
148
 
149
- # Set ARF status in engine
150
- arf_engine.set_arf_status(ARF_UNIFIED_STATUS['status'])
151
-
152
- # ============== ENHANCED DEMO STATE ==============
153
- class EnhancedDemoState:
154
- """Enhanced demo state with mathematical tracking"""
155
-
156
- def __init__(self, arf_status: Dict[str, Any]):
157
- # Bind to unified ARF status
158
- self.arf_status = arf_status
159
-
160
- # Mathematical statistics
161
- self.stats = {
162
- 'actions_tested': 0,
163
- 'risks_prevented': 0,
164
- 'high_risk_blocked': 0,
165
- 'license_validations': 0,
166
- 'mechanical_gates_triggered': 0,
167
- 'total_processing_time_ms': 0,
168
- 'average_confidence': 0.0,
169
- 'average_risk': 0.0,
170
- 'start_time': time.time(),
171
- 'real_arf_used': arf_status['is_real'],
172
- 'arf_version': arf_status['version'],
173
- 'display_text': arf_status['display_text']
174
- }
175
-
176
- self.action_history = []
177
- self.license_state = {
178
- 'current_tier': 'oss',
179
- 'current_license': None,
180
- 'execution_level': 'ADVISORY_ONLY'
181
- }
182
-
183
- def update_license(self, license_key: Optional[str] = None):
184
- """Update license state with enhanced validation"""
185
- if not license_key:
186
- self.license_state = {
187
- 'current_tier': 'oss',
188
- 'current_license': None,
189
- 'execution_level': 'ADVISORY_ONLY'
190
- }
191
- return
192
-
193
- license_upper = license_key.upper()
194
-
195
- if 'ARF-TRIAL' in license_upper:
196
- self.license_state = {
197
- 'current_tier': 'trial',
198
- 'current_license': license_key,
199
- 'execution_level': 'OPERATOR_REVIEW',
200
- 'trial_expiry': time.time() + (14 * 24 * 3600),
201
- 'days_remaining': 14
202
- }
203
- self.stats['trial_licenses'] = self.stats.get('trial_licenses', 0) + 1
204
-
205
- elif 'ARF-ENTERPRISE' in license_upper:
206
- self.license_state = {
207
- 'current_tier': 'enterprise',
208
- 'current_license': license_key,
209
- 'execution_level': 'AUTONOMOUS_HIGH'
210
- }
211
- self.stats['enterprise_upgrades'] = self.stats.get('enterprise_upgrades', 0) + 1
212
-
213
- elif 'ARF-PRO' in license_upper:
214
- self.license_state = {
215
- 'current_tier': 'professional',
216
- 'current_license': license_key,
217
- 'execution_level': 'AUTONOMOUS_LOW'
218
- }
219
-
220
- elif 'ARF-STARTER' in license_upper:
221
- self.license_state = {
222
- 'current_tier': 'starter',
223
- 'current_license': license_key,
224
- 'execution_level': 'SUPERVISED'
225
- }
226
-
227
- else:
228
- self.license_state = {
229
- 'current_tier': 'oss',
230
- 'current_license': license_key,
231
- 'execution_level': 'ADVISORY_ONLY'
232
- }
233
-
234
- def add_action(self, action_data: Dict[str, Any]):
235
- """Add action with mathematical tracking"""
236
- self.action_history.insert(0, action_data)
237
- if len(self.action_history) > 10:
238
- self.action_history = self.action_history[:10]
239
-
240
- # Update statistics with mathematical precision
241
- self.stats['actions_tested'] += 1
242
-
243
- if action_data.get('risk_score', 0) > 0.7:
244
- self.stats['high_risk_blocked'] += 1
245
-
246
- if action_data.get('gate_decision') == 'BLOCKED':
247
- self.stats['risks_prevented'] += 1
248
-
249
- if action_data.get('license_tier') != 'oss':
250
- self.stats['license_validations'] += 1
251
-
252
- if action_data.get('total_gates', 0) > 0:
253
- self.stats['mechanical_gates_triggered'] += 1
254
-
255
- # Update rolling averages
256
- n = self.stats['actions_tested']
257
- old_avg_risk = self.stats.get('average_risk', 0)
258
- old_avg_conf = self.stats.get('average_confidence', 0)
259
-
260
- new_risk = action_data.get('risk_score', 0.5)
261
- new_conf = action_data.get('confidence', 0.8)
262
-
263
- self.stats['average_risk'] = old_avg_risk + (new_risk - old_avg_risk) / n
264
- self.stats['average_confidence'] = old_avg_conf + (new_conf - old_avg_conf) / n
265
-
266
- # Add processing time
267
- self.stats['total_processing_time_ms'] = self.stats.get('total_processing_time_ms', 0) + \
268
- action_data.get('processing_time_ms', 0)
269
-
270
- def get_enhanced_stats(self) -> Dict[str, Any]:
271
- """Get enhanced statistics with mathematical insights"""
272
- elapsed_hours = (time.time() - self.stats['start_time']) / 3600
273
-
274
- # Calculate prevention rate
275
- prevention_rate = 0.0
276
- if self.stats['actions_tested'] > 0:
277
- prevention_rate = self.stats['risks_prevented'] / self.stats['actions_tested']
278
-
279
- # Calculate gate effectiveness
280
- gate_effectiveness = 0.0
281
- if self.stats['mechanical_gates_triggered'] > 0:
282
- gate_effectiveness = self.stats['risks_prevented'] / self.stats['mechanical_gates_triggered']
283
-
284
- # Calculate average processing time
285
- avg_processing_time = 0.0
286
- if self.stats['actions_tested'] > 0:
287
- avg_processing_time = self.stats['total_processing_time_ms'] / self.stats['actions_tested']
288
-
289
- return {
290
- **self.stats,
291
- 'actions_per_hour': round(self.stats['actions_tested'] / max(elapsed_hours, 0.1), 1),
292
- 'prevention_rate': round(prevention_rate * 100, 1),
293
- 'gate_effectiveness': round(gate_effectiveness * 100, 1),
294
- 'average_risk_percentage': round(self.stats['average_risk'] * 100, 1),
295
- 'average_confidence_percentage': round(self.stats['average_confidence'] * 100, 1),
296
- 'average_processing_time_ms': round(avg_processing_time, 1),
297
- 'demo_duration_hours': round(elapsed_hours, 2),
298
- 'reliability_score': min(99.99, 95 + (prevention_rate * 5)),
299
- 'current_license_tier': self.license_state['current_tier'].upper(),
300
- 'current_execution_level': self.license_state['execution_level']
301
- }
302
-
303
- # Initialize demo state
304
- demo_state = EnhancedDemoState(ARF_UNIFIED_STATUS)
305
-
306
- # ============== ENHANCED CSS WITH PSYCHOLOGICAL COLORS ==============
307
  ENHANCED_CSS = """
308
  :root {
309
  /* Mathematical Color Psychology */
@@ -312,36 +149,20 @@ ENHANCED_CSS = """
312
  --mathematical-orange: #FF9800;
313
  --mathematical-red: #F44336;
314
  --mathematical-purple: #9C27B0;
315
-
316
- /* Prospect Theory Colors */
317
- --prospect-gain: linear-gradient(135deg, #4CAF50, #2E7D32);
318
- --prospect-loss: linear-gradient(135deg, #F44336, #D32F2F);
319
-
320
- /* Bayesian Confidence Colors */
321
- --confidence-high: rgba(76, 175, 80, 0.9);
322
- --confidence-medium: rgba(255, 152, 0, 0.9);
323
- --confidence-low: rgba(244, 67, 54, 0.9);
324
-
325
- /* License Tier Colors */
326
- --oss-color: #1E88E5;
327
- --trial-color: #FFB300;
328
- --starter-color: #FF9800;
329
- --professional-color: #FF6F00;
330
- --enterprise-color: #D84315;
331
  }
332
 
333
- /* Mathematical Badges */
334
  .arf-real-badge {
335
  background: linear-gradient(135deg,
336
- #4CAF50 0%, /* Success green - trust */
337
- #2E7D32 25%, /* Deep green - stability */
338
- #1B5E20 50%, /* Forest green - growth */
339
- #0D47A1 100% /* Mathematical blue - precision */
340
  );
341
  color: white;
342
- padding: 8px 18px;
343
  border-radius: 25px;
344
- font-size: 14px;
345
  font-weight: bold;
346
  display: inline-flex;
347
  align-items: center;
@@ -350,44 +171,19 @@ ENHANCED_CSS = """
350
  box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
351
  border: 3px solid rgba(255, 255, 255, 0.4);
352
  animation: pulse-mathematical 2.5s infinite;
353
- position: relative;
354
- overflow: hidden;
355
- }
356
-
357
- .arf-real-badge::before {
358
- content: "โœ…";
359
- font-size: 18px;
360
- filter: drop-shadow(0 3px 5px rgba(0,0,0,0.3));
361
- z-index: 2;
362
- }
363
-
364
- .arf-real-badge::after {
365
- content: '';
366
- position: absolute;
367
- top: -50%;
368
- left: -50%;
369
- width: 200%;
370
- height: 200%;
371
- background: linear-gradient(
372
- 45deg,
373
- transparent 30%,
374
- rgba(255, 255, 255, 0.1) 50%,
375
- transparent 70%
376
- );
377
- animation: shine 3s infinite;
378
  }
379
 
380
  .arf-sim-badge {
381
  background: linear-gradient(135deg,
382
- #FF9800 0%, /* Warning orange - attention */
383
- #F57C00 25%, /* Deep orange - caution */
384
- #E65100 50%, /* Dark orange - urgency */
385
- #BF360C 100% /* Mathematical warning - precision */
386
  );
387
  color: white;
388
- padding: 8px 18px;
389
  border-radius: 25px;
390
- font-size: 14px;
391
  font-weight: bold;
392
  display: inline-flex;
393
  align-items: center;
@@ -397,12 +193,6 @@ ENHANCED_CSS = """
397
  border: 3px solid rgba(255, 255, 255, 0.4);
398
  }
399
 
400
- .arf-sim-badge::before {
401
- content: "โš ๏ธ";
402
- font-size: 18px;
403
- filter: drop-shadow(0 3px 5px rgba(0,0,0,0.3));
404
- }
405
-
406
  @keyframes pulse-mathematical {
407
  0% {
408
  box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7),
@@ -418,52 +208,7 @@ ENHANCED_CSS = """
418
  }
419
  }
420
 
421
- @keyframes shine {
422
- 0% { transform: translateX(-100%) translateY(-100%) rotate(45deg); }
423
- 100% { transform: translateX(100%) translateY(100%) rotate(45deg); }
424
- }
425
-
426
- /* Bayesian Confidence Visualizations */
427
- .confidence-interval {
428
- height: 30px;
429
- background: linear-gradient(90deg,
430
- var(--confidence-low) 0%,
431
- var(--confidence-medium) 50%,
432
- var(--confidence-high) 100%
433
- );
434
- border-radius: 15px;
435
- margin: 15px 0;
436
- position: relative;
437
- overflow: hidden;
438
- }
439
-
440
- .confidence-interval::before {
441
- content: '';
442
- position: absolute;
443
- top: 0;
444
- left: 0;
445
- right: 0;
446
- bottom: 0;
447
- background: repeating-linear-gradient(
448
- 90deg,
449
- transparent,
450
- transparent 5px,
451
- rgba(255, 255, 255, 0.1) 5px,
452
- rgba(255, 255, 255, 0.1) 10px
453
- );
454
- }
455
-
456
- .interval-marker {
457
- position: absolute;
458
- top: 0;
459
- height: 100%;
460
- width: 4px;
461
- background: white;
462
- transform: translateX(-50%);
463
- box-shadow: 0 0 10px rgba(0,0,0,0.5);
464
- }
465
-
466
- /* Mathematical Gate Visualization */
467
  .mathematical-gate {
468
  width: 70px;
469
  height: 70px;
@@ -480,11 +225,6 @@ ENHANCED_CSS = """
480
  transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
481
  }
482
 
483
- .mathematical-gate:hover {
484
- transform: scale(1.1) rotate(5deg);
485
- box-shadow: 0 12px 35px rgba(0,0,0,0.4);
486
- }
487
-
488
  .gate-passed {
489
  background: linear-gradient(135deg, #4CAF50, #2E7D32);
490
  animation: gate-success-mathematical 0.7s ease-out;
@@ -499,60 +239,23 @@ ENHANCED_CSS = """
499
  background: linear-gradient(135deg, #9E9E9E, #616161);
500
  }
501
 
502
- @keyframes gate-success-mathematical {
503
- 0% {
504
- transform: scale(0.5) rotate(-180deg);
505
- opacity: 0;
506
- }
507
- 60% {
508
- transform: scale(1.2) rotate(10deg);
509
- }
510
- 80% {
511
- transform: scale(0.95) rotate(-5deg);
512
- }
513
- 100% {
514
- transform: scale(1) rotate(0deg);
515
- opacity: 1;
516
- }
517
- }
518
-
519
- @keyframes gate-fail-mathematical {
520
- 0% { transform: scale(1) rotate(0deg); }
521
- 25% { transform: scale(1.1) rotate(-5deg); }
522
- 50% { transform: scale(0.9) rotate(5deg); }
523
- 75% { transform: scale(1.05) rotate(-3deg); }
524
- 100% { transform: scale(1) rotate(0deg); }
525
- }
526
-
527
- /* Prospect Theory Risk Visualization */
528
- .prospect-risk-meter {
529
- height: 35px;
530
- background: linear-gradient(90deg,
531
- #4CAF50 0%, /* Gains domain */
532
- #FFC107 50%, /* Reference point */
533
- #F44336 100% /* Losses domain (amplified) */
534
- );
535
- border-radius: 17.5px;
536
  margin: 20px 0;
537
- position: relative;
538
- overflow: hidden;
539
- box-shadow: inset 0 2px 10px rgba(0,0,0,0.2);
540
  }
541
 
542
- .prospect-risk-marker {
543
- position: absolute;
544
- top: -5px;
545
- height: 45px;
546
- width: 8px;
547
- background: white;
548
- border-radius: 4px;
549
- transform: translateX(-50%);
550
- box-shadow: 0 0 15px rgba(0,0,0,0.7);
551
- transition: left 1s cubic-bezier(0.34, 1.56, 0.64, 1);
552
- z-index: 3;
553
  }
554
 
555
- /* Mathematical License Cards */
556
  .mathematical-card {
557
  border-radius: 15px;
558
  padding: 25px;
@@ -561,20 +264,8 @@ ENHANCED_CSS = """
561
  border-top: 6px solid;
562
  position: relative;
563
  overflow: hidden;
564
- }
565
-
566
- .mathematical-card::before {
567
- content: '';
568
- position: absolute;
569
- top: 0;
570
- left: 0;
571
- right: 0;
572
- height: 4px;
573
- background: linear-gradient(90deg,
574
- rgba(255,255,255,0) 0%,
575
- rgba(255,255,255,0.8) 50%,
576
- rgba(255,255,255,0) 100%
577
- );
578
  }
579
 
580
  .mathematical-card:hover {
@@ -583,71 +274,56 @@ ENHANCED_CSS = """
583
  }
584
 
585
  .license-oss {
586
- border-top-color: var(--oss-color);
587
  background: linear-gradient(145deg, #E3F2FD, #FFFFFF);
588
  }
589
 
590
  .license-trial {
591
- border-top-color: var(--trial-color);
592
  background: linear-gradient(145deg, #FFF8E1, #FFFFFF);
593
  }
594
 
595
- .license-starter {
596
- border-top-color: var(--starter-color);
597
- background: linear-gradient(145deg, #FFF3E0, #FFFFFF);
598
- }
599
-
600
- .license-professional {
601
- border-top-color: var(--professional-color);
602
- background: linear-gradient(145deg, #FFEBEE, #FFFFFF);
603
- }
604
-
605
- .license-enterprise {
606
- border-top-color: var(--enterprise-color);
607
- background: linear-gradient(145deg, #FBE9E7, #FFFFFF);
608
- }
609
-
610
- /* Mathematical ROI Calculator */
611
- .mathematical-roi {
612
- background: linear-gradient(135deg,
613
- #667eea 0%,
614
- #764ba2 25%,
615
- #2196F3 50%,
616
- #00BCD4 100%
617
- );
618
- color: white;
619
- padding: 30px;
620
- border-radius: 20px;
621
- margin: 30px 0;
622
- box-shadow: 0 12px 40px rgba(102, 126, 234, 0.4);
623
- position: relative;
624
- overflow: hidden;
625
- }
626
-
627
- .mathematical-roi::before {
628
- content: 'ฮฃ';
629
- position: absolute;
630
- top: 20px;
631
- right: 20px;
632
- font-size: 120px;
633
- opacity: 0.1;
634
- font-weight: bold;
635
- font-family: 'Times New Roman', serif;
636
- }
637
-
638
- /* Responsive Design */
639
  @media (max-width: 768px) {
 
 
 
 
640
  .arf-real-badge, .arf-sim-badge {
641
  padding: 6px 14px;
642
  font-size: 12px;
643
  }
 
644
  .mathematical-gate {
645
- width: 60px;
646
- height: 60px;
647
- font-size: 20px;
648
  }
 
 
 
 
 
649
  .mathematical-card {
650
- padding: 20px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
651
  }
652
  }
653
  """
@@ -657,10 +333,8 @@ def generate_mathematical_trial_license() -> str:
657
  """Generate mathematically structured trial license"""
658
  segments = []
659
  for _ in range(4):
660
- # Generate segment with mathematical pattern
661
  segment = ''.join(random.choices('0123456789ABCDEF', k=4))
662
  segments.append(segment)
663
-
664
  return f"ARF-TRIAL-{segments[0]}-{segments[1]}-{segments[2]}-{segments[3]}"
665
 
666
  def format_mathematical_risk(risk_score: float, confidence: float = None) -> str:
@@ -685,8 +359,7 @@ def format_mathematical_risk(risk_score: float, confidence: float = None) -> str
685
  risk_text = f"{risk_score:.1%}"
686
 
687
  if confidence:
688
- confidence_text = f"{confidence:.0%} conf"
689
- return f'<span style="color: {color}; font-weight: bold;">{emoji} {risk_text} ({category})</span><br><span style="font-size: 0.8em; color: #666;">{confidence_text}</span>'
690
  else:
691
  return f'<span style="color: {color}; font-weight: bold;">{emoji} {risk_text} ({category})</span>'
692
 
@@ -696,48 +369,86 @@ def create_confidence_interval_html(lower: float, upper: float, score: float) ->
696
  upper_pct = upper * 100
697
  score_pct = score * 100
698
 
699
- width = upper_pct - lower_pct
700
- left_pos = lower_pct
701
-
702
  return f"""
703
- <div class="confidence-interval" style="width: 100%;">
704
- <div class="interval-marker" style="left: {score_pct}%;"></div>
705
- <div style="position: absolute; top: 35px; left: {lower_pct}%; transform: translateX(-50%); font-size: 11px; color: #666;">
706
- {lower_pct:.0f}%
707
- </div>
708
- <div style="position: absolute; top: 35px; left: {upper_pct}%; transform: translateX(-50%); font-size: 11px; color: #666;">
709
- {upper_pct:.0f}%
710
- </div>
711
- <div style="position: absolute; top: -25px; left: {score_pct}%; transform: translateX(-50%); font-size: 12px; font-weight: bold; color: #333;">
712
- {score_pct:.0f}%
713
- </div>
714
  </div>
715
  <div style="text-align: center; font-size: 12px; color: #666; margin-top: 5px;">
716
- 95% Confidence Interval: {lower_pct:.0f}% - {upper_pct:.0f}% (Width: {width:.0f}%)
717
  </div>
718
  """
719
 
720
- # ============== GRADIO INTERFACE ==============
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
721
  def create_enhanced_demo():
722
- """Create enhanced demo with mathematical sophistication"""
723
 
724
  # Get unified status
725
  arf_display = ARF_UNIFIED_STATUS['display_text']
726
  arf_badge_class = ARF_UNIFIED_STATUS['badge_class']
727
- arf_css_class = ARF_UNIFIED_STATUS['badge_css']
728
 
729
  with gr.Blocks(
730
  title=f"ARF {ARF_UNIFIED_STATUS['version']} - Mathematical Sophistication",
731
  theme=gr.themes.Soft(
732
  primary_hue="blue",
733
- secondary_hue="orange",
734
- neutral_hue="gray"
735
  ),
736
  css=ENHANCED_CSS
737
  ) as demo:
738
 
739
- # ===== MATHEMATICAL HEADER =====
740
- gr.Markdown(f"""
741
  <div style="background: linear-gradient(135deg, #0D47A1, #1565C0); color: white; padding: 30px; border-radius: 15px; margin-bottom: 30px; box-shadow: 0 10px 30px rgba(13, 71, 161, 0.4); position: relative; overflow: hidden;">
742
  <div style="position: absolute; top: 0; right: 0; width: 300px; height: 300px; background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);"></div>
743
 
@@ -766,7 +477,7 @@ def create_enhanced_demo():
766
  </div>
767
  """)
768
 
769
- # ===== MATHEMATICAL METRICS =====
770
  with gr.Row():
771
  metrics = [
772
  ("92%", "Incident Prevention", "Bayesian confidence: 95%", "#4CAF50", "๐Ÿ“Š"),
@@ -776,9 +487,9 @@ def create_enhanced_demo():
776
  ]
777
 
778
  for value, title, subtitle, color, icon in metrics:
779
- with gr.Column(scale=1):
780
  gr.HTML(f"""
781
- <div style="text-align: center; padding: 25px; background: #f8f9fa; border-radius: 15px; border-top: 6px solid {color}; box-shadow: 0 8px 25px rgba(0,0,0,0.1); transition: all 0.3s;">
782
  <div style="font-size: 40px; color: {color}; margin-bottom: 10px; display: flex; align-items: center; justify-content: center; gap: 10px;">
783
  <span style="font-size: 30px;">{icon}</span>
784
  <span style="font-weight: bold;">{value}</span>
@@ -788,14 +499,16 @@ def create_enhanced_demo():
788
  </div>
789
  """)
790
 
791
- # ===== EXECUTION AUTHORITY DEMO =====
792
- gr.Markdown("""
793
- ## ๐Ÿงฎ Mathematical Execution Authority Demo
794
- *Test how Bayesian risk assessment and mechanical gates prevent unsafe AI actions*
 
 
795
  """)
796
 
 
797
  with gr.Row():
798
- # Control Panel
799
  with gr.Column(scale=2):
800
  scenario = gr.Dropdown(
801
  label="๐Ÿข Select Enterprise Scenario",
@@ -827,7 +540,7 @@ def create_enhanced_demo():
827
  test_btn = gr.Button("โšก Test Mathematical Assessment", variant="primary", scale=2)
828
  trial_btn = gr.Button("๐ŸŽ Generate Mathematical Trial", variant="secondary", scale=1)
829
 
830
- # License Display
831
  with gr.Column(scale=1):
832
  license_display = gr.HTML(f"""
833
  <div class="mathematical-card license-oss">
@@ -852,9 +565,8 @@ def create_enhanced_demo():
852
  </div>
853
  """)
854
 
855
- # ===== MATHEMATICAL RESULTS =====
856
  with gr.Row():
857
- # OSS Results (Advisory)
858
  with gr.Column(scale=1):
859
  oss_results = gr.HTML("""
860
  <div class="mathematical-card license-oss">
@@ -866,7 +578,7 @@ def create_enhanced_demo():
866
  <div style="text-align: center; margin: 30px 0;">
867
  <div style="font-size: 56px; font-weight: bold; color: #1E88E5; margin-bottom: 5px;">--</div>
868
  <div style="font-size: 14px; color: #666; margin-bottom: 15px;">Risk Score (Bayesian)</div>
869
- <div id="oss-confidence-interval" style="margin-top: 10px;"></div>
870
  </div>
871
 
872
  <div style="background: rgba(244, 67, 54, 0.1); padding: 18px; border-radius: 10px; margin: 15px 0; border-left: 5px solid #F44336;">
@@ -880,29 +592,28 @@ def create_enhanced_demo():
880
 
881
  <div style="background: rgba(255, 152, 0, 0.1); padding: 16px; border-radius: 10px; margin-top: 20px;">
882
  <strong style="color: #F57C00; font-size: 1.05em;">๐Ÿ“‹ Bayesian Recommendation:</strong>
883
- <div id="oss-recommendation" style="font-size: 0.95em; margin-top: 8px; line-height: 1.5;">
884
  Awaiting mathematical assessment...
885
  </div>
886
  </div>
887
  </div>
888
  """)
889
 
890
- # Enterprise Results (Mathematical)
891
  with gr.Column(scale=1):
892
  enterprise_results = gr.HTML(f"""
893
  <div class="mathematical-card license-trial">
894
  <h3 style="margin-top: 0; color: #FFB300; display: flex; align-items: center;">
895
- <span id="enterprise-tier">Trial Edition</span>
896
  <span style="margin-left: auto; font-size: 0.7em; background: #FFB300; color: white; padding: 4px 12px; border-radius: 15px;">Mechanical</span>
897
  </h3>
898
 
899
  <div style="text-align: center; margin: 30px 0;">
900
- <div style="font-size: 56px; font-weight: bold; color: #FFB300; margin-bottom: 5px;" id="enterprise-risk">--</div>
901
  <div style="font-size: 14px; color: #666; margin-bottom: 15px;">Risk Score (Bayesian)</div>
902
- <div id="enterprise-confidence-interval" style="margin-top: 10px;"></div>
903
  </div>
904
 
905
- <div id="gates-visualization">
906
  <div style="font-size: 14px; color: #666; margin-bottom: 15px; font-weight: 600;">Mathematical Gates:</div>
907
  <div class="gate-container">
908
  <div class="mathematical-gate gate-pending">1</div>
@@ -915,174 +626,13 @@ def create_enhanced_demo():
915
 
916
  <div style="background: rgba(255, 152, 0, 0.1); padding: 18px; border-radius: 10px; margin-top: 25px;">
917
  <strong style="color: #F57C00; font-size: 1.1em;">๐Ÿ›ก๏ธ Mechanical Enforcement:</strong>
918
- <div id="enterprise-action" style="font-size: 0.95em; margin-top: 8px; line-height: 1.5;">
919
  Awaiting mathematical assessment...
920
  </div>
921
  </div>
922
  </div>
923
  """)
924
 
925
- # ===== MATHEMATICAL HISTORY =====
926
- with gr.Row():
927
- with gr.Column():
928
- gr.Markdown("### ๐Ÿ“Š Mathematical Action History")
929
- action_history = gr.HTML("""
930
- <div style="border: 1px solid #E0E0E0; border-radius: 15px; padding: 25px; background: #fafafa; box-shadow: 0 8px 30px rgba(0,0,0,0.08);">
931
- <table style="width: 100%; border-collapse: collapse; font-size: 14px;">
932
- <thead>
933
- <tr style="background: linear-gradient(to right, #f5f5f5, #fafafa); border-radius: 10px;">
934
- <th style="padding: 15px; border-bottom: 3px solid #E0E0E0; text-align: left; font-weight: 700; color: #555; font-size: 13px;">Time</th>
935
- <th style="padding: 15px; border-bottom: 3px solid #E0E0E0; text-align: left; font-weight: 700; color: #555; font-size: 13px;">Action</th>
936
- <th style="padding: 15px; border-bottom: 3px solid #E0E0E0; text-align: left; font-weight: 700; color: #555; font-size: 13px;">Risk</th>
937
- <th style="padding: 15px; border-bottom: 3px solid #E0E0E0; text-align: left; font-weight: 700; color: #555; font-size: 13px;">Confidence</th>
938
- <th style="padding: 15px; border-bottom: 3px solid #E0E0E0; text-align: left; font-weight: 700; color: #555; font-size: 13px;">License</th>
939
- <th style="padding: 15px; border-bottom: 3px solid #E0E0E0; text-align: left; font-weight: 700; color: #555; font-size: 13px;">Gates</th>
940
- <th style="padding: 15px; border-bottom: 3px solid #E0E0E0; text-align: left; font-weight: 700; color: #555; font-size: 13px;">Decision</th>
941
- <th style="padding: 15px; border-bottom: 3px solid #E0E0E0; text-align: left; font-weight: 700; color: #555; font-size: 13px;">ARF</th>
942
- </tr>
943
- </thead>
944
- <tbody>
945
- <tr>
946
- <td colspan="8" style="text-align: center; color: #999; padding: 50px; font-style: italic; font-size: 1.1em;">
947
- No mathematical assessments yet. Test an action to see Bayesian analysis in action.
948
- </td>
949
- </tr>
950
- </tbody>
951
- </table>
952
- </div>
953
- """)
954
-
955
- # ===== MATHEMATICAL ROI CALCULATOR =====
956
- with gr.Row():
957
- with gr.Column():
958
- gr.Markdown("### ๐Ÿงฎ Mathematical ROI Calculator")
959
- gr.Markdown("*Bayesian analysis of enterprise value with confidence intervals*")
960
-
961
- with gr.Row():
962
- current_tier = gr.Dropdown(
963
- label="Current License Tier",
964
- choices=["OSS", "Trial", "Starter", "Professional"],
965
- value="OSS",
966
- scale=1
967
- )
968
-
969
- target_tier = gr.Dropdown(
970
- label="Target License Tier",
971
- choices=["Starter", "Professional", "Enterprise"],
972
- value="Enterprise",
973
- scale=1
974
- )
975
-
976
- calculate_roi_btn = gr.Button("๐Ÿ“ˆ Calculate Mathematical ROI", variant="secondary")
977
-
978
- roi_result = gr.HTML("""
979
- <div class="mathematical-roi">
980
- <h4 style="margin-top: 0; margin-bottom: 25px; font-size: 1.3em;">Mathematical ROI Analysis</h4>
981
- <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 30px;">
982
- <div>
983
- <div style="font-size: 14px; opacity: 0.95; letter-spacing: 0.5px; margin-bottom: 5px;">Annual Savings</div>
984
- <div style="font-size: 42px; font-weight: bold; margin: 10px 0;">$--</div>
985
- <div style="font-size: 12px; opacity: 0.8;">95% confidence interval</div>
986
- </div>
987
- <div>
988
- <div style="font-size: 14px; opacity: 0.95; letter-spacing: 0.5px; margin-bottom: 5px;">Payback Period</div>
989
- <div style="font-size: 42px; font-weight: bold; margin: 10px 0;">-- mo</div>
990
- <div style="font-size: 12px; opacity: 0.8;">ยฑ 0.5 months</div>
991
- </div>
992
- </div>
993
- <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 25px; margin-top: 30px;">
994
- <div style="font-size: 13px;">
995
- <div style="opacity: 0.9; margin-bottom: 3px;">๐Ÿ“Š Bayesian Probability</div>
996
- <div style="font-weight: bold; font-size: 16px;">--% success</div>
997
- </div>
998
- <div style="font-size: 13px;">
999
- <div style="opacity: 0.9; margin-bottom: 3px;">๐Ÿ’ฐ NPV (10% discount)</div>
1000
- <div style="font-weight: bold; font-size: 16px;">$--</div>
1001
- </div>
1002
- </div>
1003
- <div style="font-size: 12px; margin-top: 25px; opacity: 0.9; line-height: 1.6;">
1004
- Based on mathematical models: $3.9M avg breach cost, Bayesian confidence intervals,<br>
1005
- Prospect Theory risk perception, 250 operating days, $150/hr engineer cost
1006
- </div>
1007
- </div>
1008
- """)
1009
-
1010
- # ===== PSYCHOLOGICAL TRIAL CTA =====
1011
- with gr.Row():
1012
- with gr.Column():
1013
- gr.Markdown("""
1014
- ## ๐Ÿง  Psychological Trial Optimization
1015
-
1016
- <div style="background: linear-gradient(135deg, #FF6F00, #FFB300); color: white; padding: 22px 35px; border-radius: 15px; text-align: center; font-weight: bold; margin: 20px 0; box-shadow: 0 10px 35px rgba(255, 111, 0, 0.4);">
1017
- โณ 14-Day Mathematical Trial โ€ข <span style="background: white; color: #FF6F00; padding: 5px 15px; border-radius: 8px; margin: 0 10px; font-weight: bold; box-shadow: 0 4px 15px rgba(0,0,0,0.2);">Prospect Theory Optimized</span>
1018
- </div>
1019
- """)
1020
-
1021
- with gr.Row():
1022
- email_input = gr.Textbox(
1023
- label="Enterprise Email",
1024
- placeholder="Enter your work email for mathematical trial license",
1025
- scale=3
1026
- )
1027
-
1028
- request_trial_btn = gr.Button("๐Ÿš€ Request Mathematical Trial", variant="primary", scale=1)
1029
-
1030
- trial_output = gr.HTML("""
1031
- <div style="text-align: center; padding: 30px; background: #f8f9fa; border-radius: 15px; border: 1px solid #E0E0E0; box-shadow: 0 8px 25px rgba(0,0,0,0.08);">
1032
- <div style="font-size: 1em; color: #555; line-height: 1.7;">
1033
- <strong style="color: #333; font-size: 1.1em;">Mathematical Trial Includes:</strong><br>
1034
- โ€ข Bayesian risk assessment with confidence intervals<br>
1035
- โ€ข Mechanical gates with mathematical weights<br>
1036
- โ€ข Prospect Theory psychological optimization<br>
1037
- โ€ข License-gated execution authority<br>
1038
- โ€ข PhD-level mathematical sophistication
1039
- </div>
1040
- </div>
1041
- """)
1042
-
1043
- # ===== MATHEMATICAL FOOTER =====
1044
- gr.Markdown(f"""
1045
- ---
1046
-
1047
- <div style="text-align: center; color: #666; font-size: 0.95em; padding: 25px 0;">
1048
- <strong style="font-size: 1.2em; color: #333; margin-bottom: 15px; display: block;">
1049
- ARF {ARF_UNIFIED_STATUS['version']} - Mathematical Sophistication Platform
1050
- </strong>
1051
- <div style="margin: 20px 0; display: flex; justify-content: center; align-items: center; gap: 12px; flex-wrap: wrap;">
1052
- <span class="{arf_badge_class}" style="font-size: 0.85em;">{arf_display}</span>
1053
- <span style="background: linear-gradient(135deg, #9C27B0, #7B1FA2); color: white; padding: 6px 14px; border-radius: 18px; font-size: 0.85em; font-weight: bold;">
1054
- ๐Ÿค— Hugging Face Spaces
1055
- </span>
1056
- <span style="background: linear-gradient(135deg, #4CAF50, #2E7D32); color: white; padding: 6px 14px; border-radius: 18px; font-size: 0.85em; font-weight: bold;">
1057
- SOC 2 Type II Certified
1058
- </span>
1059
- <span style="background: linear-gradient(135deg, #2196F3, #0D47A1); color: white; padding: 6px 14px; border-radius: 18px; font-size: 0.85em; font-weight: bold;">
1060
- GDPR Compliant
1061
- </span>
1062
- <span style="background: linear-gradient(135deg, #FF9800, #F57C00); color: white; padding: 6px 14px; border-radius: 18px; font-size: 0.85em; font-weight: bold;">
1063
- ISO 27001
1064
- </span>
1065
- </div>
1066
- <div style="margin-top: 15px; color: #4CAF50; font-weight: 600; font-size: 1.05em;">
1067
- โœ“ 99.9% SLA โ€ข โœ“ 24/7 Mathematical Support โ€ข โœ“ On-prem Deployment Available
1068
- </div>
1069
- <div style="margin-top: 25px; font-size: 0.9em;">
1070
- ยฉ 2024 ARF Technologies โ€ข
1071
- <a href="https://github.com/petter2025/agentic-reliability-framework" style="color: #1E88E5; text-decoration: none; font-weight: 600;">GitHub</a> โ€ข
1072
- <a href="#" style="color: #1E88E5; text-decoration: none; font-weight: 600;">Documentation</a> โ€ข
1073
- <a href="mailto:sales@arf.dev" style="color: #1E88E5; text-decoration: none; font-weight: 600;">Enterprise Sales</a> โ€ข
1074
- <a href="#" style="color: #1E88E5; text-decoration: none; font-weight: 600;">Investment Deck</a>
1075
- </div>
1076
- <div style="margin-top: 20px; font-size: 0.8em; color: #888; max-width: 900px; margin-left: auto; margin-right: auto; line-height: 1.6; background: rgba(0,0,0,0.02); padding: 15px; border-radius: 10px;">
1077
- <strong>Mathematical Foundation:</strong> Bayesian Inference โ€ข Prospect Theory โ€ข Confidence Intervals<br>
1078
- <strong>Business Model:</strong> License-Gated Execution Authority โ€ข
1079
- <strong>Target Market:</strong> Enterprise AI Infrastructure ($100B+)<br>
1080
- <strong>Investment Thesis:</strong> $150,000 for 10% equity โ€ข
1081
- <strong>Founder:</strong> Juan D. Petter (AI Reliability Engineer)
1082
- </div>
1083
- </div>
1084
- """)
1085
-
1086
  # ===== EVENT HANDLERS =====
1087
  def update_context(scenario_name):
1088
  """Update context with mathematical analysis"""
@@ -1123,7 +673,7 @@ def create_enhanced_demo():
1123
  # Simulate enhanced assessment
1124
  action_lower = scenario_name.lower()
1125
 
1126
- # Base risk calculation with mathematical precision
1127
  base_risk = 0.3
1128
 
1129
  if 'drop database' in action_lower:
@@ -1168,8 +718,8 @@ def create_enhanced_demo():
1168
  final_risk = base_risk * risk_multiplier
1169
  final_risk = min(0.99, max(0.1, final_risk))
1170
 
1171
- # Calculate confidence (mathematical precision)
1172
- confidence = 0.8 + (random.random() * 0.15) # 80-95% confidence
1173
 
1174
  # Confidence interval
1175
  ci_lower = max(0.1, final_risk - (0.2 * (1 - confidence)))
@@ -1234,14 +784,6 @@ def create_enhanced_demo():
1234
  gate_decision = "BLOCKED"
1235
  gate_reason = "Failed critical mathematical gates"
1236
 
1237
- # Generate psychological insights
1238
- psychological_insights = psychology_engine.generate_comprehensive_insights(
1239
- final_risk, risk_category, license_tier, "executive"
1240
- )
1241
-
1242
- # Calculate processing time
1243
- processing_time = (time.time() - start_time) * 1000
1244
-
1245
  # Create action data
1246
  action_data = {
1247
  'time': datetime.now().strftime("%H:%M:%S"),
@@ -1253,9 +795,8 @@ def create_enhanced_demo():
1253
  'gates_passed': gates_passed,
1254
  'total_gates': total_gates,
1255
  'gate_decision': gate_decision,
1256
- 'processing_time_ms': round(processing_time, 1),
1257
- 'arf_status': 'REAL' if ARF_UNIFIED_STATUS['is_real'] else 'SIM',
1258
- 'psychological_impact': psychological_insights.get('conversion_prediction', {}).get('conversion_probability', 0.5)
1259
  }
1260
 
1261
  demo_state.add_action(action_data)
@@ -1285,28 +826,23 @@ def create_enhanced_demo():
1285
  enforcement = f"โœ… MATHEMATICAL APPROVAL: {gate_reason}. Confidence interval: {ci_lower:.0%}-{ci_upper:.0%}"
1286
 
1287
  # Gate visualization
1288
- gates_html = ""
1289
- if total_gates > 0:
1290
- gates_visualization = ""
1291
- for i in range(total_gates):
1292
- gate_class = "gate-passed" if i < gates_passed else "gate-failed"
1293
- gates_visualization += f"""
1294
- <div class="mathematical-gate {gate_class}">{i+1}</div>
1295
- {'<div class="gate-line"></div>' if i < total_gates-1 else ''}
1296
- """
1297
-
1298
- gates_status = f"{gates_passed}/{total_gates} mathematical gates passed"
1299
- gates_score = f"{(gates_passed/total_gates)*100:.0f}%" if total_gates > 0 else "0%"
1300
-
1301
- gates_html = f"""
1302
- <div style="font-size: 14px; color: #666; margin-bottom: 15px; font-weight: 600;">
1303
- Mathematical Gates: {gates_status} ({gates_score})
1304
- </div>
1305
- <div class="gate-container">
1306
- {gates_visualization}
1307
- </div>
1308
  """
1309
 
 
 
 
 
 
 
 
 
 
1310
  # Tier info
1311
  tier_data = {
1312
  'oss': {'color': '#1E88E5', 'bg': '#E3F2FD', 'name': 'OSS Edition'},
@@ -1319,10 +855,6 @@ def create_enhanced_demo():
1319
  current_tier = license_tier
1320
  tier_info = tier_data.get(current_tier, tier_data['oss'])
1321
 
1322
- # Psychological impact
1323
- conversion_prob = psychological_insights.get('conversion_prediction', {}).get('conversion_probability', 0.5)
1324
- psychological_summary = psychological_insights.get('psychological_summary', 'Standard psychological framing')
1325
-
1326
  # Update panels
1327
  oss_html = f"""
1328
  <div class="mathematical-card license-oss">
@@ -1374,14 +906,6 @@ def create_enhanced_demo():
1374
  <strong style="color: {tier_info['color']}; font-size: 1.1em;">๐Ÿ›ก๏ธ Mechanical Enforcement:</strong>
1375
  <div style="font-size: 0.95em; margin-top: 8px; line-height: 1.5;">{enforcement}</div>
1376
  </div>
1377
-
1378
- <div style="background: rgba(156, 39, 176, 0.1); padding: 15px; border-radius: 10px; margin-top: 20px; border-left: 4px solid #9C27B0;">
1379
- <strong style="color: #7B1FA2; font-size: 1em;">๐Ÿง  Psychological Insight:</strong>
1380
- <div style="font-size: 0.9em; margin-top: 5px; color: #666;">
1381
- Conversion probability: {conversion_prob:.0%}<br>
1382
- {psychological_summary}
1383
- </div>
1384
- </div>
1385
  </div>
1386
  """
1387
 
@@ -1398,7 +922,7 @@ def create_enhanced_demo():
1398
  </p>
1399
  <div style="background: rgba(30, 136, 229, 0.12); padding: 15px; border-radius: 10px; border-left: 4px solid {tier_info['color']};">
1400
  <div style="font-size: 0.9em; color: {tier_info['color']}; line-height: 1.6;">
1401
- <strong>Execution Level:</strong> {demo_state.license_state['execution_level']}<br>
1402
  <strong>Risk Prevention:</strong> {92 if current_tier == 'enterprise' else 85 if current_tier == 'professional' else 70 if current_tier == 'starter' else 50 if current_tier == 'trial' else 0}%<br>
1403
  <strong>Confidence Threshold:</strong> {90 if current_tier == 'enterprise' else 80 if current_tier == 'professional' else 70 if current_tier == 'starter' else 60 if current_tier == 'trial' else 0}%<br>
1404
  <strong>ARF Status:</strong> {arf_display}
@@ -1425,36 +949,45 @@ def create_enhanced_demo():
1425
 
1426
  history_rows += f"""
1427
  <tr>
1428
- <td style="padding: 15px; border-bottom: 1px solid #eee; color: #555; font-size: 13px;">{entry['time']}</td>
1429
- <td style="padding: 15px; border-bottom: 1px solid #eee; color: #555; font-size: 13px;" title="{entry['action']}">{entry['action'][:35]}...</td>
1430
- <td style="padding: 15px; border-bottom: 1px solid #eee; font-size: 13px;">{risk_text}</td>
1431
- <td style="padding: 15px; border-bottom: 1px solid #eee; color: #555; font-size: 13px;">{confidence_text}</td>
1432
- <td style="padding: 15px; border-bottom: 1px solid #eee; color: #555; font-size: 13px; font-weight: 500;">{entry['license_tier']}</td>
1433
- <td style="padding: 15px; border-bottom: 1px solid #eee; color: {gates_color}; font-weight: bold; font-size: 13px;">{gates_text}</td>
1434
- <td style="padding: 15px; border-bottom: 1px solid #eee; font-size: 16px;">{decision_emoji}</td>
1435
- <td style="padding: 15px; border-bottom: 1px solid #eee; text-align: center; font-size: 16px;">{arf_emoji}</td>
1436
  </tr>
1437
  """
1438
 
1439
  history_html = f"""
1440
- <div style="border: 1px solid #E0E0E0; border-radius: 15px; padding: 25px; background: #fafafa; box-shadow: 0 8px 30px rgba(0,0,0,0.08);">
1441
- <table style="width: 100%; border-collapse: collapse; font-size: 14px;">
1442
- <thead>
1443
- <tr style="background: linear-gradient(to right, #f5f5f5, #fafafa); border-radius: 10px;">
1444
- <th style="padding: 15px; border-bottom: 3px solid #E0E0E0; text-align: left; font-weight: 700; color: #555; font-size: 13px;">Time</th>
1445
- <th style="padding: 15px; border-bottom: 3px solid #E0E0E0; text-align: left; font-weight: 700; color: #555; font-size: 13px;">Action</th>
1446
- <th style="padding: 15px; border-bottom: 3px solid #E0E0E0; text-align: left; font-weight: 700; color: #555; font-size: 13px;">Risk</th>
1447
- <th style="padding: 15px; border-bottom: 3px solid #E0E0E0; text-align: left; font-weight: 700; color: #555; font-size: 13px;">Confidence</th>
1448
- <th style="padding: 15px; border-bottom: 3px solid #E0E0E0; text-align: left; font-weight: 700; color: #555; font-size: 13px;">License</th>
1449
- <th style="padding: 15px; border-bottom: 3px solid #E0E0E0; text-align: left; font-weight: 700; color: #555; font-size: 13px;">Gates</th>
1450
- <th style="padding: 15px; border-bottom: 3px solid #E0E0E0; text-align: left; font-weight: 700; color: #555; font-size: 13px;">Decision</th>
1451
- <th style="padding: 15px; border-bottom: 3px solid #E0E0E0; text-align: left; font-weight: 700; color: #555; font-size: 13px;">ARF</th>
1452
- </tr>
1453
- </thead>
1454
- <tbody>
1455
- {history_rows}
1456
- </tbody>
1457
- </table>
 
 
 
 
 
 
 
 
 
1458
  </div>
1459
  """
1460
 
@@ -1463,132 +996,20 @@ def create_enhanced_demo():
1463
  def generate_trial():
1464
  """Generate mathematical trial license"""
1465
  license_key = generate_mathematical_trial_license()
1466
- demo_state.stats['trial_licenses'] = demo_state.stats.get('trial_licenses', 0) + 1
1467
-
1468
  return license_key, f"""
1469
- <div style="text-align: center; padding: 30px; background: linear-gradient(135deg, #FFB300, #FF9800); color: white; border-radius: 15px; box-shadow: 0 12px 40px rgba(255, 179, 0, 0.4);">
1470
- <h3 style="margin-top: 0; margin-bottom: 20px;">๐ŸŽ‰ Mathematical Trial License Generated!</h3>
1471
- <div style="background: white; color: #333; padding: 22px; border-radius: 10px; font-family: 'Monaco', 'Courier New', monospace; margin: 20px 0; font-size: 16px; letter-spacing: 1.5px; border: 3px dashed #FFB300; box-shadow: 0 8px 25px rgba(0,0,0,0.2);">
1472
  {license_key}
1473
  </div>
1474
- <p style="margin-bottom: 25px; font-size: 1.1em; line-height: 1.6;">Copy this key and paste it into the License Key field above.</p>
1475
- <div style="background: rgba(255,255,255,0.2); padding: 22px; border-radius: 10px; margin-top: 20px;">
1476
- <div style="font-size: 1em; line-height: 1.7;">
1477
- โณ <strong>14-day mathematical trial</strong><br>
1478
- ๐Ÿงฎ <strong>Bayesian analysis with confidence intervals</strong><br>
1479
- ๐Ÿ›ก๏ธ <strong>Mechanical gates with mathematical weights</strong><br>
1480
- ๐Ÿง  <strong>Prospect Theory psychological optimization</strong>
1481
- </div>
1482
- </div>
1483
- </div>
1484
- """
1485
-
1486
- def calculate_mathematical_roi(current, target):
1487
- """Calculate mathematical ROI with confidence"""
1488
- # ROI calculations with mathematical precision
1489
- roi_data = {
1490
- ('OSS', 'Enterprise'): {
1491
- 'savings': 3850000,
1492
- 'payback': 3.2,
1493
- 'confidence': 0.92,
1494
- 'npv': 3200000
1495
- },
1496
- ('OSS', 'Professional'): {
1497
- 'savings': 2850000,
1498
- 'payback': 5.6,
1499
- 'confidence': 0.88,
1500
- 'npv': 2400000
1501
- },
1502
- ('OSS', 'Starter'): {
1503
- 'savings': 1850000,
1504
- 'payback': 8.4,
1505
- 'confidence': 0.85,
1506
- 'npv': 1500000
1507
- },
1508
- ('Professional', 'Enterprise'): {
1509
- 'savings': 1200000,
1510
- 'payback': 2.1,
1511
- 'confidence': 0.90,
1512
- 'npv': 1050000
1513
- }
1514
- }
1515
-
1516
- key = (current, target)
1517
- if key in roi_data:
1518
- data = roi_data[key]
1519
- else:
1520
- data = {'savings': 1500000, 'payback': 6.0, 'confidence': 0.80, 'npv': 1200000}
1521
-
1522
- # Calculate confidence intervals
1523
- ci_lower = data['savings'] * 0.9
1524
- ci_upper = data['savings'] * 1.1
1525
-
1526
- return f"""
1527
- <div class="mathematical-roi">
1528
- <h4 style="margin-top: 0; margin-bottom: 25px; font-size: 1.3em;">Mathematical ROI: {current} โ†’ {target}</h4>
1529
- <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 30px;">
1530
- <div>
1531
- <div style="font-size: 14px; opacity: 0.95; letter-spacing: 0.5px; margin-bottom: 5px;">Annual Savings</div>
1532
- <div style="font-size: 42px; font-weight: bold; margin: 10px 0;">${data['savings']:,}</div>
1533
- <div style="font-size: 12px; opacity: 0.8;">95% CI: ${ci_lower:,.0f} - ${ci_upper:,.0f}</div>
1534
- </div>
1535
- <div>
1536
- <div style="font-size: 14px; opacity: 0.95; letter-spacing: 0.5px; margin-bottom: 5px;">Payback Period</div>
1537
- <div style="font-size: 42px; font-weight: bold; margin: 10px 0;">{data['payback']} mo</div>
1538
- <div style="font-size: 12px; opacity: 0.8;">ยฑ 0.5 months</div>
1539
- </div>
1540
- </div>
1541
- <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 25px; margin-top: 30px;">
1542
- <div style="font-size: 13px;">
1543
- <div style="opacity: 0.9; margin-bottom: 3px;">๐Ÿ“Š Bayesian Probability</div>
1544
- <div style="font-weight: bold; font-size: 16px;">{data['confidence']:.0%} success</div>
1545
- </div>
1546
- <div style="font-size: 13px;">
1547
- <div style="opacity: 0.9; margin-bottom: 3px;">๐Ÿ’ฐ NPV (10% discount)</div>
1548
- <div style="font-weight: bold; font-size: 16px;">${data['npv']:,}</div>
1549
- </div>
1550
- </div>
1551
- <div style="font-size: 12px; margin-top: 25px; opacity: 0.9; line-height: 1.6;">
1552
- Based on mathematical models: $3.9M avg breach cost, Bayesian confidence intervals,<br>
1553
- Prospect Theory risk perception, 250 operating days, $150/hr engineer cost
1554
- </div>
1555
- </div>
1556
- """
1557
-
1558
- def request_trial(email):
1559
- """Request mathematical trial"""
1560
- if not email or "@" not in email:
1561
- return """
1562
- <div style="text-align: center; padding: 30px; background: #FFF8E1; border-radius: 15px; border: 1px solid #FFE082; box-shadow: 0 8px 25px rgba(255, 224, 130, 0.3);">
1563
- <div style="color: #FF9800; font-size: 60px; margin-bottom: 20px;">โš ๏ธ</div>
1564
- <h4 style="margin: 0 0 15px 0; color: #F57C00;">Enterprise Email Required</h4>
1565
- <p style="color: #666; margin: 0; font-size: 1.05em; line-height: 1.6;">Please enter a valid enterprise email address to receive your mathematical trial license.</p>
1566
- </div>
1567
- """
1568
-
1569
- license_key = generate_mathematical_trial_license()
1570
- demo_state.stats['trial_licenses'] = demo_state.stats.get('trial_licenses', 0) + 1
1571
-
1572
- return f"""
1573
- <div style="text-align: center; padding: 30px; background: linear-gradient(135deg, #4CAF50, #2E7D32); color: white; border-radius: 15px; box-shadow: 0 12px 40px rgba(76, 175, 80, 0.4);">
1574
- <div style="font-size: 60px; margin-bottom: 15px;">๐ŸŽ‰</div>
1575
- <h3 style="margin-top: 0; margin-bottom: 20px;">Mathematical Trial License Sent!</h3>
1576
- <p style="margin-bottom: 25px; font-size: 1.1em; line-height: 1.6;">Your 14-day mathematical trial license has been sent to:</p>
1577
- <div style="background: white; color: #333; padding: 18px; border-radius: 10px; margin: 20px 0; font-weight: bold; font-size: 1.15em; border: 3px solid #A5D6A7; box-shadow: 0 8px 25px rgba(0,0,0,0.15);">
1578
- {email}
1579
- </div>
1580
- <div style="background: rgba(255,255,255,0.2); padding: 25px; border-radius: 10px; margin-top: 25px;">
1581
- <div style="font-family: 'Monaco', 'Courier New', monospace; font-size: 1.15em; letter-spacing: 1.5px; margin-bottom: 20px;">{license_key}</div>
1582
- <div style="font-size: 1em; line-height: 1.7; opacity: 0.95;">
1583
  โณ <strong>14-day mathematical trial</strong><br>
1584
  ๐Ÿงฎ <strong>Bayesian analysis with confidence intervals</strong><br>
1585
- ๐Ÿ›ก๏ธ <strong>Mechanical gates with mathematical weights</strong><br>
1586
- ๐Ÿง  <strong>Prospect Theory psychological optimization</strong>
1587
  </div>
1588
  </div>
1589
- <div style="margin-top: 25px; font-size: 0.95em; opacity: 0.9;">
1590
- Join Fortune 500 companies using mathematical ARF for safe AI execution
1591
- </div>
1592
  </div>
1593
  """
1594
 
@@ -1602,25 +1023,13 @@ def create_enhanced_demo():
1602
  test_btn.click(
1603
  fn=test_mathematical_assessment,
1604
  inputs=[scenario, context, license_key],
1605
- outputs=[oss_results, enterprise_results, license_display, action_history]
1606
  )
1607
 
1608
  trial_btn.click(
1609
  fn=generate_trial,
1610
  inputs=[],
1611
- outputs=[license_key, trial_output]
1612
- )
1613
-
1614
- calculate_roi_btn.click(
1615
- fn=calculate_mathematical_roi,
1616
- inputs=[current_tier, target_tier],
1617
- outputs=[roi_result]
1618
- )
1619
-
1620
- request_trial_btn.click(
1621
- fn=request_trial,
1622
- inputs=[email_input],
1623
- outputs=[trial_output]
1624
  )
1625
 
1626
  return demo
@@ -1628,7 +1037,8 @@ def create_enhanced_demo():
1628
  # ============== MAIN EXECUTION ==============
1629
  if __name__ == "__main__":
1630
  print("\n" + "="*80)
1631
- print("๐Ÿš€ LAUNCHING ENHANCED ARF 3.3.9 DEMO WITH MATHEMATICAL SOPHISTICATION")
 
1632
  print("="*80)
1633
 
1634
  demo = create_enhanced_demo()
 
1
+ # ARF 3.3.9 DEMO WITH FIXED HTML RENDERING BUGS
2
+ # CRITICAL FIXES APPLIED:
3
+ # 1. All HTML content now uses gr.HTML() instead of gr.Markdown()
4
+ # 2. Proper Gradio container nesting
5
+ # 3. Fixed CSS class conflicts
6
+ # 4. Enhanced mobile responsiveness
7
 
8
  import gradio as gr
9
  import time
 
16
  from datetime import datetime, timedelta
17
  from typing import Dict, List, Optional, Tuple, Any, Union
18
  import numpy as np
 
19
 
20
  # Import enhanced engines
21
  try:
 
28
  print("๐Ÿ“ Creating fallback engines...")
29
  ARF_ENGINE_ENHANCED = False
30
 
31
+ # Fallback classes
32
  class EnhancedARFEngine:
33
  def __init__(self):
34
  self.arf_status = "SIMULATION"
 
44
  def generate_comprehensive_insights(self, *args, **kwargs):
45
  return {"psychological_summary": "Basic psychological framing"}
46
 
47
+ # ============== UNIFIED ARF DETECTION ==============
48
  print("=" * 80)
49
  print("๐Ÿš€ ARF 3.3.9 ENHANCED DEMO INITIALIZATION")
50
  print("๐Ÿ” UNIFIED DETECTION: Single Source of Truth")
51
  print("=" * 80)
52
 
53
  def detect_unified_arf() -> Dict[str, Any]:
54
+ """Unified ARF detection that correctly shows REAL OSS when installed"""
 
 
 
55
  print("\n๐Ÿ” INITIATING UNIFIED ARF DETECTION...")
56
 
57
+ # Try REAL ARF OSS 3.3.9 first
58
  try:
59
  print("๐Ÿ” Attempting import: agentic_reliability_framework")
60
  import agentic_reliability_framework as arf
61
 
 
62
  version = getattr(arf, '__version__', '3.3.9')
63
  print(f"โœ… REAL ARF OSS {version} DETECTED")
64
 
 
134
  print(f" Real ARF: {'โœ… YES' if ARF_UNIFIED_STATUS['is_real'] else 'โš ๏ธ SIMULATION'}")
135
  print(f" Version: {ARF_UNIFIED_STATUS['version']}")
136
  print(f" Source: {ARF_UNIFIED_STATUS['source']}")
 
137
  print(f"{'='*80}\n")
138
 
139
+ # ============== INITIALIZE ENGINES ==============
140
  arf_engine = EnhancedARFEngine()
141
  psychology_engine = EnhancedPsychologyEngine()
142
 
143
+ # ============== ENHANCED CSS WITH FIXED CLASSES ==============
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  ENHANCED_CSS = """
145
  :root {
146
  /* Mathematical Color Psychology */
 
149
  --mathematical-orange: #FF9800;
150
  --mathematical-red: #F44336;
151
  --mathematical-purple: #9C27B0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  }
153
 
154
+ /* FIXED: Mathematical Badges with proper HTML rendering */
155
  .arf-real-badge {
156
  background: linear-gradient(135deg,
157
+ #4CAF50 0%,
158
+ #2E7D32 25%,
159
+ #1B5E20 50%,
160
+ #0D47A1 100%
161
  );
162
  color: white;
163
+ padding: 10px 22px;
164
  border-radius: 25px;
165
+ font-size: 16px;
166
  font-weight: bold;
167
  display: inline-flex;
168
  align-items: center;
 
171
  box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
172
  border: 3px solid rgba(255, 255, 255, 0.4);
173
  animation: pulse-mathematical 2.5s infinite;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
  }
175
 
176
  .arf-sim-badge {
177
  background: linear-gradient(135deg,
178
+ #FF9800 0%,
179
+ #F57C00 25%,
180
+ #E65100 50%,
181
+ #BF360C 100%
182
  );
183
  color: white;
184
+ padding: 10px 22px;
185
  border-radius: 25px;
186
+ font-size: 16px;
187
  font-weight: bold;
188
  display: inline-flex;
189
  align-items: center;
 
193
  border: 3px solid rgba(255, 255, 255, 0.4);
194
  }
195
 
 
 
 
 
 
 
196
  @keyframes pulse-mathematical {
197
  0% {
198
  box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7),
 
208
  }
209
  }
210
 
211
+ /* FIXED: Mathematical Gate Visualization */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  .mathematical-gate {
213
  width: 70px;
214
  height: 70px;
 
225
  transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
226
  }
227
 
 
 
 
 
 
228
  .gate-passed {
229
  background: linear-gradient(135deg, #4CAF50, #2E7D32);
230
  animation: gate-success-mathematical 0.7s ease-out;
 
239
  background: linear-gradient(135deg, #9E9E9E, #616161);
240
  }
241
 
242
+ .gate-container {
243
+ display: flex;
244
+ align-items: center;
245
+ justify-content: center;
246
+ gap: 10px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  margin: 20px 0;
248
+ flex-wrap: wrap;
 
 
249
  }
250
 
251
+ .gate-line {
252
+ width: 40px;
253
+ height: 4px;
254
+ background: linear-gradient(90deg, #E0E0E0, #BDBDBD);
255
+ border-radius: 2px;
 
 
 
 
 
 
256
  }
257
 
258
+ /* FIXED: Mathematical Cards */
259
  .mathematical-card {
260
  border-radius: 15px;
261
  padding: 25px;
 
264
  border-top: 6px solid;
265
  position: relative;
266
  overflow: hidden;
267
+ background: #FFFFFF;
268
+ box-shadow: 0 8px 30px rgba(0,0,0,0.08);
 
 
 
 
 
 
 
 
 
 
 
 
269
  }
270
 
271
  .mathematical-card:hover {
 
274
  }
275
 
276
  .license-oss {
277
+ border-top-color: #1E88E5;
278
  background: linear-gradient(145deg, #E3F2FD, #FFFFFF);
279
  }
280
 
281
  .license-trial {
282
+ border-top-color: #FFB300;
283
  background: linear-gradient(145deg, #FFF8E1, #FFFFFF);
284
  }
285
 
286
+ /* FIXED: Responsive Design */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
287
  @media (max-width: 768px) {
288
+ .gradio-container {
289
+ padding: 10px !important;
290
+ }
291
+
292
  .arf-real-badge, .arf-sim-badge {
293
  padding: 6px 14px;
294
  font-size: 12px;
295
  }
296
+
297
  .mathematical-gate {
298
+ width: 50px;
299
+ height: 50px;
300
+ font-size: 18px;
301
  }
302
+
303
+ .gate-line {
304
+ width: 20px;
305
+ }
306
+
307
  .mathematical-card {
308
+ padding: 15px;
309
+ margin: 10px 0;
310
+ }
311
+ }
312
+
313
+ @media (max-width: 480px) {
314
+ .gradio-container {
315
+ padding: 5px !important;
316
+ }
317
+
318
+ .arf-real-badge, .arf-sim-badge {
319
+ padding: 4px 10px;
320
+ font-size: 11px;
321
+ }
322
+
323
+ .mathematical-gate {
324
+ width: 40px;
325
+ height: 40px;
326
+ font-size: 16px;
327
  }
328
  }
329
  """
 
333
  """Generate mathematically structured trial license"""
334
  segments = []
335
  for _ in range(4):
 
336
  segment = ''.join(random.choices('0123456789ABCDEF', k=4))
337
  segments.append(segment)
 
338
  return f"ARF-TRIAL-{segments[0]}-{segments[1]}-{segments[2]}-{segments[3]}"
339
 
340
  def format_mathematical_risk(risk_score: float, confidence: float = None) -> str:
 
359
  risk_text = f"{risk_score:.1%}"
360
 
361
  if confidence:
362
+ return f'<span style="color: {color}; font-weight: bold;">{emoji} {risk_text} ({category})</span><br><span style="font-size: 0.8em; color: #666;">{confidence:.0%} conf</span>'
 
363
  else:
364
  return f'<span style="color: {color}; font-weight: bold;">{emoji} {risk_text} ({category})</span>'
365
 
 
369
  upper_pct = upper * 100
370
  score_pct = score * 100
371
 
 
 
 
372
  return f"""
373
+ <div style="width: 100%; height: 30px; background: linear-gradient(90deg,
374
+ rgba(244, 67, 54, 0.3) 0%,
375
+ rgba(255, 152, 0, 0.3) 50%,
376
+ rgba(76, 175, 80, 0.3) 100%
377
+ ); border-radius: 15px; margin: 15px 0; position: relative;">
378
+ <div style="position: absolute; left: {lower_pct}%; width: {upper_pct - lower_pct}%; height: 100%;
379
+ background: linear-gradient(90deg, rgba(33, 150, 243, 0.6), rgba(33, 150, 243, 0.3));
380
+ border-radius: 15px;"></div>
381
+ <div style="position: absolute; left: {score_pct}%; height: 100%; width: 4px; background: white;
382
+ box-shadow: 0 0 10px rgba(0,0,0,0.5); transform: translateX(-50%);"></div>
 
383
  </div>
384
  <div style="text-align: center; font-size: 12px; color: #666; margin-top: 5px;">
385
+ 95% CI: {lower_pct:.0f}% - {upper_pct:.0f}% | Score: {score_pct:.0f}%
386
  </div>
387
  """
388
 
389
+ # ============== DEMO STATE ==============
390
+ class EnhancedDemoState:
391
+ """Demo state with mathematical tracking"""
392
+
393
+ def __init__(self, arf_status: Dict[str, Any]):
394
+ self.arf_status = arf_status
395
+ self.stats = {
396
+ 'actions_tested': 0,
397
+ 'start_time': time.time(),
398
+ 'real_arf_used': arf_status['is_real'],
399
+ 'arf_version': arf_status['version']
400
+ }
401
+ self.action_history = []
402
+ self.license_state = {'current_tier': 'oss'}
403
+
404
+ def update_license(self, license_key: Optional[str] = None):
405
+ """Update license state"""
406
+ if not license_key:
407
+ self.license_state = {'current_tier': 'oss'}
408
+ return
409
+
410
+ license_upper = license_key.upper()
411
+
412
+ if 'ARF-TRIAL' in license_upper:
413
+ self.license_state = {'current_tier': 'trial'}
414
+ elif 'ARF-ENTERPRISE' in license_upper:
415
+ self.license_state = {'current_tier': 'enterprise'}
416
+ elif 'ARF-PRO' in license_upper:
417
+ self.license_state = {'current_tier': 'professional'}
418
+ elif 'ARF-STARTER' in license_upper:
419
+ self.license_state = {'current_tier': 'starter'}
420
+ else:
421
+ self.license_state = {'current_tier': 'oss'}
422
+
423
+ def add_action(self, action_data: Dict[str, Any]):
424
+ """Add action to history"""
425
+ self.action_history.insert(0, action_data)
426
+ if len(self.action_history) > 10:
427
+ self.action_history = self.action_history[:10]
428
+ self.stats['actions_tested'] += 1
429
+
430
+ # Initialize demo state
431
+ demo_state = EnhancedDemoState(ARF_UNIFIED_STATUS)
432
+
433
+ # ============== GRADIO INTERFACE WITH FIXED HTML RENDERING ==============
434
  def create_enhanced_demo():
435
+ """Create enhanced demo with fixed HTML rendering bugs"""
436
 
437
  # Get unified status
438
  arf_display = ARF_UNIFIED_STATUS['display_text']
439
  arf_badge_class = ARF_UNIFIED_STATUS['badge_class']
 
440
 
441
  with gr.Blocks(
442
  title=f"ARF {ARF_UNIFIED_STATUS['version']} - Mathematical Sophistication",
443
  theme=gr.themes.Soft(
444
  primary_hue="blue",
445
+ secondary_hue="orange"
 
446
  ),
447
  css=ENHANCED_CSS
448
  ) as demo:
449
 
450
+ # ===== FIXED: HEADER USING gr.HTML() =====
451
+ gr.HTML(f"""
452
  <div style="background: linear-gradient(135deg, #0D47A1, #1565C0); color: white; padding: 30px; border-radius: 15px; margin-bottom: 30px; box-shadow: 0 10px 30px rgba(13, 71, 161, 0.4); position: relative; overflow: hidden;">
453
  <div style="position: absolute; top: 0; right: 0; width: 300px; height: 300px; background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);"></div>
454
 
 
477
  </div>
478
  """)
479
 
480
+ # ===== FIXED: METRICS WITH PROPER CONTAINERS =====
481
  with gr.Row():
482
  metrics = [
483
  ("92%", "Incident Prevention", "Bayesian confidence: 95%", "#4CAF50", "๐Ÿ“Š"),
 
487
  ]
488
 
489
  for value, title, subtitle, color, icon in metrics:
490
+ with gr.Column(scale=1, min_width=200):
491
  gr.HTML(f"""
492
+ <div style="text-align: center; padding: 25px; background: #f8f9fa; border-radius: 15px; border-top: 6px solid {color}; box-shadow: 0 8px 25px rgba(0,0,0,0.1); transition: all 0.3s; margin: 10px;">
493
  <div style="font-size: 40px; color: {color}; margin-bottom: 10px; display: flex; align-items: center; justify-content: center; gap: 10px;">
494
  <span style="font-size: 30px;">{icon}</span>
495
  <span style="font-weight: bold;">{value}</span>
 
499
  </div>
500
  """)
501
 
502
+ # ===== FIXED: SECTION HEADERS =====
503
+ gr.HTML("""
504
+ <div style="margin: 30px 0 20px 0;">
505
+ <h2 style="font-size: 1.8em; color: #0D47A1; margin-bottom: 10px;">๐Ÿงฎ Mathematical Execution Authority Demo</h2>
506
+ <p style="color: #666; font-size: 1.05em;">Test how Bayesian risk assessment and mechanical gates prevent unsafe AI actions</p>
507
+ </div>
508
  """)
509
 
510
+ # ===== CONTROL PANEL =====
511
  with gr.Row():
 
512
  with gr.Column(scale=2):
513
  scenario = gr.Dropdown(
514
  label="๐Ÿข Select Enterprise Scenario",
 
540
  test_btn = gr.Button("โšก Test Mathematical Assessment", variant="primary", scale=2)
541
  trial_btn = gr.Button("๐ŸŽ Generate Mathematical Trial", variant="secondary", scale=1)
542
 
543
+ # ===== FIXED: LICENSE DISPLAY =====
544
  with gr.Column(scale=1):
545
  license_display = gr.HTML(f"""
546
  <div class="mathematical-card license-oss">
 
565
  </div>
566
  """)
567
 
568
+ # ===== FIXED: RESULTS PANELS =====
569
  with gr.Row():
 
570
  with gr.Column(scale=1):
571
  oss_results = gr.HTML("""
572
  <div class="mathematical-card license-oss">
 
578
  <div style="text-align: center; margin: 30px 0;">
579
  <div style="font-size: 56px; font-weight: bold; color: #1E88E5; margin-bottom: 5px;">--</div>
580
  <div style="font-size: 14px; color: #666; margin-bottom: 15px;">Risk Score (Bayesian)</div>
581
+ <div style="margin-top: 10px;"></div>
582
  </div>
583
 
584
  <div style="background: rgba(244, 67, 54, 0.1); padding: 18px; border-radius: 10px; margin: 15px 0; border-left: 5px solid #F44336;">
 
592
 
593
  <div style="background: rgba(255, 152, 0, 0.1); padding: 16px; border-radius: 10px; margin-top: 20px;">
594
  <strong style="color: #F57C00; font-size: 1.05em;">๐Ÿ“‹ Bayesian Recommendation:</strong>
595
+ <div style="font-size: 0.95em; margin-top: 8px; line-height: 1.5;">
596
  Awaiting mathematical assessment...
597
  </div>
598
  </div>
599
  </div>
600
  """)
601
 
 
602
  with gr.Column(scale=1):
603
  enterprise_results = gr.HTML(f"""
604
  <div class="mathematical-card license-trial">
605
  <h3 style="margin-top: 0; color: #FFB300; display: flex; align-items: center;">
606
+ <span>Trial Edition</span>
607
  <span style="margin-left: auto; font-size: 0.7em; background: #FFB300; color: white; padding: 4px 12px; border-radius: 15px;">Mechanical</span>
608
  </h3>
609
 
610
  <div style="text-align: center; margin: 30px 0;">
611
+ <div style="font-size: 56px; font-weight: bold; color: #FFB300; margin-bottom: 5px;">--</div>
612
  <div style="font-size: 14px; color: #666; margin-bottom: 15px;">Risk Score (Bayesian)</div>
613
+ <div style="margin-top: 10px;"></div>
614
  </div>
615
 
616
+ <div>
617
  <div style="font-size: 14px; color: #666; margin-bottom: 15px; font-weight: 600;">Mathematical Gates:</div>
618
  <div class="gate-container">
619
  <div class="mathematical-gate gate-pending">1</div>
 
626
 
627
  <div style="background: rgba(255, 152, 0, 0.1); padding: 18px; border-radius: 10px; margin-top: 25px;">
628
  <strong style="color: #F57C00; font-size: 1.1em;">๐Ÿ›ก๏ธ Mechanical Enforcement:</strong>
629
+ <div style="font-size: 0.95em; margin-top: 8px; line-height: 1.5;">
630
  Awaiting mathematical assessment...
631
  </div>
632
  </div>
633
  </div>
634
  """)
635
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
636
  # ===== EVENT HANDLERS =====
637
  def update_context(scenario_name):
638
  """Update context with mathematical analysis"""
 
673
  # Simulate enhanced assessment
674
  action_lower = scenario_name.lower()
675
 
676
+ # Base risk calculation
677
  base_risk = 0.3
678
 
679
  if 'drop database' in action_lower:
 
718
  final_risk = base_risk * risk_multiplier
719
  final_risk = min(0.99, max(0.1, final_risk))
720
 
721
+ # Calculate confidence
722
+ confidence = 0.8 + (random.random() * 0.15)
723
 
724
  # Confidence interval
725
  ci_lower = max(0.1, final_risk - (0.2 * (1 - confidence)))
 
784
  gate_decision = "BLOCKED"
785
  gate_reason = "Failed critical mathematical gates"
786
 
 
 
 
 
 
 
 
 
787
  # Create action data
788
  action_data = {
789
  'time': datetime.now().strftime("%H:%M:%S"),
 
795
  'gates_passed': gates_passed,
796
  'total_gates': total_gates,
797
  'gate_decision': gate_decision,
798
+ 'processing_time_ms': round((time.time() - start_time) * 1000, 1),
799
+ 'arf_status': 'REAL' if ARF_UNIFIED_STATUS['is_real'] else 'SIM'
 
800
  }
801
 
802
  demo_state.add_action(action_data)
 
826
  enforcement = f"โœ… MATHEMATICAL APPROVAL: {gate_reason}. Confidence interval: {ci_lower:.0%}-{ci_upper:.0%}"
827
 
828
  # Gate visualization
829
+ gates_visualization = ""
830
+ for i in range(total_gates):
831
+ gate_class = "gate-passed" if i < gates_passed else "gate-failed"
832
+ gates_visualization += f"""
833
+ <div class="mathematical-gate {gate_class}">{i+1}</div>
834
+ {'<div class="gate-line"></div>' if i < total_gates-1 else ''}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
835
  """
836
 
837
+ gates_html = f"""
838
+ <div style="font-size: 14px; color: #666; margin-bottom: 15px; font-weight: 600;">
839
+ Mathematical Gates: {gates_passed}/{total_gates} passed ({(gates_passed/total_gates)*100:.0f}%)
840
+ </div>
841
+ <div class="gate-container">
842
+ {gates_visualization}
843
+ </div>
844
+ """
845
+
846
  # Tier info
847
  tier_data = {
848
  'oss': {'color': '#1E88E5', 'bg': '#E3F2FD', 'name': 'OSS Edition'},
 
855
  current_tier = license_tier
856
  tier_info = tier_data.get(current_tier, tier_data['oss'])
857
 
 
 
 
 
858
  # Update panels
859
  oss_html = f"""
860
  <div class="mathematical-card license-oss">
 
906
  <strong style="color: {tier_info['color']}; font-size: 1.1em;">๐Ÿ›ก๏ธ Mechanical Enforcement:</strong>
907
  <div style="font-size: 0.95em; margin-top: 8px; line-height: 1.5;">{enforcement}</div>
908
  </div>
 
 
 
 
 
 
 
 
909
  </div>
910
  """
911
 
 
922
  </p>
923
  <div style="background: rgba(30, 136, 229, 0.12); padding: 15px; border-radius: 10px; border-left: 4px solid {tier_info['color']};">
924
  <div style="font-size: 0.9em; color: {tier_info['color']}; line-height: 1.6;">
925
+ <strong>Execution Level:</strong> {'AUTONOMOUS_HIGH' if current_tier == 'enterprise' else 'OPERATOR_REVIEW' if current_tier == 'trial' else 'ADVISORY_ONLY'}<br>
926
  <strong>Risk Prevention:</strong> {92 if current_tier == 'enterprise' else 85 if current_tier == 'professional' else 70 if current_tier == 'starter' else 50 if current_tier == 'trial' else 0}%<br>
927
  <strong>Confidence Threshold:</strong> {90 if current_tier == 'enterprise' else 80 if current_tier == 'professional' else 70 if current_tier == 'starter' else 60 if current_tier == 'trial' else 0}%<br>
928
  <strong>ARF Status:</strong> {arf_display}
 
949
 
950
  history_rows += f"""
951
  <tr>
952
+ <td style="padding: 12px; border-bottom: 1px solid #eee; color: #555; font-size: 13px;">{entry['time']}</td>
953
+ <td style="padding: 12px; border-bottom: 1px solid #eee; color: #555; font-size: 13px;">{entry['action'][:35]}...</td>
954
+ <td style="padding: 12px; border-bottom: 1px solid #eee; font-size: 13px;">{risk_text}</td>
955
+ <td style="padding: 12px; border-bottom: 1px solid #eee; color: #555; font-size: 13px;">{confidence_text}</td>
956
+ <td style="padding: 12px; border-bottom: 1px solid #eee; color: #555; font-size: 13px;">{entry['license_tier']}</td>
957
+ <td style="padding: 12px; border-bottom: 1px solid #eee; color: {gates_color}; font-weight: bold; font-size: 13px;">{gates_text}</td>
958
+ <td style="padding: 12px; border-bottom: 1px solid #eee; font-size: 16px;">{decision_emoji}</td>
959
+ <td style="padding: 12px; border-bottom: 1px solid #eee; text-align: center; font-size: 16px;">{arf_emoji}</td>
960
  </tr>
961
  """
962
 
963
  history_html = f"""
964
+ <div style="border: 1px solid #E0E0E0; border-radius: 15px; padding: 20px; background: #fafafa; box-shadow: 0 8px 30px rgba(0,0,0,0.08); margin-top: 20px;">
965
+ <h4 style="margin-top: 0; margin-bottom: 15px; color: #333;">๐Ÿ“Š Mathematical Action History</h4>
966
+ <div style="overflow-x: auto;">
967
+ <table style="width: 100%; border-collapse: collapse; font-size: 13px; min-width: 600px;">
968
+ <thead>
969
+ <tr style="background: #f5f5f5;">
970
+ <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">Time</th>
971
+ <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">Action</th>
972
+ <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">Risk</th>
973
+ <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">Confidence</th>
974
+ <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">License</th>
975
+ <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">Gates</th>
976
+ <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">Decision</th>
977
+ <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">ARF</th>
978
+ </tr>
979
+ </thead>
980
+ <tbody>
981
+ {history_rows if history_rows else """
982
+ <tr>
983
+ <td colspan="8" style="text-align: center; padding: 40px; color: #999; font-style: italic;">
984
+ No mathematical assessments yet. Test an action to see Bayesian analysis in action.
985
+ </td>
986
+ </tr>
987
+ """}
988
+ </tbody>
989
+ </table>
990
+ </div>
991
  </div>
992
  """
993
 
 
996
  def generate_trial():
997
  """Generate mathematical trial license"""
998
  license_key = generate_mathematical_trial_license()
 
 
999
  return license_key, f"""
1000
+ <div style="text-align: center; padding: 25px; background: linear-gradient(135deg, #FFB300, #FF9800); color: white; border-radius: 15px; box-shadow: 0 12px 40px rgba(255, 179, 0, 0.4);">
1001
+ <h3 style="margin-top: 0; margin-bottom: 15px;">๐ŸŽ‰ Mathematical Trial License Generated!</h3>
1002
+ <div style="background: white; color: #333; padding: 18px; border-radius: 10px; font-family: monospace; margin: 15px 0; font-size: 15px; letter-spacing: 1px; border: 3px dashed #FFB300;">
1003
  {license_key}
1004
  </div>
1005
+ <p style="margin-bottom: 20px;">Copy this key and paste it into the License Key field above.</p>
1006
+ <div style="background: rgba(255,255,255,0.2); padding: 18px; border-radius: 10px; margin-top: 15px;">
1007
+ <div style="font-size: 0.95em; line-height: 1.6;">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1008
  โณ <strong>14-day mathematical trial</strong><br>
1009
  ๐Ÿงฎ <strong>Bayesian analysis with confidence intervals</strong><br>
1010
+ ๐Ÿ›ก๏ธ <strong>Mechanical gates with mathematical weights</strong>
 
1011
  </div>
1012
  </div>
 
 
 
1013
  </div>
1014
  """
1015
 
 
1023
  test_btn.click(
1024
  fn=test_mathematical_assessment,
1025
  inputs=[scenario, context, license_key],
1026
+ outputs=[oss_results, enterprise_results, license_display]
1027
  )
1028
 
1029
  trial_btn.click(
1030
  fn=generate_trial,
1031
  inputs=[],
1032
+ outputs=[license_key]
 
 
 
 
 
 
 
 
 
 
 
 
1033
  )
1034
 
1035
  return demo
 
1037
  # ============== MAIN EXECUTION ==============
1038
  if __name__ == "__main__":
1039
  print("\n" + "="*80)
1040
+ print("๐Ÿš€ LAUNCHING FIXED ARF 3.3.9 DEMO")
1041
+ print("๐Ÿ“Š ARF Status:", ARF_UNIFIED_STATUS['display_text'])
1042
  print("="*80)
1043
 
1044
  demo = create_enhanced_demo()