petter2025 commited on
Commit
663691e
Β·
verified Β·
1 Parent(s): 90f508c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +92 -22
app.py CHANGED
@@ -2,6 +2,7 @@
2
  # πŸš€ ARF Ultimate Investor Demo v3.3.9 - ENTERPRISE EDITION
3
  # Enhanced with clear OSS vs Enterprise boundaries
4
  # UPDATED: Added realism panel integration for enterprise-seasoned SRE experience
 
5
 
6
  import logging
7
  import sys
@@ -210,7 +211,7 @@ class AsyncRunner:
210
  """Decorator to convert async function to sync"""
211
  def wrapper(*args, **kwargs):
212
  try:
213
- return AsyncRunner.run_async(async_func(*args, **kwargs))
214
  except Exception as e:
215
  logger.error(f"Async to sync conversion failed: {e}")
216
  return {"error": str(e), "status": "failed", "boundary_context": "OSS advisory only - execution requires Enterprise"}
@@ -840,12 +841,12 @@ def import_components() -> Dict[str, Any]:
840
  from ui.styles import get_styles
841
  components["get_styles"] = get_styles
842
 
843
- # Import UI components - IMPORTANT: Now includes create_realism_panel
844
  from ui.components import (
845
  create_header, create_status_bar, create_tab1_incident_demo,
846
  create_tab2_business_roi, create_tab3_enterprise_features,
847
  create_tab4_audit_trail, create_tab5_learning_engine,
848
- create_footer, create_realism_panel
849
  )
850
 
851
  components.update({
@@ -857,7 +858,8 @@ def import_components() -> Dict[str, Any]:
857
  "create_tab4_audit_trail": create_tab4_audit_trail,
858
  "create_tab5_learning_engine": create_tab5_learning_engine,
859
  "create_footer": create_footer,
860
- "create_realism_panel": create_realism_panel # Added for realism panel
 
861
  })
862
 
863
  # Import scenarios
@@ -997,7 +999,7 @@ def import_components() -> Dict[str, Any]:
997
 
998
  components["all_available"] = True
999
  components["error"] = None
1000
- logger.info("βœ… Successfully imported all modular components")
1001
 
1002
  except Exception as e:
1003
  logger.error(f"❌ IMPORT ERROR: {e}")
@@ -1028,6 +1030,47 @@ def import_components() -> Dict[str, Any]:
1028
  "summary": {"roi_multiplier": "5.2Γ—"}
1029
  }
1030
  components["EnhancedROICalculator"] = MinimalROICalculator()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1031
 
1032
  return components
1033
 
@@ -1475,7 +1518,7 @@ class AuditTrailManager:
1475
  <th style="padding: 15px; text-align: left; font-size: 13px; color: #475569; font-weight: 600;">Scenario</th>
1476
  <th style="padding: 15px; text-align: left; font-size: 13px; color: #475569; font-weight: 600;">Status</th>
1477
  <th style="padding: 15px; text-align: left; font-size: 13px; color: #475569; font-weight: 600;">Boundary</th>
1478
- <th style="padding: 15px; text-align: left; font-size: 13px; color: #475569; font-weight: 600;">Time</th>
1479
  </tr>
1480
  </thead>
1481
  <tbody>
@@ -1653,6 +1696,25 @@ def update_scenario_display(scenario_name: str) -> tuple:
1653
  # ============ CHANGE HERE: Add realism_html to return tuple ============
1654
  return scenario_card_html, telemetry_fig, impact_fig, timeline_fig, realism_html
1655
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1656
  # ===========================================
1657
  # SURGICAL FIX: run_true_arf_analysis() - FIXED to return DataFrames
1658
  # ===========================================
@@ -2122,11 +2184,14 @@ def create_demo_interface():
2122
 
2123
  # ============ EVENT HANDLERS ============
2124
 
2125
- # Update scenario display when dropdown changes - ADD realism_panel output
2126
  scenario_dropdown.change(
2127
- fn=update_scenario_display, # ← This now returns 5 values
2128
  inputs=[scenario_dropdown],
2129
- outputs=[scenario_card, telemetry_viz, impact_viz, timeline_viz, realism_panel] # ← Added realism_panel
 
 
 
2130
  )
2131
 
2132
  # Run OSS Analysis - FIXED: Now returns DataFrame for incident_table
@@ -2150,8 +2215,8 @@ def create_demo_interface():
2150
  @AsyncRunner.async_to_sync
2151
  async def run_complete_demo_async(scenario_name):
