File size: 29,024 Bytes
bbe2211
a400436
dddcb49
bbe2211
 
 
cc6b2b9
 
bbe2211
cc6b2b9
a400436
b37ab2f
cc6b2b9
bbe2211
a400436
cc6b2b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bbe2211
cc6b2b9
bbe2211
cc6b2b9
 
b37ab2f
cc6b2b9
 
 
 
 
 
 
 
 
 
 
 
 
 
bbe2211
cc6b2b9
 
b37ab2f
bbe2211
cc6b2b9
 
 
 
 
dddcb49
cc6b2b9
 
 
 
 
 
 
 
 
 
 
 
dddcb49
cc6b2b9
 
 
 
 
 
 
 
 
 
 
 
 
b37ab2f
cc6b2b9
 
 
 
 
 
 
b37ab2f
cc6b2b9
 
 
 
 
 
 
b37ab2f
cc6b2b9
 
 
 
 
b37ab2f
cc6b2b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b37ab2f
 
 
 
 
 
 
 
bbe2211
dddcb49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cc6b2b9
 
b37ab2f
cc6b2b9
 
a400436
b37ab2f
cc6b2b9
 
b37ab2f
cc6b2b9
 
 
 
a400436
b37ab2f
a400436
 
b37ab2f
cc6b2b9
 
b37ab2f
 
 
 
cc6b2b9
 
b37ab2f
cc6b2b9
 
 
 
 
b37ab2f
cc6b2b9
b37ab2f
cc6b2b9
 
 
bbe2211
cc6b2b9
 
b37ab2f
 
cc6b2b9
b37ab2f
 
cc6b2b9
b37ab2f
 
cc6b2b9
 
b37ab2f
a400436
cc6b2b9
 
 
b37ab2f
 
 
 
 
 
a400436
 
 
b37ab2f
 
 
cc6b2b9
 
b37ab2f
 
 
cc6b2b9
b37ab2f
 
 
 
 
 
 
 
cc6b2b9
 
b37ab2f
 
 
 
 
 
 
 
cc6b2b9
 
 
b37ab2f
cc6b2b9
b37ab2f
 
 
 
 
 
 
 
 
a400436
 
 
 
b37ab2f
cc6b2b9
 
 
 
b37ab2f
cc6b2b9
b37ab2f
a400436
b37ab2f
a400436
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b37ab2f
 
cc6b2b9
 
 
b37ab2f
 
cc6b2b9
 
b37ab2f
a400436
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cc6b2b9
 
 
b37ab2f
cc6b2b9
 
b37ab2f
 
 
cc6b2b9
b37ab2f
 
a400436
cc6b2b9
 
 
 
 
 
b37ab2f
cc6b2b9
b37ab2f
 
a400436
cc6b2b9
 
 
 
b37ab2f
 
 
 
 
cc6b2b9
 
b37ab2f
 
cc6b2b9
 
 
a400436
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cc6b2b9
 
 
 
 
a400436
cc6b2b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a400436
cc6b2b9
 
 
 
 
 
 
 
 
 
a400436
 
 
 
 
 
cc6b2b9
 
 
 
 
 
 
a400436
 
 
 
 
 
 
 
cc6b2b9
 
 
 
 
 
 
a400436
 
 
 
 
 
cc6b2b9
 
 
 
 
 
 
 
a400436
2cd95f6
a400436
cc6b2b9
 
2cd95f6
 
 
 
 
 
 
 
 
 
 
cc6b2b9
bbe2211
cc6b2b9
1
2
3
4
5
6
7
8
9
10
11
12
13
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
"""
UI components for the 5-tab demo - COMPLETE FIXED VERSION
ALL TABS WORKING - Tab 1 now updates dynamically
"""

import gradio as gr
from typing import Dict, List, Any, Optional, Tuple
import plotly.graph_objects as go


