Update ui/components.py
Browse files- ui/components.py +229 -163
ui/components.py
CHANGED
|
@@ -1,180 +1,246 @@
|
|
| 1 |
"""
|
| 2 |
-
|
| 3 |
-
|
|
|
|
| 4 |
"""
|
| 5 |
-
from __future__ import annotations
|
| 6 |
|
| 7 |
-
import
|
| 8 |
-
from datetime import datetime
|
| 9 |
-
from typing import List, Dict, Any
|
| 10 |
-
import time
|
| 11 |
|
|
|
|
| 12 |
import plotly.graph_objects as go
|
| 13 |
-
import
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
self.action = action
|
| 41 |
-
self.component = component
|
| 42 |
-
self.confidence = confidence
|
| 43 |
-
self.status = status
|
| 44 |
-
self.rag_similarity_score = rag_similarity_score
|
| 45 |
-
self.deterministic_id = f"intent_{int(time.time())}"
|
| 46 |
-
self.created_at = time.time()
|
| 47 |
-
|
| 48 |
-
def get_execution_summary(self):
|
| 49 |
-
return {
|
| 50 |
-
"intent_id": self.deterministic_id,
|
| 51 |
-
"action": self.action,
|
| 52 |
-
"component": self.component,
|
| 53 |
-
"confidence": self.confidence,
|
| 54 |
-
"status": self.status.value if hasattr(self.status, "value") else self.status,
|
| 55 |
-
"rag_similarity_score": self.rag_similarity_score,
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
# -----------------------------
|
| 60 |
-
# UI Components (SAFE)
|
| 61 |
-
# -----------------------------
|
| 62 |
-
def create_arf_enhanced_timeline(
|
| 63 |
-
incident_data: Dict[str, Any],
|
| 64 |
-
healing_intents: List[Dict[str, Any]] | None = None,
|
| 65 |
-
):
|
| 66 |
-
if not _require_streamlit():
|
| 67 |
-
return
|
| 68 |
-
|
| 69 |
-
col1, col2 = st.columns([2, 1])
|
| 70 |
-
|
| 71 |
-
with col1:
|
| 72 |
-
st.markdown("### 📈 ARF-Enhanced Incident Timeline")
|
| 73 |
-
|
| 74 |
-
events = [
|
| 75 |
-
{"time": "-5m", "event": "📡 Alert Triggered", "phase": "detection", "color": "#FF6B6B"},
|
| 76 |
-
{"time": "-4m", "event": "🧠 ARF Analysis Started", "phase": "analysis", "color": "#4ECDC4"},
|
| 77 |
-
{"time": "-3.5m", "event": "🔍 RAG Similarity Search", "phase": "rag", "color": "#1E90FF"},
|
| 78 |
-
{"time": "-2.5m", "event": "🎯 Pattern Detection", "phase": "pattern", "color": "#9D4EDD"},
|
| 79 |
-
{"time": "-1.5m", "event": "💡 HealingIntent Generated", "phase": "intent", "color": "#FFD166"},
|
| 80 |
-
{"time": "-1m", "event": "⚡ MCP Execution", "phase": "execution", "color": "#06D6A0"},
|
| 81 |
-
{"time": "Now", "event": "✅ Resolution Complete", "phase": "resolution", "color": "#118AB2"},
|
| 82 |
-
]
|
| 83 |
-
|
| 84 |
-
fig = go.Figure()
|
| 85 |
-
|
| 86 |
-
fig.add_trace(
|
| 87 |
-
go.Scatter(
|
| 88 |
-
x=list(range(len(events))),
|
| 89 |
-
y=[0] * len(events),
|
| 90 |
-
mode="lines+markers",
|
| 91 |
-
marker=dict(size=16, color=[e["color"] for e in events]),
|
| 92 |
-
line=dict(width=2),
|
| 93 |
-
hovertext=[e["event"] for e in events],
|
| 94 |
-
hoverinfo="text",
|
| 95 |
-
)
|
| 96 |
-
)
|
| 97 |
-
|
| 98 |
-
fig.update_layout(
|
| 99 |
-
height=250,
|
| 100 |
-
showlegend=False,
|
| 101 |
-
xaxis=dict(visible=False),
|
| 102 |
-
yaxis=dict(visible=False),
|
| 103 |
-
margin=dict(l=20, r=20, t=20, b=20),
|
| 104 |
-
)
|
| 105 |
-
|
| 106 |
-
st.plotly_chart(fig, use_container_width=True)
|
| 107 |
-
|
| 108 |
-
with col2:
|
| 109 |
-
st.markdown("### 🎯 ARF Pattern Detection")
|
| 110 |
-
|
| 111 |
-
rag_score = (
|
| 112 |
-
healing_intents[0].get("rag_similarity_score", 0.85)
|
| 113 |
-
if healing_intents
|
| 114 |
-
else 0.85
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
fig = go.Figure(
|
| 118 |
-
go.Indicator(
|
| 119 |
-
mode="gauge+number",
|
| 120 |
-
value=rag_score * 100,
|
| 121 |
-
gauge={"axis": {"range": [0, 100]}},
|
| 122 |
-
title={"text": "RAG Similarity"},
|
| 123 |
-
)
|
| 124 |
-
)
|
| 125 |
-
|
| 126 |
-
fig.update_layout(height=200)
|
| 127 |
-
st.plotly_chart(fig, use_container_width=True)
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
def create_healing_intent_visualizer(healing_intent: Dict[str, Any]):
|
| 131 |
-
if not _require_streamlit():
|
| 132 |
-
return
|
| 133 |
-
|
| 134 |
-
st.markdown("### 💡 ARF HealingIntent")
|
| 135 |
-
|
| 136 |
-
confidence = healing_intent.get("confidence", 0.85)
|
| 137 |
-
|
| 138 |
-
fig = go.Figure(
|
| 139 |
-
go.Indicator(
|
| 140 |
-
mode="gauge+number",
|
| 141 |
-
value=confidence * 100,
|
| 142 |
-
gauge={"axis": {"range": [0, 100]}},
|
| 143 |
-
title={"text": "Confidence"},
|
| 144 |
-
)
|
| 145 |
-
)
|
| 146 |
|
| 147 |
-
fig.update_layout(height=180)
|
| 148 |
-
st.plotly_chart(fig, use_container_width=True)
|
| 149 |
-
|
| 150 |
-
st.json(healing_intent)
|
| 151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
-
def create_rag_similarity_panel(query: str, similar_incidents: List[Dict[str, Any]]):
|
| 154 |
-
if not _require_streamlit():
|
| 155 |
-
return
|
| 156 |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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
"""
|
| 2 |
+
ARF UI Components
|
| 3 |
+
Gradio-first, Hugging Face Spaces safe
|
| 4 |
+
Compatible with app.py v3.8.0
|
| 5 |
"""
|
|
|
|
| 6 |
|
| 7 |
+
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
import gradio as gr
|
| 10 |
import plotly.graph_objects as go
|
| 11 |
+
from typing import Dict, Any, List
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
# ============================================================
|
| 15 |
+
# HEADER / FOOTER
|
| 16 |
+
# ============================================================
|
| 17 |
+
|
| 18 |
+
def create_header(version: str, enterprise: bool = False):
|
| 19 |
+
badge = "ENTERPRISE EDITION" if enterprise else "OSS EDITION"
|
| 20 |
+
return gr.HTML(
|
| 21 |
+
f"""
|
| 22 |
+
<div style="padding:20px;border-bottom:1px solid #eee">
|
| 23 |
+
<h1>🚀 Agentic Reliability Framework</h1>
|
| 24 |
+
<p><b>Version:</b> {version} · <b>{badge}</b></p>
|
| 25 |
+
</div>
|
| 26 |
+
"""
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def create_footer():
|
| 31 |
+
return gr.HTML(
|
| 32 |
+
"""
|
| 33 |
+
<div style="padding:20px;border-top:1px solid #eee;text-align:center;color:#666">
|
| 34 |
+
ARF © 2025 · Self-Healing Agentic Systems
|
| 35 |
+
</div>
|
| 36 |
+
"""
|
| 37 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
def create_status_bar():
|
| 41 |
+
return gr.HTML(
|
| 42 |
+
"""
|
| 43 |
+
<div style="padding:10px;background:#f5f7fa;border-radius:8px">
|
| 44 |
+
✅ System Online · 🧠 Agentic Core Active · 📦 OSS Mode
|
| 45 |
+
</div>
|
| 46 |
+
"""
|
| 47 |
+
)
|
| 48 |
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
# ============================================================
|
| 51 |
+
# TAB 1 — INCIDENT DEMO
|
| 52 |
+
# ============================================================
|
| 53 |
|
| 54 |
+
def create_tab1_incident_demo(scenarios: Dict[str, Any], default: str):
|
| 55 |
+
scenario_dropdown = gr.Dropdown(
|
| 56 |
+
choices=list(scenarios.keys()),
|
| 57 |
+
value=default,
|
| 58 |
+
label="Incident Scenario"
|
| 59 |
+
)
|
| 60 |
|
| 61 |
+
scenario_description = gr.Markdown("Select a scenario to begin analysis.")
|
| 62 |
+
metrics_display = gr.JSON(label="Live Metrics")
|
| 63 |
+
impact_display = gr.Markdown("### Estimated Business Impact")
|
| 64 |
+
timeline_output = gr.Markdown("Timeline will render here")
|
| 65 |
+
|
| 66 |
+
oss_btn = gr.Button("Run OSS Analysis")
|
| 67 |
+
enterprise_btn = gr.Button("Execute Enterprise Healing", variant="primary")
|
| 68 |
+
approval_toggle = gr.Checkbox(label="Require Human Approval", value=True)
|
| 69 |
+
|
| 70 |
+
demo_btn = gr.Button("Run Demo")
|
| 71 |
+
approval_display = gr.HTML()
|
| 72 |
+
oss_results_display = gr.JSON(label="OSS Results")
|
| 73 |
+
enterprise_results_display = gr.JSON(label="Enterprise Results")
|
| 74 |
+
|
| 75 |
+
return (
|
| 76 |
+
scenario_dropdown,
|
| 77 |
+
scenario_description,
|
| 78 |
+
metrics_display,
|
| 79 |
+
impact_display,
|
| 80 |
+
timeline_output,
|
| 81 |
+
oss_btn,
|
| 82 |
+
enterprise_btn,
|
| 83 |
+
approval_toggle,
|
| 84 |
+
demo_btn,
|
| 85 |
+
approval_display,
|
| 86 |
+
oss_results_display,
|
| 87 |
+
enterprise_results_display,
|
| 88 |
+
)
|
| 89 |
|
| 90 |
|
| 91 |
+
# ============================================================
|
| 92 |
+
# TAB 2 — ROI / BUSINESS IMPACT
|
| 93 |
+
# ============================================================
|
| 94 |
|
| 95 |
+
def create_tab2_business_roi(scenarios: Dict[str, Any]):
|
| 96 |
+
dashboard_output = gr.Plot(label="Executive ROI Dashboard")
|
| 97 |
|
| 98 |
+
roi_scenario_dropdown = gr.Dropdown(
|
| 99 |
+
choices=list(scenarios.keys()),
|
| 100 |
+
label="Scenario"
|
| 101 |
+
)
|
| 102 |
|
| 103 |
+
monthly_slider = gr.Slider(
|
| 104 |
+
1, 100, value=15, step=1, label="Monthly Incidents"
|
| 105 |
+
)
|
| 106 |
|
| 107 |
+
team_slider = gr.Slider(
|
| 108 |
+
1, 50, value=5, step=1, label="On-call Team Size"
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
calculate_btn = gr.Button("Calculate ROI", variant="primary")
|
| 112 |
+
roi_output = gr.JSON(label="ROI Breakdown")
|
| 113 |
+
roi_chart = gr.Plot(label="ROI Multiplier")
|
| 114 |
+
|
| 115 |
+
return (
|
| 116 |
+
dashboard_output,
|
| 117 |
+
roi_scenario_dropdown,
|
| 118 |
+
monthly_slider,
|
| 119 |
+
team_slider,
|
| 120 |
+
calculate_btn,
|
| 121 |
+
roi_output,
|
| 122 |
+
roi_chart,
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
# ============================================================
|
| 127 |
+
# TAB 3 — ENTERPRISE FEATURES
|
| 128 |
+
# ============================================================
|
| 129 |
+
|
| 130 |
+
def create_tab3_enterprise_features():
|
| 131 |
+
license_display = gr.JSON(label="License Status")
|
| 132 |
+
|
| 133 |
+
validate_btn = gr.Button("Validate License")
|
| 134 |
+
trial_btn = gr.Button("Start Trial")
|
| 135 |
+
upgrade_btn = gr.Button("Upgrade")
|
| 136 |
+
|
| 137 |
+
mcp_mode = gr.Radio(
|
| 138 |
+
["advisory", "approval", "autonomous"],
|
| 139 |
+
value="advisory",
|
| 140 |
+
label="MCP Execution Mode"
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
mcp_mode_info = gr.JSON(label="Mode Details")
|
| 144 |
+
|
| 145 |
+
features_table = gr.Dataframe(
|
| 146 |
+
headers=["Feature", "Available"],
|
| 147 |
+
value=[
|
| 148 |
+
["Autonomous Healing", "Enterprise"],
|
| 149 |
+
["Audit Trail", "Enterprise"],
|
| 150 |
+
["Compliance", "Enterprise"],
|
| 151 |
+
],
|
| 152 |
+
interactive=False
|
| 153 |
+
)
|
| 154 |
+
|
| 155 |
+
integrations_table = gr.Dataframe(
|
| 156 |
+
headers=["Integration", "Status"],
|
| 157 |
+
value=[
|
| 158 |
+
["Kubernetes", "Ready"],
|
| 159 |
+
["AWS", "Ready"],
|
| 160 |
+
["GCP", "Ready"],
|
| 161 |
+
],
|
| 162 |
+
interactive=False
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
return (
|
| 166 |
+
license_display,
|
| 167 |
+
validate_btn,
|
| 168 |
+
trial_btn,
|
| 169 |
+
upgrade_btn,
|
| 170 |
+
mcp_mode,
|
| 171 |
+
mcp_mode_info,
|
| 172 |
+
features_table,
|
| 173 |
+
integrations_table,
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
# ============================================================
|
| 178 |
+
# TAB 4 — AUDIT TRAIL
|
| 179 |
+
# ============================================================
|
| 180 |
+
|
| 181 |
+
def create_tab4_audit_trail():
|
| 182 |
+
refresh_btn = gr.Button("Refresh")
|
| 183 |
+
clear_btn = gr.Button("Clear")
|
| 184 |
+
export_btn = gr.Button("Export")
|
| 185 |
+
|
| 186 |
+
execution_table = gr.Dataframe(
|
| 187 |
+
headers=["Time", "Scenario", "Mode", "Status", "Savings", "Details"],
|
| 188 |
+
interactive=False
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
incident_table = gr.Dataframe(
|
| 192 |
+
headers=["Time", "Component", "Scenario", "Severity", "Status"],
|
| 193 |
+
interactive=False
|
| 194 |
+
)
|
| 195 |
+
|
| 196 |
+
export_text = gr.Textbox(
|
| 197 |
+
label="Exported Audit JSON",
|
| 198 |
+
lines=15
|
| 199 |
+
)
|
| 200 |
+
|
| 201 |
+
return (
|
| 202 |
+
refresh_btn,
|
| 203 |
+
clear_btn,
|
| 204 |
+
export_btn,
|
| 205 |
+
execution_table,
|
| 206 |
+
incident_table,
|
| 207 |
+
export_text,
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
# ============================================================
|
| 212 |
+
# TAB 5 — LEARNING ENGINE
|
| 213 |
+
# ============================================================
|
| 214 |
+
|
| 215 |
+
def create_tab5_learning_engine():
|
| 216 |
+
learning_graph = gr.Plot(label="Learning Graph")
|
| 217 |
+
|
| 218 |
+
graph_type = gr.Dropdown(
|
| 219 |
+
["patterns", "performance", "confidence"],
|
| 220 |
+
value="patterns",
|
| 221 |
+
label="Graph Type"
|
| 222 |
+
)
|
| 223 |
+
|
| 224 |
+
show_labels = gr.Checkbox(value=True, label="Show Labels")
|
| 225 |
+
|
| 226 |
+
search_query = gr.Textbox(label="Search Incidents")
|
| 227 |
+
search_btn = gr.Button("Search")
|
| 228 |
+
clear_btn_search = gr.Button("Clear")
|
| 229 |
+
|
| 230 |
+
search_results = gr.JSON(label="Search Results")
|
| 231 |
+
stats_display = gr.JSON(label="Learning Stats")
|
| 232 |
+
patterns_display = gr.JSON(label="Detected Patterns")
|
| 233 |
+
performance_display = gr.JSON(label="Performance Metrics")
|
| 234 |
+
|
| 235 |
+
return (
|
| 236 |
+
learning_graph,
|
| 237 |
+
graph_type,
|
| 238 |
+
show_labels,
|
| 239 |
+
search_query,
|
| 240 |
+
search_btn,
|
| 241 |
+
clear_btn_search,
|
| 242 |
+
search_results,
|
| 243 |
+
stats_display,
|
| 244 |
+
patterns_display,
|
| 245 |
+
performance_display,
|
| 246 |
+
)
|