2152
  """Run a complete demo walkthrough with true ARF and boundary awareness"""
2153
- # Step 1: Update scenario
2154
- update_result = update_scenario_display(scenario_name)
2155
 
2156
  # Step 2: Run true ARF analysis
2157
  oss_result = await run_true_arf_analysis(scenario_name)
@@ -2162,7 +2227,7 @@ def create_demo_interface():
2162
  scenario = components["INCIDENT_SCENARIOS"].get(scenario_name, {})
2163
  impact = scenario.get("business_impact", {})
2164
  revenue_loss = impact.get("revenue_loss_per_hour", get_scenario_impact(scenario_name))
2165
- savings = int(revenue_loss * 0.85)
2166
 
2167
  # Get boundary context
2168
  boundaries = BoundaryManager.get_system_boundaries()
@@ -2189,7 +2254,7 @@ def create_demo_interface():
2189
  "outcome": {
2190
  "recovery_time": "12 minutes",
2191
  "manual_comparison": "45 minutes",
2192
- "cost_saved": f"${savings:,}",
2193
  "users_protected": "45,000",
2194
  "learning": "Pattern added to RAG memory"
2195
  },
@@ -2249,7 +2314,7 @@ def create_demo_interface():
2249
  β€’ Autonomous execution simulated<br>
2250
  β€’ Rollback guarantee: 100%<br>
2251
  β€’ 12min vs 45min recovery<br>
2252
- β€’ ${savings:,} saved
2253
  </div>
2254
  </div>
2255
  </div>
@@ -2298,7 +2363,7 @@ def create_demo_interface():
2298
  </div>
2299
  <div>
2300
  <div style="font-size: 11px; color: #64748b; margin-bottom: 5px;">Cost Saved</div>
2301
- <div style="font-size: 18px; font-weight: 700; color: #10b981;">${savings:,}</div>
2302
  </div>
2303
  <div>
2304
  <div style="font-size: 11px; color: #64748b; margin-bottom: 5px;">ROI Multiplier</div>
@@ -2340,7 +2405,7 @@ def create_demo_interface():
2340
 
2341
  # Combine all results
2342
  return (
2343
- *update_result, # 5 outputs: scenario_card, telemetry_viz, impact_viz, timeline_viz, realism_panel
2344
  *oss_result[:3], # 3 outputs: detection_agent, recall_agent, decision_agent
2345
  oss_result[3], # 1 output: oss_results_display
2346
  enterprise_results, # 1 output: enterprise_results_display
@@ -2354,7 +2419,8 @@ def create_demo_interface():
2354
  fn=run_complete_demo_async,
2355
  inputs=[scenario_dropdown],
2356
  outputs=[
2357
- scenario_card, telemetry_viz, impact_viz, timeline_viz, realism_panel, # 5
 
2358
  detection_agent, recall_agent, decision_agent, # 3
2359
  oss_results_display, # 1
2360
  enterprise_results_display, # 1
@@ -2468,11 +2534,14 @@ def create_demo_interface():
2468
  outputs=[license_display]
2469
  )
2470
 
2471
- # Load default scenario - UPDATE outputs with realism_panel
2472
  demo.load(
2473
- fn=lambda: update_scenario_display(settings.default_scenario),
2474
  inputs=[],
2475
- outputs=[scenario_card, telemetry_viz, impact_viz, timeline_viz, realism_panel]
 
 
 
2476
  )
2477
 
2478
  # Load ROI data
@@ -2482,7 +2551,7 @@ def create_demo_interface():
2482
  outputs=[roi_output, roi_chart]
2483
  )
2484
 
2485
- logger.info("βœ… Demo interface created successfully with boundary awareness and realism panel")
2486
 
2487
  return demo
2488
 
@@ -2566,6 +2635,7 @@ if __name__ == "__main__":
2566
  logger.info("=" * 60)
2567
  logger.info("Enhanced with clear OSS vs Enterprise boundaries")
2568
  logger.info("Now with Realism Panel for enterprise-seasoned SRE experience")
 
2569
  logger.info(f"True ARF OSS v3.3.9 integration with simulated Enterprise execution")
2570
  logger.info("=" * 60)
2571
 
@@ -2575,7 +2645,7 @@ if __name__ == "__main__":
2575
  print("\n" + "="*60)
2576
  print("πŸš€ ARF Ultimate Investor Demo v3.3.9 - ENTERPRISE EDITION")
2577
  print("πŸ“Š Architecture: OSS advises β†’ Enterprise executes")