def create_header(oss_version: str, oss_available: bool) -> gr.HTML:
    """Create the demo header - FIXED VERSION"""
    status_badge = "โœ… Connected" if oss_available else "โš ๏ธ Mock Mode"
    
    return gr.HTML(f"""
    <div style="text-align: center; padding: 30px 20px 20px 20px; background: linear-gradient(135deg, #f8fafc 0%, #ffffff 100%); border-radius: 0 0 20px 20px; margin-bottom: 30px; border-bottom: 3px solid #4ECDC4;">
        <h1 style="margin-bottom: 10px;">๐Ÿš€ Agentic Reliability Framework</h1>
        <h2 style="color: #4a5568; font-weight: 600; margin-bottom: 20px;">Investor Demo v3.8.0</h2>
        
        <div style="display: flex; justify-content: center; gap: 20px; flex-wrap: wrap; margin-bottom: 20px;">
            <div style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 8px 16px; border-radius: 20px; font-weight: 700; font-size: 0.85rem;">
                ๐Ÿข Enterprise Edition
            </div>
            <div style="background: linear-gradient(135deg, #4299e1 0%, #38b2ac 100%); color: white; padding: 8px 16px; border-radius: 20px; font-weight: 700; font-size: 0.85rem;">
                ๐Ÿ†“ OSS v{oss_version}
            </div>
            <div style="background: #e8f5e8; color: #2d3748; padding: 8px 16px; border-radius: 20px; font-weight: 600; font-size: 0.85rem;">
                ๐Ÿ“ˆ 5.2ร— ROI
            </div>
            <div style="background: #fff3cd; color: #856404; padding: 8px 16px; border-radius: 20px; font-weight: 600; font-size: 0.85rem;">
                โšก 85% MTTR Reduction
            </div>
        </div>
        
        <div style="color: #718096; font-size: 16px; max-width: 800px; margin: 0 auto; line-height: 1.6;">
            From <span style="font-weight: 700; color: #4299e1;">OSS Advisory</span> 
            to <span style="font-weight: 700; color: #764ba2;">Enterprise Autonomous Healing</span>.
        </div>
        
        <div style="margin-top: 15px; font-size: 0.9rem; color: #4ECDC4; font-weight: 600;">
            {status_badge}
        </div>
    </div>
    """)


def create_status_bar() -> gr.HTML:
    """Create system status bar - FIXED VERSION"""
    return gr.HTML("""
    <div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin-bottom: 25px;">
        <div style="background: white; padding: 20px; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); border-left: 4px solid #4ECDC4;">
            <div style="font-size: 0.9rem; color: #718096; margin-bottom: 5px;">System Status</div>
            <div style="display: flex; align-items: center; gap: 8px;">
                <div style="width: 10px; height: 10px; background: #4ECDC4; border-radius: 50%;"></div>
                <div style="font-weight: 700; color: #2d3748;">Operational</div>
            </div>
        </div>
        
        <div style="background: white; padding: 20px; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); border-left: 4px solid #FFA726;">
            <div style="font-size: 0.9rem; color: #718096; margin-bottom: 5px;">Performance</div>
            <div style="font-weight: 700; color: #2d3748; font-size: 1.1rem;">8.2 min avg resolution</div>
        </div>
        
        <div style="background: white; padding: 20px; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); border-left: 4px solid #42A5F5;">
            <div style="font-size: 0.9rem; color: #718096; margin-bottom: 5px;">Learning Engine</div>
            <div style="font-weight: 700; color: #2d3748; font-size: 1.1rem;">6 patterns detected</div>
        </div>
    </div>
    """)


