petter2025 commited on
Commit
8f8a739
·
verified ·
1 Parent(s): e0ae759

Update ui/components.py

Browse files
Files changed (1) hide show
  1. ui/components.py +45 -49
ui/components.py CHANGED
@@ -1050,7 +1050,7 @@ def create_historical_evidence_panel(scenario_data: Dict[str, Any]) -> gr.HTML:
1050
  def update_performance_metrics(scenario_name: str, scenarios=INCIDENT_SCENARIOS) -> tuple:
1051
  """
1052
  Update performance metrics based on scenario
1053
- Returns: (detection_time_html, mttr_html, auto_heal_html, savings_html)
1054
  Doctrinal: No red/green colors, use gradient colors instead of binary thresholds
1055
  """
1056
 
@@ -1058,38 +1058,37 @@ def update_performance_metrics(scenario_name: str, scenarios=INCIDENT_SCENARIOS)
1058
  metrics_config = {
1059
  "Cache": {
1060
  "detection_time": ("45s", "89% faster", "linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%)"),
1061
- "mttr": ("12m", "73% reduction", "linear-gradient(135deg, #10b981 0%, #047857 100%)"),
1062
- "auto_heal": ("82%", "5.4× improvement", "linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%)"),
 
1063
  "savings_multiplier": 0.85
1064
  },
1065
  "Database": {
1066
  "detection_time": ("38s", "91% faster", "linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%)"),
1067
- "mttr": ("18m", "68% reduction", "linear-gradient(135deg, #10b981 0%, #047857 100%)"),
1068
- "auto_heal": ("74%", "4.8× improvement", "linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%)"),
 
1069
  "savings_multiplier": 0.82
1070
  },
1071
  "Kubernetes": {
1072
  "detection_time": ("52s", "87% faster", "linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%)"),
1073
- "mttr": ("15m", "71% reduction", "linear-gradient(135deg, #10b981 0%, #047857 100%)"),
1074
- "auto_heal": ("79%", "5.1× improvement", "linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%)"),
 
1075
  "savings_multiplier": 0.83
1076
  },
1077
  "Network": {
1078
  "detection_time": ("28s", "93% faster", "linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%)"),
1079
- "mttr": ("8m", "82% reduction", "linear-gradient(135deg, #10b981 0%, #047857 100%)"),
1080
- "auto_heal": ("89%", "6.2× improvement", "linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%)"),
 
1081
  "savings_multiplier": 0.88
1082
  },
1083
- "Storage": {
1084
- "detection_time": ("35s", "92% faster", "linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%)"),
1085
- "mttr": ("22m", "65% reduction", "linear-gradient(135deg, #10b981 0%, #047857 100%)"),
1086
- "auto_heal": ("72%", "4.6× improvement", "linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%)"),
1087
- "savings_multiplier": 0.80
1088
- },
1089
  "Default": {
1090
  "detection_time": ("42s", "90% faster", "linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%)"),
1091
- "mttr": ("14m", "70% reduction", "linear-gradient(135deg, #10b981 0%, #047857 100%)"),
1092
- "auto_heal": ("79%", "5.0× improvement", "linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%)"),
 
1093
  "savings_multiplier": 0.85
1094
  }
1095
  }
@@ -1104,12 +1103,6 @@ def update_performance_metrics(scenario_name: str, scenarios=INCIDENT_SCENARIOS)
1104
  # Get metrics for scenario type
1105
  metrics = metrics_config.get(scenario_type, metrics_config["Default"])
1106
 
1107
- # Get scenario data for savings calculation
1108
- scenario_data = scenarios.get(scenario_name, {})
1109
- business_impact = scenario_data.get("business_impact", {})
1110
- revenue_loss = business_impact.get('revenue_risk_per_hour', 8500) # Changed from 'revenue_loss_per_hour'
1111
- savings_amount = int(revenue_loss * metrics["savings_multiplier"] / 1000)
1112
-
1113
  # Create HTML for each metric card WITH GRADIENT BORDERS
1114
  detection_time_html = f"""
1115
  <div style="border: 1px solid #e2e8f0; border-radius: 12px; padding: 18px; background: white; margin: 8px; text-align: center; flex: 1; min-width: 140px;
@@ -1123,44 +1116,44 @@ def update_performance_metrics(scenario_name: str, scenarios=INCIDENT_SCENARIOS)
1123
  </div>
1124
  """
