Update ui/components.py
Browse files- ui/components.py +127 -0
ui/components.py
CHANGED
|
@@ -4,6 +4,7 @@ Ensures full compatibility with app.py
|
|
| 4 |
Updated with proper imports and error handling
|
| 5 |
NOW WITH REAL ARF INSTALLATION DETECTION
|
| 6 |
UPDATED: Added realism panel integration for Tab 1
|
|
|
|
| 7 |
"""
|
| 8 |
|
| 9 |
import gradio as gr
|
|
@@ -64,6 +65,132 @@ def create_status_bar() -> gr.HTML:
|
|
| 64 |
</div>
|
| 65 |
""")
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
# -----------------------------
|
| 68 |
# Tab 1: Live Incident Demo - UPDATED WITH REALISM PANEL
|
| 69 |
# -----------------------------
|
|
|
|
| 4 |
Updated with proper imports and error handling
|
| 5 |
NOW WITH REAL ARF INSTALLATION DETECTION
|
| 6 |
UPDATED: Added realism panel integration for Tab 1
|
| 7 |
+
UPDATED: Added dynamic performance metrics function for Phase 2
|
| 8 |
"""
|
| 9 |
|
| 10 |
import gradio as gr
|
|
|
|
| 65 |
</div>
|
| 66 |
""")
|
| 67 |
|
| 68 |
+
# -----------------------------
|
| 69 |
+
# Performance Metrics Function - NEW FOR PHASE 2
|
| 70 |
+
# -----------------------------
|
| 71 |
+
def update_performance_metrics(scenario_name: str, scenarios=INCIDENT_SCENARIOS) -> tuple:
|
| 72 |
+
"""
|
| 73 |
+
Update performance metrics based on scenario
|
| 74 |
+
Returns: (detection_time_html, mttr_html, auto_heal_html, savings_html)
|
| 75 |
+
|
| 76 |
+
Different metrics based on scenario type:
|
| 77 |
+
- Cache scenarios: Fast detection, moderate recovery
|
| 78 |
+
- Database scenarios: Medium detection, slower recovery
|
| 79 |
+
- Kubernetes scenarios: Slower detection, fast recovery
|
| 80 |
+
- Network scenarios: Very fast detection, very fast recovery
|
| 81 |
+
- Storage scenarios: Fast detection, slow recovery
|
| 82 |
+
"""
|
| 83 |
+
|
| 84 |
+
# Scenario-specific metrics mapping
|
| 85 |
+
metrics_config = {
|
| 86 |
+
# Cache scenarios
|
| 87 |
+
"Cache": {
|
| 88 |
+
"detection_time": ("45s", "β89%", "#3b82f6"),
|
| 89 |
+
"mttr": ("12m", "β73%", "#10b981"),
|
| 90 |
+
"auto_heal": ("81.7%", "β5.4Γ", "#8b5cf6"),
|
| 91 |
+
"savings_multiplier": 0.85
|
| 92 |
+
},
|
| 93 |
+
# Database scenarios
|
| 94 |
+
"Database": {
|
| 95 |
+
"detection_time": ("38s", "β91%", "#3b82f6"),
|
| 96 |
+
"mttr": ("18m", "β68%", "#10b981"),
|
| 97 |
+
"auto_heal": ("74.3%", "β4.8Γ", "#8b5cf6"),
|
| 98 |
+
"savings_multiplier": 0.82
|
| 99 |
+
},
|
| 100 |
+
# Kubernetes scenarios
|
| 101 |
+
"Kubernetes": {
|
| 102 |
+
"detection_time": ("52s", "β87%", "#3b82f6"),
|
| 103 |
+
"mttr": ("15m", "β71%", "#10b981"),
|
| 104 |
+
"auto_heal": ("79.2%", "β5.1Γ", "#8b5cf6"),
|
| 105 |
+
"savings_multiplier": 0.83
|
| 106 |
+
},
|
| 107 |
+
# Network scenarios
|
| 108 |
+
"Network": {
|
| 109 |
+
"detection_time": ("28s", "β93%", "#3b82f6"),
|
| 110 |
+
"mttr": ("8m", "β82%", "#10b981"),
|
| 111 |
+
"auto_heal": ("88.5%", "β6.2Γ", "#8b5cf6"),
|
| 112 |
+
"savings_multiplier": 0.88
|
| 113 |
+
},
|
| 114 |
+
# Storage scenarios
|
| 115 |
+
"Storage": {
|
| 116 |
+
"detection_time": ("35s", "β92%", "#3b82f6"),
|
| 117 |
+
"mttr": ("22m", "β65%", "#10b981"),
|
| 118 |
+
"auto_heal": ("71.8%", "β4.6Γ", "#8b5cf6"),
|
| 119 |
+
"savings_multiplier": 0.80
|
| 120 |
+
},
|
| 121 |
+
# Default (fallback)
|
| 122 |
+
"Default": {
|
| 123 |
+
"detection_time": ("42s", "β90%", "#3b82f6"),
|
| 124 |
+
"mttr": ("14m", "β70%", "#10b981"),
|
| 125 |
+
"auto_heal": ("78.9%", "β5.0Γ", "#8b5cf6"),
|
| 126 |
+
"savings_multiplier": 0.85
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
# Determine scenario type
|
| 131 |
+
scenario_type = "Default"
|
| 132 |
+
for key in ["Cache", "Database", "Kubernetes", "Network", "Storage"]:
|
| 133 |
+
if key.lower() in scenario_name.lower():
|
| 134 |
+
scenario_type = key
|
| 135 |
+
break
|
| 136 |
+
|
| 137 |
+
# Get metrics for scenario type
|
| 138 |
+
metrics = metrics_config.get(scenario_type, metrics_config["Default"])
|
| 139 |
+
|
| 140 |
+
# Get scenario data for savings calculation
|
| 141 |
+
scenario_data = scenarios.get(scenario_name, {})
|
| 142 |
+
business_impact = scenario_data.get("business_impact", {})
|
| 143 |
+
revenue_loss = business_impact.get('revenue_loss_per_hour', 8500)
|
| 144 |
+
savings_amount = int(revenue_loss * metrics["savings_multiplier"] / 1000)
|
| 145 |
+
|
| 146 |
+
# Create HTML for each metric card
|
| 147 |
+
detection_time_html = f"""
|
| 148 |
+
<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 {metrics['detection_time'][2]};">
|
| 149 |
+
<div style="font-size: 28px; margin-bottom: 10px;">β±οΈ</div>
|
| 150 |
+
<div>
|
| 151 |
+
<h4 style="margin: 0 0 8px 0; font-size: 14px; color: #64748b; font-weight: 600;">Detection Time</h4>
|
| 152 |
+
<p style="font-size: 28px; font-weight: bold; color: {metrics['detection_time'][2]}; margin: 8px 0;">{metrics['detection_time'][0]}</p>
|
| 153 |
+
<p style="font-size: 12px; color: #64748b; margin: 0;">{metrics['detection_time'][1]} faster than average</p>
|
| 154 |
+
</div>
|
| 155 |
+
</div>
|
| 156 |
+
"""
|
| 157 |
+
|
| 158 |
+
mttr_html = f"""
|
| 159 |
+
<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 {metrics['mttr'][2]};">
|
| 160 |
+
<div style="font-size: 28px; margin-bottom: 10px;">β‘</div>
|
| 161 |
+
<div>
|
| 162 |
+
<h4 style="margin: 0 0 8px 0; font-size: 14px; color: #64748b; font-weight: 600;">Mean Time to Resolve</h4>
|
| 163 |
+
<p style="font-size: 28px; font-weight: bold; color: {metrics['mttr'][2]}; margin: 8px 0;">{metrics['mttr'][0]}</p>
|
| 164 |
+
<p style="font-size: 12px; color: #64748b; margin: 0;">{metrics['mttr'][1]} faster than manual</p>
|
| 165 |
+
</div>
|
| 166 |
+
</div>
|
| 167 |
+
"""
|
| 168 |
+
|
| 169 |
+
auto_heal_html = f"""
|
| 170 |
+
<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 {metrics['auto_heal'][2]};">
|
| 171 |
+
<div style="font-size: 28px; margin-bottom: 10px;">π€</div>
|
| 172 |
+
<div>
|
| 173 |
+
<h4 style="margin: 0 0 8px 0; font-size: 14px; color: #64748b; font-weight: 600;">Auto-Heal Rate</h4>
|
| 174 |
+
<p style="font-size: 28px; font-weight: bold; color: {metrics['auto_heal'][2]}; margin: 8px 0;">{metrics['auto_heal'][0]}</p>
|
| 175 |
+
<p style="font-size: 12px; color: #64748b; margin: 0;">{metrics['auto_heal'][1]} industry average</p>
|
| 176 |
+
</div>
|
| 177 |
+
</div>
|
| 178 |
+
"""
|
| 179 |
+
|
| 180 |
+
savings_html = f"""
|
| 181 |
+
<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;">
|
| 182 |
+
<div style="font-size: 28px; margin-bottom: 10px;">π°</div>
|
| 183 |
+
<div>
|
| 184 |
+
<h4 style="margin: 0 0 8px 0; font-size: 14px; color: #64748b; font-weight: 600;">Cost Saved</h4>
|
| 185 |
+
<p style="font-size: 28px; font-weight: bold; color: #f59e0b; margin: 8px 0;">${savings_amount:.1f}K</p>
|
| 186 |
+
<p style="font-size: 12px; color: #64748b; margin: 0;">Per incident avoided</p>
|
| 187 |
+
</div>
|
| 188 |
+
</div>
|
| 189 |
+
"""
|
| 190 |
+
|
| 191 |
+
logger.info(f"β
Updated performance metrics for {scenario_name} ({scenario_type} type)")
|
| 192 |
+
return detection_time_html, mttr_html, auto_heal_html, savings_html
|
| 193 |
+
|
| 194 |
# -----------------------------
|
| 195 |
# Tab 1: Live Incident Demo - UPDATED WITH REALISM PANEL
|
| 196 |
# -----------------------------
|