def create_tab1_incident_demo(scenarios: Dict, default_scenario: str = "Cache Miss Storm") -> Tuple:
    """Create Tab 1: Live Incident Demo - COMPLETE FIXED VERSION WITH DYNAMIC UPDATES"""
    with gr.Row():
        # Left Panel
        with gr.Column(scale=1):
            gr.Markdown("### ๐ŸŽฌ Select Incident Scenario")
            
            scenario_dropdown = gr.Dropdown(
                choices=list(scenarios.keys()),
                value=default_scenario,
                label="Choose an incident to analyze:",
                interactive=True
            )
            
            # Initialize with default scenario data
            scenario_description = gr.Markdown(
                value=scenarios[default_scenario]["description"]
            )
            
            gr.Markdown("### ๐Ÿ“Š Current Metrics")
            metrics_display = gr.JSON(
                value=scenarios[default_scenario].get("metrics", {}),
                label="",
                show_label=False
            )
            
            gr.Markdown("### ๐Ÿ’ฐ Business Impact")
            impact_display = gr.JSON(
                value=scenarios[default_scenario].get("business_impact", {}),
                label="",
                show_label=False
            )
        
        # Right Panel
        with gr.Column(scale=2):
            gr.Markdown("### ๐Ÿ“ˆ Incident Timeline")
            timeline_output = gr.Plot(label="", show_label=False)
            
            gr.Markdown("### โšก Take Action")
            with gr.Row():
                oss_btn = gr.Button(
                    "๐Ÿ†“ Run OSS Analysis",
                    variant="secondary",
                    size="lg",
                    elem_id="oss_btn"
                )
                enterprise_btn = gr.Button(
                    "๐Ÿš€ Execute Enterprise Healing",
                    variant="primary",
                    size="lg",
                    elem_id="enterprise_btn"
                )
            
            with gr.Row():
                approval_toggle = gr.Checkbox(
                    label="๐Ÿ” Require Manual Approval",
                    value=True,
                    interactive=True
                )
                demo_btn = gr.Button(
                    "โšก Quick Demo",
                    variant="secondary",
                    size="sm"
                )
            
            approval_display = gr.HTML(
                value="<div style='padding: 15px; background: #f8f9fa; border-radius: 8px; color: #6c757d;'>"
                      "Approval workflow will appear here after execution"
                      "</div>"
            )
            
            with gr.Row():
                with gr.Column():
                    gr.Markdown("### ๐Ÿ“‹ OSS Results")
                    oss_results_display = gr.JSON(label="", value={})
                
                with gr.Column():
                    gr.Markdown("### ๐ŸŽฏ Enterprise Results")
                    enterprise_results_display = gr.JSON(label="", value={})
    
    # Define function to update scenario details when dropdown changes
    def update_scenario_details(scenario_name):
        """Update all scenario details when dropdown changes"""
        # Get the selected scenario, fallback to default if not found
        scenario = scenarios.get(scenario_name, scenarios[default_scenario])
        
        # Update the timeline visualization based on scenario
        timeline_fig = create_scenario_timeline(scenario_name)
        
        return (
            scenario.get("description", "No description available"),
            scenario.get("metrics", {}),
            scenario.get("business_impact", {}),
            timeline_fig
        )
    
    # Helper function to create timeline visualization
    def create_scenario_timeline(scenario_name):
        """Create a timeline visualization for the selected scenario"""
        fig = go.Figure()
        
        # Different timeline events for different scenarios
        scenario_timelines = {
            "Cache Miss Storm": [
                {"time": "T-5m", "event": "๐Ÿ“‰ Cache hit rate drops below 20%", "type": "problem"},
                {"time": "T-4m", "event": "โš ๏ธ Database load exceeds 90%", "type": "alert"},
                {"time": "T-3m", "event": "๐Ÿค– ARF detects cache pattern", "type": "detection"},
                {"time": "T-2m", "event": "๐Ÿง  Cache analysis complete", "type": "analysis"},
                {"time": "T-1m", "event": "โšก Redis cluster scaled", "type": "action"},
                {"time": "T-0m", "event": "โœ… Cache performance restored", "type": "recovery"}
            ],
            "Database Connection Pool Exhaustion": [
                {"time": "T-5m", "event": "๐Ÿ“‰ Connection pool reaches 95%", "type": "problem"},
                {"time": "T-4m", "event": "โš ๏ธ API latency spikes to 2s+", "type": "alert"},
                {"time": "T-3m", "event": "๐Ÿค– ARF detects connection pattern", "type": "detection"},
                {"time": "T-2m", "event": "๐Ÿง  Pool analysis complete", "type": "analysis"},
                {"time": "T-1m", "event": "โšก Connection pool increased", "type": "action"},
                {"time": "T-0m", "event": "โœ… Database connections stable", "type": "recovery"}
            ],
            "Kubernetes Memory Leak": [
                {"time": "T-5m", "event": "๐Ÿ“‰ Memory usage hits 95%", "type": "problem"},
                {"time": "T-4m", "event": "โš ๏ธ Pod restarts every 5 minutes", "type": "alert"},
                {"time": "T-3m", "event": "๐Ÿค– ARF detects memory pattern", "type": "detection"},
                {"time": "T-2m", "event": "๐Ÿง  Heap analysis complete", "type": "analysis"},
                {"time": "T-1m", "event": "โšก Memory limits adjusted", "type": "action"},
                {"time": "T-0m", "event": "โœ… JVM memory stabilized", "type": "recovery"}
            ],
            "API Rate Limit Storm": [
                {"time": "T-5m", "event": "๐Ÿ“‰ 429 errors exceed 40%", "type": "problem"},
                {"time": "T-4m", "event": "โš ๏ธ Partner API calls failing", "type": "alert"},
                {"time": "T-3m", "event": "๐Ÿค– ARF detects rate limit pattern", "type": "detection"},
                {"time": "T-2m", "event": "๐Ÿง  Backoff strategy analyzed", "type": "analysis"},
                {"time": "T-1m", "event": "โšก Circuit breaker implemented", "type": "action"},
                {"time": "T-0m", "event": "โœ… API calls normalized", "type": "recovery"}
            ],
            "Network Partition": [
                {"time": "T-5m", "event": "๐Ÿ“‰ Network partition detected", "type": "problem"},
                {"time": "T-4m", "event": "โš ๏ธ Database split-brain risk", "type": "alert"},
                {"time": "T-3m", "event": "๐Ÿค– ARF detects partition pattern", "type": "detection"},
                {"time": "T-2m", "event": "๐Ÿง  Consensus analysis complete", "type": "analysis"},
                {"time": "T-1m", "event": "โšก Quorum restored", "type": "action"},
                {"time": "T-0m", "event": "โœ… Cluster consistency restored", "type": "recovery"}
            ],
            "Storage I/O Saturation": [
                {"time": "T-5m", "event": "๐Ÿ“‰ I/O utilization hits 98%", "type": "problem"},
                {"time": "T-4m", "event": "โš ๏ธ Application timeouts increasing", "type": "alert"},
                {"time": "T-3m", "event": "๐Ÿค– ARF detects storage pattern", "type": "detection"},
                {"time": "T-2m", "event": "๐Ÿง  I/O analysis complete", "type": "analysis"},
                {"time": "T-1m", "event": "โšก Storage optimized", "type": "action"},
                {"time": "T-0m", "event": "โœ… I/O performance restored", "type": "recovery"}
            ]
        }
        
        # Get timeline for this scenario, default to Cache Miss Storm
        events = scenario_timelines.get(scenario_name, scenario_timelines["Cache Miss Storm"])
        
        # Color mapping
        color_map = {
            "problem": "#FF6B6B",
            "alert": "#FFE66D",
            "detection": "#45B7D1",
            "analysis": "#9B59B6",
            "action": "#4ECDC4",
            "recovery": "#2ECC71"
        }
        
        # Add events
        for event in events:
            fig.add_trace(go.Scatter(
                x=[event["time"]],
                y=[1],
                mode='markers+text',
                marker=dict(
                    size=20,
                    color=color_map[event["type"]],
                    symbol='circle',
                    line=dict(width=2, color='white')
                ),
                text=[event["event"]],
                textposition="top center",
                hoverinfo='text',
                name=event["type"].capitalize(),
                hovertemplate="<b>%{text}</b><br>Click for details<extra></extra>"
            ))
        
        # Add connecting line
        fig.add_trace(go.Scatter(
            x=[e["time"] for e in events],
            y=[1] * len(events),
            mode='lines',
            line=dict(color='gray', width=2, dash='dash'),
            hoverinfo='none',
            showlegend=False
        ))
        
        fig.update_layout(
            title=f"<b>Incident Timeline: {scenario_name}</b>",
            height=450,
            paper_bgcolor="rgba(0,0,0,0)",
            plot_bgcolor="rgba(0,0,0,0)",
            hovermode='closest',
            clickmode='event+select',
            yaxis=dict(
                showticklabels=False,
                range=[0.5, 1.5],
                gridcolor="rgba(200,200,200,0.1)"
            ),
            xaxis=dict(
                gridcolor="rgba(200,200,200,0.1)"
            ),
            showlegend=True,
            legend=dict(
                yanchor="top",
                y=0.99,
                xanchor="left",
                x=0.01
            )
        )
        
        return fig
    
    # Create initial timeline
    initial_timeline = create_scenario_timeline(default_scenario)
    
    # Connect the dropdown change event to update all components
    scenario_dropdown.change(
        fn=update_scenario_details,
        inputs=[scenario_dropdown],
        outputs=[scenario_description, metrics_display, impact_display, timeline_output]
    )
    
    # Initialize timeline output with the default scenario timeline
    timeline_output.value = initial_timeline
    
    return (scenario_dropdown, scenario_description, metrics_display, impact_display,
            timeline_output, oss_btn, enterprise_btn, approval_toggle, demo_btn,
            approval_display, oss_results_display, enterprise_results_display)