1125
 
1126
- mttr_html = f"""
1127
  <div style="border: 1px solid #e2e8f0; border-radius: 12px; padding: 18px; background: white; margin: 8px; text-align: center; flex: 1; min-width: 140px;
1128
- border-left: 4px solid; border-image: {metrics['mttr'][2]}; border-image-slice: 1;">
1129
- <div style="font-size: 28px; margin-bottom: 10px;"></div>
1130
  <div>
1131
- <h4 style="margin: 0 0 8px 0; font-size: 14px; color: #64748b; font-weight: 600;">Mean Time to Resolve</h4>
1132
- <p style="font-size: 28px; font-weight: bold; background: {metrics['mttr'][2]}; -webkit-background-clip: text; -webkit-text-fill-color: transparent; margin: 8px 0;">{metrics['mttr'][0]}</p>
1133
- <p style="font-size: 12px; color: #64748b; margin: 0;">{metrics['mttr'][1]} than manual</p>
1134
  </div>
1135
  </div>
1136
  """
1137
 
1138
- auto_heal_html = f"""
1139
  <div style="border: 1px solid #e2e8f0; border-radius: 12px; padding: 18px; background: white; margin: 8px; text-align: center; flex: 1; min-width: 140px;
1140
- border-left: 4px solid; border-image: {metrics['auto_heal'][2]}; border-image-slice: 1;">
1141
- <div style="font-size: 28px; margin-bottom: 10px;">🛡️</div>
1142
  <div>
1143
- <h4 style="margin: 0 0 8px 0; font-size: 14px; color: #64748b; font-weight: 600;">Auto-Heal Rate</h4>
1144
- <p style="font-size: 28px; font-weight: bold; background: {metrics['auto_heal'][2]}; -webkit-background-clip: text; -webkit-text-fill-color: transparent; margin: 8px 0;">{metrics['auto_heal'][0]}</p>
1145
- <p style="font-size: 12px; color: #64748b; margin: 0;">{metrics['auto_heal'][1]}</p>
1146
  </div>
1147
  </div>
1148
  """
1149
 
1150
- savings_html = f"""
1151
  <div style="border: 1px solid #e2e8f0; border-radius: 12px; padding: 18px; background: white; margin: 8px; text-align: center; flex: 1; min-width: 140px;
1152
- border-left: 4px solid; border-image: linear-gradient(135deg, #f59e0b 0%, #d97706 100%); border-image-slice: 1;">
1153
- <div style="font-size: 28px; margin-bottom: 10px;">💰</div>
1154
  <div>
1155
- <h4 style="margin: 0 0 8px 0; font-size: 14px; color: #64748b; font-weight: 600;">Cost Avoided</h4>
1156
- <p style="font-size: 28px; font-weight: bold; background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; margin: 8px 0;">${savings_amount:.1f}K</p>
1157
- <p style="font-size: 12px; color: #64748b; margin: 0;">Per incident avoided</p>
1158
  </div>
1159
  </div>
1160
  """
1161
 
1162
  logger.info(f"��� Updated performance metrics for {scenario_name} ({scenario_type} type)")
1163
- return detection_time_html, mttr_html, auto_heal_html, savings_html
1164
 
1165
  # -----------------------------
1166
  # Tab 1: Live Incident Demo - UPDATED WITH RESTORED FUNCTIONS