2578
- print("🎭 New: Realism Panel with ranked actions & uncertainty")
2579
  print("🌐 Starting on http://localhost:7860")
2580
  print("="*60 + "\n")
2581
 
 
2
  # πŸš€ ARF Ultimate Investor Demo v3.3.9 - ENTERPRISE EDITION
3
  # Enhanced with clear OSS vs Enterprise boundaries
4
  # UPDATED: Added realism panel integration for enterprise-seasoned SRE experience
5
+ # UPDATED: Added dynamic performance metrics for Phase 2
6
 
7
  import logging
8
  import sys
 
211
  """Decorator to convert async function to sync"""
212
  def wrapper(*args, **kwargs):
213
  try:
214
+ return AsyncRunner.run_until_complete(async_func(*args, **kwargs))
215
  except Exception as e:
216
  logger.error(f"Async to sync conversion failed: {e}")
217
  return {"error": str(e), "status": "failed", "boundary_context": "OSS advisory only - execution requires Enterprise"}
 
841
  from ui.styles import get_styles
842
  components["get_styles"] = get_styles
843
 
844
+ # Import UI components - IMPORTANT: Now includes create_realism_panel AND update_performance_metrics
845
  from ui.components import (
846
  create_header, create_status_bar, create_tab1_incident_demo,
847
  create_tab2_business_roi, create_tab3_enterprise_features,
848
  create_tab4_audit_trail, create_tab5_learning_engine,
849
+ create_footer, create_realism_panel, update_performance_metrics # Added update_performance_metrics
850
  )
851
 
852
  components.update({
 
858
  "create_tab4_audit_trail": create_tab4_audit_trail,
859
  "create_tab5_learning_engine": create_tab5_learning_engine,
860
  "create_footer": create_footer,
861
+ "create_realism_panel": create_realism_panel,
862
+ "update_performance_metrics": update_performance_metrics # Added for dynamic metrics
863
  })
864
 
865
  # Import scenarios
 
999
 
1000
  components["all_available"] = True
1001
  components["error"] = None
1002
+ logger.info("βœ… Successfully imported all modular components including update_performance_metrics")
1003
 
1004
  except Exception as e:
1005
  logger.error(f"❌ IMPORT ERROR: {e}")
 
1030
  "summary": {"roi_multiplier": "5.2Γ—"}
1031
  }
1032
  components["EnhancedROICalculator"] = MinimalROICalculator()
1033
+
1034
+ # Ensure update_performance_metrics exists
1035
+ if "update_performance_metrics" not in components:
1036
+ def fallback_performance_metrics(scenario_name: str):
1037
+ """Fallback function if the real one fails"""
1038
+ logger.warning(f"Using fallback performance metrics for {scenario_name}")
1039
+ return (
1040
+ """<div style="border: 1px solid #e2e8f0; border-radius: 12px; padding: 18px; background: white; margin: 8px; text-align: center; flex: 1; min-width: 140px; border-left: 4px solid #3b82f6;">
1041
+ <div style="font-size: 28px; margin-bottom: 10px;">⏱️</div>
1042
+ <div>
1043
+ <h4 style="margin: 0 0 8px 0; font-size: 14px; color: #64748b; font-weight: 600;">Detection Time</h4>
1044
+ <p style="font-size: 28px; font-weight: bold; color: #1e40af; margin: 8px 0;">42s</p>
1045
+ <p style="font-size: 12px; color: #64748b; margin: 0;">↓ 90% faster than average</p>
1046
+ </div>
1047
+ </div>""",
1048
+ """<div style="border: 1px solid #e2e8f0; border-radius: 12px; padding: 18px; background: white; margin: 8px; text-align: center; flex: 1; min-width: 140px; border-left: 4px solid #10b981;">
1049
+ <div style="font-size: 28px; margin-bottom: 10px;">⚑</div>
1050
+ <div>
1051
+ <h4 style="margin: 0 0 8px 0; font-size: 14px; color: #64748b; font-weight: 600;">Mean Time to Resolve</h4>
1052
+ <p style="font-size: 28px; font-weight: bold; color: #10b981; margin: 8px 0;">14m</p>
1053
+ <p style="font-size: 12px; color: #64748b; margin: 0;">↓ 70% faster than manual</p>
1054
+ </div>
1055
+ </div>""",
1056
+ """<div style="border: 1px solid #e2e8f0; border-radius: 12px; padding: 18px; background: white; margin: 8px; text-align: center; flex: 1; min-width: 140px; border-left: 4px solid #8b5cf6;">
1057
+ <div style="font-size: 28px; margin-bottom: 10px;">πŸ€–</div>
1058
+ <div>
1059
+ <h4 style="margin: 0 0 8px 0; font-size: 14px; color: #64748b; font-weight: 600;">Auto-Heal Rate</h4>
1060
+ <p style="font-size: 28px; font-weight: bold; color: #8b5cf6; margin: 8px 0;">78.9%</p>
1061
+ <p style="font-size: 12px; color: #64748b; margin: 0;">↑ 5.0Γ— industry average</p>
1062
+ </div>
1063
+ </div>""",
1064
+ """<div style="border: 1px solid #e2e8f0; border-radius: 12px; padding: 18px; background: white; margin: 8px; text-align: center; flex: 1; min-width: 140px; border-left: 4px solid #f59e0b;">
1065
+ <div style="font-size: 28px; margin-bottom: 10px;">πŸ’°</div>
1066
+ <div>
1067
+ <h4 style="margin: 0 0 8px 0; font-size: 14px; color: #64748b; font-weight: 600;">Cost Saved</h4>
1068
+ <p style="font-size: 28px; font-weight: bold; color: #f59e0b; margin: 8px 0;">$7.2K</p>
1069
+ <p style="font-size: 12px; color: #64748b; margin: 0;">Per incident avoided</p>
1070
+ </div>
1071
+ </div>"""
1072
+ )
1073
+ components["update_performance_metrics"] = fallback_performance_metrics
1074
 