def create_tab2_business_roi(scenarios: Dict) -> Tuple:
    """Create Tab 2: Business Impact & ROI - FIXED VERSION"""
    with gr.Column():
        gr.Markdown("### ๐Ÿ“Š Executive Dashboard")
        dashboard_output = gr.Plot(label="", show_label=False)
        
        gr.Markdown("### ๐Ÿงฎ ROI Calculator")
        with gr.Row():
            with gr.Column(scale=1):
                # Scenario selector - FIXED: Initialize with scenarios
                roi_scenario_dropdown = gr.Dropdown(
                    choices=list(scenarios.keys()),
                    value="Cache Miss Storm",
                    label="Select scenario for ROI calculation:",
                    interactive=True
                )
                
                monthly_slider = gr.Slider(
                    1, 100, value=15, step=1,
                    label="Monthly similar incidents",
                    interactive=True
                )
                
                team_slider = gr.Slider(
                    1, 20, value=5, step=1,
                    label="Reliability team size",
                    interactive=True
                )
                
                calculate_btn = gr.Button(
                    "Calculate ROI",
                    variant="primary",
                    size="lg"
                )
            
            with gr.Column(scale=2):
                roi_output = gr.JSON(
                    label="ROI Analysis Results",
                    value={}
                )
                
                roi_chart = gr.Plot(label="Cost Comparison", show_label=False)
    
    return (dashboard_output, roi_scenario_dropdown, monthly_slider, team_slider,
            calculate_btn, roi_output, roi_chart)