@@ -1409,11 +1402,12 @@ def create_tab1_incident_demo(scenarios=INCIDENT_SCENARIOS, default_scenario="Ca
1409
  # Real-time Metrics Dashboard
1410
  metrics_header = gr.Markdown("## 📊 Performance Metrics")
1411
 
1412
- # Metric Cards Grid - CALL update_performance_metrics function
 
1413
  detection_time = gr.HTML()
1414
- mttr = gr.HTML()
1415
- auto_heal = gr.HTML()
1416
- savings = gr.HTML()
1417
 
1418
  # Results Display Areas
1419
  oss_results_header = gr.Markdown("### 🆓 Policy Analysis Results")
@@ -1474,9 +1468,11 @@ def create_tab1_incident_demo(scenarios=INCIDENT_SCENARIOS, default_scenario="Ca
1474
  observation_gate_placeholder, sequencing_panel, workflow_header, detection_process,
1475
  recall_process, decision_process, oss_section, enterprise_section, oss_btn, enterprise_btn,
1476
  approval_toggle, mcp_mode, timeline_viz,
1477
- # Right column returns
1478
- detection_time, mttr, auto_heal, savings,
1479
- oss_results_display, enterprise_results_display, approval_display, demo_btn
 
 
1480
  )
1481
 
1482
  # -----------------------------
 
1050
  def update_performance_metrics(scenario_name: str, scenarios=INCIDENT_SCENARIOS) -> tuple:
1051
  """
1052
  Update performance metrics based on scenario
1053
+ Returns: (detection_time_html, recall_quality_html, confidence_score_html, sequencing_stage_html)
1054
  Doctrinal: No red/green colors, use gradient colors instead of binary thresholds
1055
  """
1056
 
 
1058
  metrics_config = {
1059
  "Cache": {
1060
  "detection_time": ("45s", "89% faster", "linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%)"),
1061
+ "recall_quality": ("92%", "85% accuracy", "linear-gradient(135deg, #10b981 0%, #047857 100%)"),
1062
+ "confidence_score": ("87%", "High certainty", "linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%)"),
1063
+ "sequencing_stage": ("Dampening", "Step 1/4", "linear-gradient(135deg, #f59e0b 0%, #d97706 100%)"),
1064
  "savings_multiplier": 0.85
1065
  },
1066
  "Database": {
1067
  "detection_time": ("38s", "91% faster", "linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%)"),
1068
+ "recall_quality": ("89%", "82% accuracy", "linear-gradient(135deg, #10b981 0%, #047857 100%)"),
1069
+ "confidence_score": ("84%", "High certainty", "linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%)"),
1070
+ "sequencing_stage": ("Concurrency", "Step 2/4", "linear-gradient(135deg, #f59e0b 0%, #d97706 100%)"),
1071
  "savings_multiplier": 0.82
1072
  },
1073
  "Kubernetes": {
1074
  "detection_time": ("52s", "87% faster", "linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%)"),
1075
+ "recall_quality": ("91%", "84% accuracy", "linear-gradient(135deg, #10b981 0%, #047857 100%)"),
1076
+ "confidence_score": ("86%", "High certainty", "linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%)"),
1077
+ "sequencing_stage": ("Observe", "Step 3/4", "linear-gradient(135deg, #f59e0b 0%, #d97706 100%)"),
1078
  "savings_multiplier": 0.83
1079
  },
1080
  "Network": {
1081
  "detection_time": ("28s", "93% faster", "linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%)"),
1082
+ "recall_quality": ("94%", "88% accuracy", "linear-gradient(135deg, #10b981 0%, #047857 100%)"),
1083
+ "confidence_score": ("89%", "High certainty", "linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%)"),
1084
+ "sequencing_stage": ("Scale", "Step 4/4", "linear-gradient(135deg, #f59e0b 0%, #d97706 100%)"),
1085
  "savings_multiplier": 0.88
1086
  },
 
 
 
 
 
 
1087
  "Default": {
1088
  "detection_time": ("42s", "90% faster", "linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%)"),
1089
+ "recall_quality": ("90%", "85% accuracy", "linear-gradient(135deg, #10b981 0%, #047857 100%)"),
1090
+ "confidence_score": ("85%", "High certainty", "linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%)"),
1091
+ "sequencing_stage": ("Dampening", "Step 1/4", "linear-gradient(135deg, #f59e0b 0%, #d97706 100%)"),
1092
  "savings_multiplier": 0.85
1093
  }
1094
  }
 
1103
  # Get metrics for scenario type
1104
  metrics = metrics_config.get(scenario_type, metrics_config["Default"])
1105
 
 
 
 
 
 
 
1106
  # Create HTML for each metric card WITH GRADIENT BORDERS
1107
  detection_time_html = f"""
1108
  <div style="border: 1px solid #e2e8f0; border-radius: 12px; padding: 18px; background: white; margin: 8px; text-align: center; flex: 1; min-width: 140px;
 
1116
  </div>
1117
  """
1118
 
1119
+ recall_quality_html = f"""
1120
  <div style="border: 1px solid #e2e8f0; border-radius: 12px; padding: 18px; background: white; margin: 8px; text-align: center; flex: 1; min-width: 140px;
1121
+ border-left: 4px solid; border-image: {metrics['recall_quality'][2]}; border-image-slice: 1;">
1122
+ <div style="font-size: 28px; margin-bottom: 10px;">🧠</div>
1123
  <div>
1124
+ <h4 style="margin: 0 0 8px 0; font-size: 14px; color: #64748b; font-weight: 600;">Recall Quality</h4>
1125
+ <p style="font-size: 28px; font-weight: bold; background: {metrics['recall_quality'][2]}; -webkit-background-clip: text; -webkit-text-fill-color: transparent; margin: 8px 0;">{metrics['recall_quality'][0]}</p>
1126
+ <p style="font-size: 12px; color: #64748b; margin: 0;">{metrics['recall_quality'][1]}</p>
1127
  </div>
1128
  </div>
1129
  """
1130
 
1131
+ confidence_score_html = f"""
1132
  <div style="border: 1px solid #e2e8f0; border-radius: 12px; padding: 18px; background: white; margin: 8px; text-align: center; flex: 1; min-width: 140px;
1133
+ border-left: 4px solid; border-image: {metrics['confidence_score'][2]}; border-image-slice: 1;">
1134
+ <div style="font-size: 28px; margin-bottom: 10px;">🎯</div>
1135
  <div>
1136
+ <h4 style="margin: 0 0 8px 0; font-size: 14px; color: #64748b; font-weight: 600;">Confidence Score</h4>
1137
+ <p style="font-size: 28px; font-weight: bold; background: {metrics['confidence_score'][2]}; -webkit-background-clip: text; -webkit-text-fill-color: transparent; margin: 8px 0;">{metrics['confidence_score'][0]}</p>
1138
+ <p style="font-size: 12px; color: #64748b; margin: 0;">{metrics['confidence_score'][1]}</p>
1139
  </div>
1140
  </div>
1141
  """
1142
 
1143
+ sequencing_stage_html = f"""
1144
  <div style="border: 1px solid #e2e8f0; border-radius: 12px; padding: 18px; background: white; margin: 8px; text-align: center; flex: 1; min-width: 140px;
1145
+ border-left: 4px solid; border-image: {metrics['sequencing_stage'][2]}; border-image-slice: 1;">
1146
+ <div style="font-size: 28px; margin-bottom: 10px;">🔁</div>
1147
  <div>
1148
+ <h4 style="margin: 0 0 8px 0; font-size: 14px; color: #64748b; font-weight: 600;">Sequencing Stage</h4>
1149
+ <p style="font-size: 28px; font-weight: bold; background: {metrics['sequencing_stage'][2]}; -webkit-background-clip: text; -webkit-text-fill-color: transparent; margin: 8px 0;">{metrics['sequencing_stage'][0]}</p>
1150
+ <p style="font-size: 12px; color: #64748b; margin: 0;">{metrics['sequencing_stage'][1]}</p>
1151
  </div>
1152
  </div>
1153
  """
1154
 
1155
  logger.info(f"��� Updated performance metrics for {scenario_name} ({scenario_type} type)")
1156
+ return detection_time_html, recall_quality_html, confidence_score_html, sequencing_stage_html
1157
 
1158
  # -----------------------------
1159
  # Tab 1: Live Incident Demo - UPDATED WITH RESTORED FUNCTIONS
 
1402
  # Real-time Metrics Dashboard
1403
  metrics_header = gr.Markdown("## 📊 Performance Metrics")
1404
 
1405
+ # Metric Cards Grid - FIXED to match app.py expectations
1406
+ # app.py expects: detection_time, recall_quality, confidence_score, sequencing_stage
1407
  detection_time = gr.HTML()
1408
+ recall_quality = gr.HTML() # Changed from mttr
1409
+ confidence_score = gr.HTML() # Changed from auto_heal
1410
+ sequencing_stage = gr.HTML() # Changed from savings
1411
 
1412
  # Results Display Areas
1413
  oss_results_header = gr.Markdown("### 🆓 Policy Analysis Results")
 
1468
  observation_gate_placeholder, sequencing_panel, workflow_header, detection_process,
1469
  recall_process, decision_process, oss_section, enterprise_section, oss_btn, enterprise_btn,
1470
  approval_toggle, mcp_mode, timeline_viz,
1471
+ # Right column returns - FIXED to match app.py expectations
1472
+ detection_time, recall_quality, confidence_score, sequencing_stage, # Changed variable names
1473
+ oss_results_display, enterprise_results_display, approval_display, demo_btn,
1474
+ # Also return the info elements that app.py might need
1475
+ oss_info, enterprise_info, demo_info
1476
  )
1477
 
1478
  # -----------------------------