1075
  return components
1076
 
 
1518
  <th style="padding: 15px; text-align: left; font-size: 13px; color: #475569; font-weight: 600;">Scenario</th>
1519
  <th style="padding: 15px; text-align: left; font-size: 13px; color: #475569; font-weight: 600;">Status</th>
1520
  <th style="padding: 15px; text-align: left; font-size: 13px; color: #475569; font-weight: 600;">Boundary</th>
1521
+ <th style="padding: 15px; text-align: left; font-size: 13px; color: #475569; font-weight=600;">Time</th>
1522
  </tr>
1523
  </thead>
1524
  <tbody>
 
1696
  # ============ CHANGE HERE: Add realism_html to return tuple ============
1697
  return scenario_card_html, telemetry_fig, impact_fig, timeline_fig, realism_html
1698
 
1699
+ # ===========================================
1700
+ # ENHANCED: Combined update function for scenario display + performance metrics
1701
+ # ===========================================
1702
+ def update_scenario_display_with_metrics(scenario_name: str) -> tuple:
1703
+ """
1704
+ Combined update function that returns both scenario display AND performance metrics.
1705
+ Returns 9 values: (scenario_card, telemetry_viz, impact_viz, timeline_viz, realism_panel,
1706
+ detection_time_html, mttr_html, auto_heal_html, savings_html)
1707
+ """
1708
+ # Get the scenario display components (5 outputs)
1709
+ scenario_card, telemetry_fig, impact_fig, timeline_fig, realism_html = update_scenario_display(scenario_name)
1710
+
1711
+ # Get performance metrics (4 outputs)
1712
+ components = get_components()
1713
+ detection_time_html, mttr_html, auto_heal_html, savings_html = components["update_performance_metrics"](scenario_name)
1714
+
1715
+ return (scenario_card, telemetry_fig, impact_fig, timeline_fig, realism_html,
1716
+ detection_time_html, mttr_html, auto_heal_html, savings_html)
1717
+
1718
  # ===========================================
1719
  # SURGICAL FIX: run_true_arf_analysis() - FIXED to return DataFrames
1720
  # ===========================================
 
2184
 
2185
  # ============ EVENT HANDLERS ============
2186
 
2187
+ # Update scenario display when dropdown changes - NOW INCLUDES PERFORMANCE METRICS
2188
  scenario_dropdown.change(
2189
+ fn=update_scenario_display_with_metrics, # ← Changed to combined function
2190
  inputs=[scenario_dropdown],
2191
+ outputs=[
2192
+ scenario_card, telemetry_viz, impact_viz, timeline_viz, realism_panel,
2193
+ detection_time, mttr, auto_heal, savings # 4 new outputs for metrics
2194
+ ]
2195
  )
2196
 
2197
  # Run OSS Analysis - FIXED: Now returns DataFrame for incident_table
 
2215
  @AsyncRunner.async_to_sync