def create_tab3_enterprise_features() -> Tuple:
    """Create Tab 3: Enterprise Features - UPDATED"""
    with gr.Row():
        # Left Column
        with gr.Column(scale=1):
            gr.Markdown("### ๐Ÿ” License Management")
            
            license_display = gr.JSON(
                value={
                    "status": "Active",
                    "tier": "Enterprise",
                    "expires": "2026-12-31",
                    "features": ["autonomous_healing", "compliance", "audit_trail", 
                               "predictive_analytics", "multi_cloud", "role_based_access"]
                },
                label="Current License"
            )
            
            with gr.Row():
                validate_btn = gr.Button("๐Ÿ” Validate", variant="secondary")
                trial_btn = gr.Button("๐Ÿ†“ Start Trial", variant="primary")
                upgrade_btn = gr.Button("๐Ÿš€ Upgrade", variant="secondary")
            
            gr.Markdown("### โšก MCP Execution Modes")
            
            mcp_mode = gr.Radio(
                choices=["advisory", "approval", "autonomous"],
                value="advisory",
                label="Execution Mode",
                interactive=True,
                info="advisory = OSS only, approval = human review, autonomous = AI-driven"
            )
            
            mcp_mode_info = gr.JSON(
                value={
                    "current_mode": "advisory",
                    "description": "OSS Edition - Analysis only, no execution",
                    "features": ["Incident analysis", "RAG similarity", "HealingIntent creation"]
                },
                label="Mode Details"
            )
        
        # Right Column
        with gr.Column(scale=1):
            gr.Markdown("### ๐Ÿ“‹ Feature Comparison")
            
            features_table = gr.Dataframe(
                headers=["Feature", "OSS", "Enterprise"],
                value=[
                    ["Autonomous Healing", "โŒ", "โœ…"],
                    ["Compliance Automation", "โŒ", "โœ…"],
                    ["Predictive Analytics", "โŒ", "โœ…"],
                    ["Multi-Cloud Support", "โŒ", "โœ…"],
                    ["Audit Trail", "Basic", "Comprehensive"],
                    ["Role-Based Access", "โŒ", "โœ…"],
                    ["Custom Dashboards", "โŒ", "โœ…"],
                    ["Enterprise Support", "Community", "24/7 SLA"],
                    ["Custom Integrations", "โŒ", "โœ…"],
                    ["Advanced Analytics", "โŒ", "โœ…"]
                ],
                label="",
                interactive=False
            )
            
            gr.Markdown("### ๐Ÿ”— Integrations")
            
            integrations_table = gr.Dataframe(
                headers=["Platform", "Status", "Type"],
                value=[
                    ["AWS", "โœ… Connected", "Cloud"],
                    ["Azure", "โœ… Connected", "Cloud"],
                    ["GCP", "โœ… Connected", "Cloud"],
                    ["Datadog", "โœ… Connected", "Monitoring"],
                    ["PagerDuty", "โœ… Connected", "Alerting"],
                    ["ServiceNow", "โœ… Connected", "ITSM"],
                    ["Slack", "โœ… Connected", "Collaboration"],
                    ["Teams", "โœ… Connected", "Collaboration"],
                    ["GitHub", "โœ… Connected", "DevOps"],
                    ["GitLab", "โœ… Connected", "DevOps"],
                    ["Jira", "โœ… Connected", "Project Management"],
                    ["Splunk", "โœ… Connected", "Monitoring"],
                    ["New Relic", "โœ… Connected", "APM"],
                    ["Prometheus", "โœ… Connected", "Metrics"],
                    ["Elasticsearch", "โœ… Connected", "Logging"]
                ],
                label="",
                interactive=False
            )
    
    return (license_display, validate_btn, trial_btn, upgrade_btn,
            mcp_mode, mcp_mode_info, features_table, integrations_table)


def create_tab4_audit_trail() -> Tuple:
    """Create Tab 4: Audit Trail & History - WITH DEMO DATA"""
    # Demo data
    demo_executions = [
        ["14:30", "Cache Miss Storm", "Autonomous", "โœ… Success", "$7,225", "Auto-execution"],
        ["14:15", "Database Connection Pool", "Approval", "โœ… Success", "$3,570", "Approved by admin"],
        ["13:45", "Memory Leak", "Advisory", "โš ๏ธ Analysis", "$0", "OSS analysis only"],
        ["13:20", "Cache Miss Storm", "Autonomous", "โœ… Success", "$7,225", "Pattern match"],
        ["12:50", "API Rate Limit", "Approval", "โœ… Success", "$3,230", "Scheduled fix"],
        ["12:15", "Network Partition", "Autonomous", "โœ… Success", "$10,200", "Emergency response"],
        ["11:40", "Storage I/O", "Advisory", "โš ๏ธ Analysis", "$0", "Performance review"]
    ]
    
    demo_incidents = [
        ["14:30", "redis_cache", "Cache Miss Storm", "CRITICAL", "Resolved"],
        ["14:15", "postgresql", "Database Connection Pool", "HIGH", "Resolved"],
        ["13:45", "java_service", "Memory Leak", "HIGH", "Analyzed"],
        ["13:20", "redis_cache", "Cache Miss Storm", "CRITICAL", "Resolved"],
        ["12:50", "api_gateway", "API Rate Limit", "MEDIUM", "Resolved"],
        ["12:15", "database", "Network Partition", "CRITICAL", "Resolved"],
        ["11:40", "storage", "Storage I/O", "HIGH", "Analyzed"],
        ["11:10", "redis_cache", "Cache Performance", "LOW", "Monitoring"],
        ["10:45", "load_balancer", "Traffic Spike", "MEDIUM", "Auto-scaled"],
        ["10:20", "api_gateway", "Rate Limit", "MEDIUM", "Resolved"]
    ]
    
    with gr.Row():
        # Left Column
        with gr.Column(scale=1):
            gr.Markdown("### ๐Ÿ“‹ Execution History")
            
            with gr.Row():
                refresh_btn = gr.Button("๐Ÿ”„ Refresh", variant="secondary", size="sm")
                clear_btn = gr.Button("๐Ÿ—‘๏ธ Clear", variant="stop", size="sm")
                export_btn = gr.Button("๐Ÿ“ฅ Export", variant="secondary", size="sm")
            
            execution_table = gr.Dataframe(
                headers=["Time", "Scenario", "Mode", "Status", "Savings", "Details"],
                value=demo_executions,
                label="",
                interactive=False
            )
        
        # Right Column
        with gr.Column(scale=1):
            gr.Markdown("### ๐Ÿ“Š Incident History")
            
            incident_table = gr.Dataframe(
                headers=["Time", "Component", "Scenario", "Severity", "Status"],
                value=demo_incidents,
                label="",
                interactive=False
            )
            
            gr.Markdown("### ๐Ÿ“ค Export")
            export_text = gr.Textbox(
                label="Audit Trail (JSON)",
                lines=6,
                interactive=False
            )
    
    return (refresh_btn, clear_btn, export_btn, execution_table,
            incident_table, export_text)