2216
  async def run_complete_demo_async(scenario_name):
2217
  """Run a complete demo walkthrough with true ARF and boundary awareness"""
2218
+ # Step 1: Update scenario with metrics
2219
+ update_result = update_scenario_display_with_metrics(scenario_name)
2220
 
2221
  # Step 2: Run true ARF analysis
2222
  oss_result = await run_true_arf_analysis(scenario_name)
 
2227
  scenario = components["INCIDENT_SCENARIOS"].get(scenario_name, {})
2228
  impact = scenario.get("business_impact", {})
2229
  revenue_loss = impact.get("revenue_loss_per_hour", get_scenario_impact(scenario_name))
2230
+ savings_amount = int(revenue_loss * 0.85)
2231
 
2232
  # Get boundary context
2233
  boundaries = BoundaryManager.get_system_boundaries()
 
2254
  "outcome": {
2255
  "recovery_time": "12 minutes",
2256
  "manual_comparison": "45 minutes",
2257
+ "cost_saved": f"${savings_amount:,}",
2258
  "users_protected": "45,000",
2259
  "learning": "Pattern added to RAG memory"
2260
  },
 
2314
  β€’ Autonomous execution simulated<br>
2315
  β€’ Rollback guarantee: 100%<br>
2316
  β€’ 12min vs 45min recovery<br>
2317
+ β€’ ${savings_amount:,} saved
2318
  </div>
2319
  </div>
2320
  </div>
 
2363
  </div>
2364
  <div>
2365
  <div style="font-size: 11px; color: #64748b; margin-bottom: 5px;">Cost Saved</div>
2366
+ <div style="font-size: 18px; font-weight: 700; color: #10b981;">${savings_amount:,}</div>
2367
  </div>
2368
  <div>
2369
  <div style="font-size: 11px; color: #64748b; margin-bottom: 5px;">ROI Multiplier</div>
 
2405
 
2406
  # Combine all results
2407
  return (
2408
+ *update_result, # 9 outputs: scenario_card, telemetry_viz, impact_viz, timeline_viz, realism_panel, detection_time, mttr, auto_heal, savings
2409
  *oss_result[:3], # 3 outputs: detection_agent, recall_agent, decision_agent
2410
  oss_result[3], # 1 output: oss_results_display
2411
  enterprise_results, # 1 output: enterprise_results_display
 
2419
  fn=run_complete_demo_async,
2420
  inputs=[scenario_dropdown],
2421
  outputs=[
2422
+ scenario_card, telemetry_viz, impact_viz, timeline_viz, realism_panel,
2423
+ detection_time, mttr, auto_heal, savings, # 9
2424
  detection_agent, recall_agent, decision_agent, # 3
2425
  oss_results_display, # 1
2426
  enterprise_results_display, # 1
 
2534
  outputs=[license_display]
2535
  )
2536
 
2537
+ # Load default scenario - UPDATE outputs with realism_panel AND performance metrics
2538
  demo.load(
2539
+ fn=lambda: update_scenario_display_with_metrics(settings.default_scenario),
2540
  inputs=[],
2541
+ outputs=[
2542
+ scenario_card, telemetry_viz, impact_viz, timeline_viz, realism_panel,
2543
+ detection_time, mttr, auto_heal, savings
2544
+ ]
2545
  )
2546
 
2547
  # Load ROI data
 
2551
  outputs=[roi_output, roi_chart]
2552
  )
2553
 
2554
+ logger.info("βœ… Demo interface created successfully with boundary awareness, realism panel, and dynamic performance metrics")
2555
 
2556
  return demo
2557
 
 
2635
  logger.info("=" * 60)
2636
  logger.info("Enhanced with clear OSS vs Enterprise boundaries")
2637
  logger.info("Now with Realism Panel for enterprise-seasoned SRE experience")
2638
+ logger.info("PHASE 2: Dynamic Performance Metrics by Scenario Type")
2639
  logger.info(f"True ARF OSS v3.3.9 integration with simulated Enterprise execution")
2640
  logger.info("=" * 60)
2641
 
 
2645
  print("\n" + "="*60)
2646
  print("πŸš€ ARF Ultimate Investor Demo v3.3.9 - ENTERPRISE EDITION")
2647
  print("πŸ“Š Architecture: OSS advises β†’ Enterprise executes")
2648
+ print("🎭 Phase 2: Dynamic Performance Metrics by Scenario")
2649
  print("🌐 Starting on http://localhost:7860")
2650
  print("="*60 + "\n")
2651