def create_tab5_learning_engine() -> Tuple:
    """Create Tab 5: Learning Engine - WITH DEMO DATA"""
    # Demo data
    demo_search_results = [
        ["Cache Miss Storm", "92%", "Scale Redis + Circuit Breaker", "โœ… Auto-healed"],
        ["Database Connection", "85%", "Increase pool + Monitoring", "โœ… Approved"],
        ["Memory Leak Pattern", "78%", "Heap analysis + Restart", "โš ๏ธ Advisory"],
        ["API Rate Limit", "72%", "Backoff + Queue", "โœ… Auto-healed"],
        ["Network Partition", "65%", "Quorum + Consensus", "โœ… Emergency"]
    ]
    
    # Create a simple demo graph
    fig = go.Figure(data=go.Scatter(
        x=[1, 2, 3, 4, 5],
        y=[2, 5, 3, 8, 7],
        mode='markers+text',
        marker=dict(size=[20, 30, 25, 40, 35], color=['#FF6B6B', '#4ECDC4', '#45B7D1', '#FFE66D', '#9B59B6']),
        text=['Cache', 'DB', 'Memory', 'API', 'Network'],
        textposition="top center"
    ))
    
    fig.update_layout(
        title="Incident Pattern Relationships",
        height=400,
        paper_bgcolor="rgba(0,0,0,0)",
        plot_bgcolor="rgba(0,0,0,0)"
    )
    
    with gr.Row():
        # Left Column
        with gr.Column(scale=2):
            gr.Markdown("### ๐Ÿง  Incident Memory Graph")
            
            learning_graph = gr.Plot(value=fig, label="", show_label=False)
            
            with gr.Row():
                graph_type = gr.Radio(
                    choices=["Force", "Hierarchical", "Circular"],
                    value="Force",
                    label="Layout",
                    interactive=True
                )
                show_labels = gr.Checkbox(label="Show Labels", value=True, interactive=True)
            
            gr.Markdown("### ๐Ÿ” Similarity Search")
            
            search_query = gr.Textbox(
                label="Describe incident or paste metrics",
                placeholder="e.g., 'Redis cache miss causing database overload'",
                lines=2,
                interactive=True
            )
            
            with gr.Row():
                search_btn = gr.Button("๐Ÿ” Search", variant="primary")
                clear_btn = gr.Button("Clear", variant="secondary")
            
            search_results = gr.Dataframe(
                headers=["Incident", "Similarity", "Resolution", "Actions"],
                value=demo_search_results,
                label="",
                interactive=False
            )
        
        # Right Column
        with gr.Column(scale=1):
            gr.Markdown("### ๐Ÿ“Š Learning Stats")
            
            stats_display = gr.JSON(
                value={
                    "total_incidents": 42,
                    "patterns_detected": 6,
                    "similarity_searches": 128,
                    "confidence_threshold": 0.85,
                    "successful_predictions": 38,
                    "accuracy_rate": "90.5%"
                },
                label="Statistics"
            )
            
            gr.Markdown("### ๐ŸŽฏ Pattern Detection")
            
            patterns_display = gr.JSON(
                value={
                    "cache_miss_storm": {"occurrences": 12, "confidence": 0.92, "auto_heal": True},
                    "db_connection_exhaustion": {"occurrences": 8, "confidence": 0.88, "auto_heal": True},
                    "memory_leak_java": {"occurrences": 5, "confidence": 0.85, "auto_heal": False},
                    "api_rate_limit": {"occurrences": 10, "confidence": 0.91, "auto_heal": True},
                    "network_partition": {"occurrences": 3, "confidence": 0.79, "auto_heal": True},
                    "storage_io_saturation": {"occurrences": 4, "confidence": 0.86, "auto_heal": False}
                },
                label="Detected Patterns"
            )
            
            gr.Markdown("### ๐Ÿ“ˆ Performance")
            
            performance_display = gr.JSON(
                value={
                    "avg_resolution_time": "8.2 min",
                    "success_rate": "95.2%",
                    "auto_heal_rate": "78.6%",
                    "mttr_reduction": "85%",
                    "cost_savings": "$1.2M",
                    "roi_multiplier": "5.2ร—"
                },
                label="Performance Metrics"
            )
    
    return (learning_graph, graph_type, show_labels, search_query, search_btn,
            clear_btn, search_results, stats_display, patterns_display, performance_display)


def create_footer() -> gr.HTML:
    """Create the demo footer - UPDATED FOR 2026"""
    return gr.HTML("""
    <div style="margin-top: 40px; padding: 30px; background: linear-gradient(135deg, #1a365d 0%, #2d3748 100%); border-radius: 20px; color: white;">
        <div style="border-top: 1px solid #4a5568; padding-top: 20px; text-align: center; color: #a0aec0; font-size: 0.9rem;">
            <p style="margin: 0;">ยฉ 2026 Agentic Reliability Framework. Demo v3.8.0 Enterprise Edition.</p>
            <p style="margin: 10px 0 0 0; font-size: 0.85rem; color: #cbd5e0;">
                This is a demonstration environment showcasing ARF capabilities.<br>
                Actual implementation results may vary based on specific use cases and configurations.
            </p>
            <p style="margin: 15px 0 0 0; font-size: 0.8rem; color: #718096;">
                For production inquiries or enterprise licensing, visit 
                <a href="https://arf.dev/enterprise" style="color: #4ECDC4; text-decoration: none; font-weight: 600;">
                    arf.dev/enterprise
                </a>
            </p>
        </div>
    </div>
    """)