File size: 16,703 Bytes
3f5fadf
7f3d172
 
3f5fadf
 
 
7f3d172
7ebbb94
7f3d172
 
 
 
 
 
 
 
 
 
 
 
 
3f5fadf
fef95f5
 
 
 
9d7ff51
7f3d172
9d7ff51
 
7f3d172
 
7450c87
7f3d172
 
 
 
 
 
 
 
 
 
 
 
fef95f5
7f3d172
 
 
 
9d7ff51
 
7f3d172
9d7ff51
4335b20
7f3d172
 
 
 
 
 
 
 
 
 
 
b20e8fd
7f3d172
fef95f5
7f3d172
 
 
 
 
fef95f5
7f3d172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fef95f5
7f3d172
 
 
fef95f5
 
7f3d172
fef95f5
7f3d172
 
 
fef95f5
7f3d172
fef95f5
7f3d172
 
fef95f5
7f3d172
 
fef95f5
7f3d172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
be213f1
9d7ff51
7f3d172
9d7ff51
3f5fadf
7f3d172
 
 
 
 
2aa7110
fef95f5
7f3d172
 
 
fef95f5
a82ff13
b20e8fd
 
7f3d172
b20e8fd
11cd487
7f3d172
 
 
b20e8fd
3f5fadf
7f3d172
 
 
 
 
 
 
fef95f5
b20e8fd
 
 
fef95f5
b20e8fd
7f3d172
b20e8fd
 
fef95f5
7f3d172
b20e8fd
7f3d172
 
7c722fd
 
b20e8fd
fef95f5
7f3d172
fef95f5
7c722fd
b20e8fd
fef95f5
7f3d172
fef95f5
b20e8fd
7f3d172
b20e8fd
7f3d172
 
fef95f5
7f3d172
b20e8fd
 
 
7c722fd
7f3d172
 
 
 
 
7c722fd
7f3d172
7c722fd
b20e8fd
 
7c722fd
7f3d172
 
 
 
 
 
 
 
7c722fd
7f3d172
 
7c722fd
fef95f5
b20e8fd
 
 
 
a82ff13
fef95f5
 
 
 
b20e8fd
7450c87
b20e8fd
fef95f5
b20e8fd
fef95f5
7f3d172
fef95f5
7450c87
fef95f5
b20e8fd
 
 
fef95f5
b20e8fd
7f3d172
 
b20e8fd
fef95f5
b20e8fd
7f3d172
 
b20e8fd
fef95f5
b20e8fd
7f3d172
 
b20e8fd
 
a82ff13
b20e8fd
fef95f5
 
7f3d172
fef95f5
a82ff13
fef95f5
7f3d172
b20e8fd
 
 
 
 
 
7f3d172
 
 
 
 
 
 
b20e8fd
 
 
7f3d172
 
 
 
 
 
 
 
 
 
 
 
b20e8fd
 
fef95f5
b20e8fd
7f3d172
fef95f5
7f3d172
 
fef95f5
b20e8fd
 
fef95f5
7f3d172
fef95f5
7f3d172
fef95f5
11cd487
7f3d172
fef95f5
7f3d172
fef95f5
 
 
 
7f3d172
fef95f5
7f3d172
fef95f5
 
 
 
 
 
 
 
 
 
 
7f3d172
b20e8fd
7f3d172
fef95f5
 
 
 
7f3d172
 
 
 
 
 
 
 
fef95f5
7f3d172
 
fef95f5
7f3d172
fef95f5
 
7f3d172
fef95f5
7f3d172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b20e8fd
7f3d172
 
 
 
 
 
 
 
b20e8fd
fef95f5
7342596
9d7ff51
7f3d172
9d7ff51
7ebbb94
7f3d172
 
 
 
 
 
 
9d7ff51
7f3d172
7ebbb94
 
 
 
fef95f5
 
7f3d172
 
 
 
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
"""
๐Ÿš€ ARF Ultimate Investor Demo v3.6.0 - Main Application
Enhanced with best practices, Pythonic code, and investor-grade UX
"""

import logging
from typing import Dict, Any, List, Optional
import gradio as gr

# Import modules
from core.data_models import IncidentDatabase, IncidentScenario, DemoMode
from core.visualizations import EnhancedVisualizationEngine
from core.calculators import EnhancedROICalculator
from demo.orchestrator import DemoOrchestrator
from ui.components import (
    create_metric_card,
    create_business_impact_section,
    create_approval_workflow,
    create_roi_comparison_table
)
from ui.styles import CUSTOM_CSS, THEME

# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# ===========================================
# APPLICATION STATE
# ===========================================

class ARFDemoState:
    """Maintain application state"""
    
    def __init__(self):
        self.scenario_db = IncidentDatabase()
        self.viz_engine = EnhancedVisualizationEngine()
        self.roi_calculator = EnhancedROICalculator()
        self.demo_orchestrator = DemoOrchestrator(DemoMode.INVESTOR)
        self.current_scenario = None
        self.approval_required = True
        
    def get_scenario(self, name: str) -> Optional[IncidentScenario]:
        """Get scenario by name"""
        scenarios = self.scenario_db.get_scenarios()
        return scenarios.get(name)
    
    def get_scenario_names(self) -> List[str]:
        """Get all scenario names"""
        scenarios = self.scenario_db.get_scenarios()
        return list(scenarios.keys())

# ===========================================
# EVENT HANDLERS
# ===========================================

class EventHandlers:
    """Handle all application events"""
    
    def __init__(self, state: ARFDemoState):
        self.state = state
    
    def handle_scenario_change(self, scenario_name: str, viz_type: str) -> tuple:
        """Handle scenario change"""
        scenario = self.state.get_scenario(scenario_name)
        if not scenario:
            return {}, {}, self.state.viz_engine.create_interactive_timeline(None)
        
        self.state.current_scenario = scenario
        
        # Create visualization
        if viz_type == "Interactive Timeline":
            viz = self.state.viz_engine.create_interactive_timeline(scenario)
        else:
            viz = self.state.viz_engine.create_executive_dashboard()
        
        return scenario.metrics, scenario.impact, viz
    
    def handle_oss_analysis(self, scenario_name: str) -> Dict:
        """Handle OSS analysis"""
        scenario = self.state.get_scenario(scenario_name)
        if not scenario or not scenario.oss_analysis:
            return {"status": "โŒ No analysis available"}
        
        return scenario.oss_analysis.to_dict()
    
    def handle_enterprise_execution(self, scenario_name: str, 
                                   approval_required: bool) -> tuple:
        """Handle enterprise execution"""
        self.state.approval_required = approval_required
        
        scenario = self.state.get_scenario(scenario_name)
        if not scenario or not scenario.enterprise_results:
            # Default results
            results = {
                "actions_completed": ["โœ… Auto-scaled resources", "โœ… Optimized configuration"],
                "metrics_improvement": {"Recovery": "Complete"},
                "business_impact": {"Cost Saved": "$5,000"}
            }
        else:
            results = scenario.enterprise_results.to_dict()
        
        # Update approval in results
        if approval_required:
            results["status"] = "โœ… Approved and Executed"
        else:
            results["status"] = "โœ… Auto-Executed"
        
        # Create approval workflow display
        approval_display = create_approval_workflow(approval_required)
        
        # Configuration
        config = {"approval_required": approval_required, "compliance_mode": "strict"}
        
        return approval_display, config, results
    
    def handle_roi_calculation(self, monthly_incidents: int,
                              avg_impact: int, team_size: int) -> Dict:
        """Handle ROI calculation"""
        try:
            return self.state.roi_calculator.calculate_comprehensive_roi(
                monthly_incidents, avg_impact, team_size
            )
        except Exception as e:
            logger.error(f"ROI calculation error: {e}")
            return {"error": "Calculation failed"}
    
    def handle_next_demo_step(self) -> Dict:
        """Get next demo step guidance"""
        return self.state.demo_orchestrator.get_next_guidance()

# ===========================================
# MAIN INTERFACE
# ===========================================

def create_main_interface():
    """Create the main Gradio interface"""
    
    state = ARFDemoState()
    handlers = EventHandlers(state)
    
    with gr.Blocks(
        title="๐Ÿš€ ARF Investor Demo v3.6.0",
        theme=THEME,
        css=CUSTOM_CSS
    ) as demo:
        
        # ============ HEADER ============
        gr.Markdown("""
        # ๐Ÿš€ Agentic Reliability Framework - Investor Demo v3.6.0
        ## From Cost Center to Profit Engine: 5.2ร— ROI with Autonomous Reliability
        
        <div style='color: #666; font-size: 16px; margin-top: 10px;'>
        Experience the transformation: <b>OSS (Advisory)</b> โ†” <b>Enterprise (Autonomous)</b>
        </div>
        """)
        
        # ============ PRESENTER GUIDANCE ============
        gr.Markdown("### ๐ŸŽฏ Presenter Guidance")
        next_step_btn = gr.Button("๐ŸŽฌ Next Demo Step", variant="secondary", size="sm")
        guidance_display = gr.HTML(
            value="<div class='presenter-guidance'>Click 'Next Demo Step' for guidance</div>"
        )
        
        # ============ MAIN TABS ============
        with gr.Tabs():
            
            # TAB 1: LIVE INCIDENT DEMO
            with gr.TabItem("๐Ÿ”ฅ Live Incident Demo", id="live-demo"):
                with gr.Row():
                    # Left Panel - Incident Details
                    with gr.Column(scale=1):
                        gr.Markdown("### ๐ŸŽฌ Incident Scenario")
                        scenario_dropdown = gr.Dropdown(
                            choices=state.get_scenario_names(),
                            value="Cache Miss Storm",
                            label="Select critical incident:",
                            interactive=True
                        )
                        
                        gr.Markdown("### ๐Ÿ“Š Current Crisis Metrics")
                        metrics_display = gr.JSON(
                            value=state.get_scenario("Cache Miss Storm").metrics
                        )
                        
                        gr.Markdown("### ๐Ÿ’ฐ Business Impact")
                        impact_display = gr.JSON(
                            value=state.get_scenario("Cache Miss Storm").impact
                        )
                    
                    # Right Panel - Visualization & Actions
                    with gr.Column(scale=2):
                        # Visualization Selector
                        gr.Markdown("### ๐Ÿ“ˆ Incident Visualization")
                        viz_radio = gr.Radio(
                            choices=["Interactive Timeline", "Executive Dashboard"],
                            value="Interactive Timeline",
                            label="Choose visualization:"
                        )
                        
                        # Visualization Output
                        timeline_output = gr.Plot(
                            label="Visualization",
                            show_label=False
                        )
                        
                        # Action Section
                        with gr.Row():
                            oss_btn = gr.Button("๐Ÿ†“ Run OSS Analysis", variant="secondary")
                            enterprise_btn = gr.Button("๐Ÿš€ Execute Enterprise Healing", variant="primary")
                        
                        # Approval Controls
                        with gr.Row():
                            approval_toggle = gr.Checkbox(
                                label="๐Ÿ” Require Manual Approval",
                                value=True,
                                info="Toggle to show approval workflow vs auto-execution"
                            )
                            demo_mode_btn = gr.Button("๐ŸŽฏ Auto-Demo Mode", variant="secondary", size="sm")
                        
                        # Approval Workflow Display
                        approval_display = gr.HTML()
                        
                        # Configuration
                        config_display = gr.JSON(
                            label="โš™๏ธ Enterprise Configuration",
                            value={"approval_required": True, "compliance_mode": "strict"}
                        )
                        
                        # Results
                        results_display = gr.JSON(
                            label="๐ŸŽฏ Execution Results",
                            value={"status": "Ready for execution..."}
                        )
            
            # TAB 2: BUSINESS IMPACT & ROI
            with gr.TabItem("๐Ÿ’ฐ Business Impact & ROI", id="business-roi"):
                with gr.Column():
                    # Business Dashboard
                    gr.Markdown("### ๐Ÿ“Š Executive Business Dashboard")
                    dashboard_output = gr.Plot()
                    
                    # ROI Calculator
                    gr.Markdown("### ๐Ÿงฎ Interactive ROI Calculator")
                    with gr.Row():
                        with gr.Column(scale=1):
                            monthly_slider = gr.Slider(
                                1, 100, value=15, step=1,
                                label="Monthly incidents",
                                info="Typical range: 10-50 incidents/month"
                            )
                            impact_slider = gr.Slider(
                                1000, 50000, value=8500, step=500,
                                label="Average incident impact ($)",
                                info="Includes revenue loss, engineer time, customer impact"
                            )
                            team_slider = gr.Slider(
                                1, 20, value=5, step=1,
                                label="Reliability team size",
                                info="SREs, DevOps engineers managing incidents"
                            )
                            calculate_btn = gr.Button("Calculate My ROI", variant="primary")
                        
                        with gr.Column(scale=2):
                            roi_output = gr.JSON(
                                label="Your ROI Analysis",
                                value={"status": "Adjust sliders and click Calculate"}
                            )
                    
                    # Capability Comparison
                    comparison_table = create_roi_comparison_table()
        
        # ============ FOOTER ============
        gr.Markdown("---")
        with gr.Row():
            with gr.Column(scale=2):
                gr.Markdown("""
                **๐Ÿ“ž Contact & Resources**
                <div style='margin-top: 10px;'>
                ๐Ÿ“ง <b>Email:</b> enterprise@arf.dev<br>
                ๐ŸŒ <b>Website:</b> <a href='https://arf.dev' target='_blank'>https://arf.dev</a><br>
                ๐Ÿ“š <b>Documentation:</b> <a href='https://docs.arf.dev' target='_blank'>https://docs.arf.dev</a><br>
                ๐Ÿ’ป <b>GitHub:</b> <a href='https://github.com/petterjuan/agentic-reliability-framework' target='_blank'>petterjuan/agentic-reliability-framework</a>
                </div>
                """)
            with gr.Column(scale=1):
                gr.Markdown("""
                **๐ŸŽฏ Schedule a Demo**
                <div style='margin-top: 10px;'>
                <a href='https://arf.dev/demo' target='_blank' style='
                    display: inline-block;
                    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
                    color: white;
                    padding: 10px 20px;
                    border-radius: 6px;
                    text-decoration: none;
                    font-weight: bold;
                '>Schedule 30-min Demo โ†’</a>
                </div>
                """)
        
        # ============ EVENT HANDLERS ============
        
        # Scenario changes
        scenario_dropdown.change(
            handlers.handle_scenario_change,
            inputs=[scenario_dropdown, viz_radio],
            outputs=[metrics_display, impact_display, timeline_output]
        )
        
        viz_radio.change(
            handlers.handle_scenario_change,
            inputs=[scenario_dropdown, viz_radio],
            outputs=[metrics_display, impact_display, timeline_output]
        )
        
        # OSS Analysis
        oss_btn.click(
            handlers.handle_oss_analysis,
            inputs=[scenario_dropdown],
            outputs=[results_display]
        )
        
        # Enterprise Execution
        enterprise_btn.click(
            handlers.handle_enterprise_execution,
            inputs=[scenario_dropdown, approval_toggle],
            outputs=[approval_display, config_display, results_display]
        )
        
        # Approval toggle updates config
        approval_toggle.change(
            lambda approval: {"approval_required": approval, "compliance_mode": "strict"},
            inputs=[approval_toggle],
            outputs=[config_display]
        )
        
        # ROI Calculation
        calculate_btn.click(
            handlers.handle_roi_calculation,
            inputs=[monthly_slider, impact_slider, team_slider],
            outputs=[roi_output]
        )
        
        # Next demo step guidance
        next_step_btn.click(
            handlers.handle_next_demo_step,
            outputs=[guidance_display]
        )
        
        # Demo mode button
        demo_mode_btn.click(
            lambda: (
                {"approval_required": False, "compliance_mode": "strict"},
                create_approval_workflow(False)
            ),
            outputs=[config_display, approval_display]
        )
        
        # ============ INITIAL LOAD ============
        
        def load_initial_state():
            """Load initial visualizations and data"""
            # Get initial scenario
            scenario = state.get_scenario("Cache Miss Storm")
            
            # Create visualizations
            timeline_viz = state.viz_engine.create_interactive_timeline(scenario)
            dashboard_viz = state.viz_engine.create_executive_dashboard()
            
            # Get initial guidance
            guidance = state.demo_orchestrator.get_next_guidance()
            
            return (
                scenario.metrics if scenario else {},
                scenario.impact if scenario else {},
                timeline_viz,
                dashboard_viz,
                guidance["html"]
            )
        
        demo.load(
            load_initial_state,
            outputs=[
                metrics_display, 
                impact_display, 
                timeline_output, 
                dashboard_output,
                guidance_display
            ]
        )
        
        # ============ INSTRUCTIONS ============
        gr.Markdown("""
        <div class='footer'>
        ๐Ÿš€ <b>ARF Ultimate Investor Demo v3.6.0</b> | Enhanced with Professional Analytics & Best Practices  
        <i>Built with โค๏ธ using Python, Gradio & Plotly | All visualizations guaranteed working</i>
        </div>
        """)
    
    return demo

# ===========================================
# APPLICATION ENTRY POINT
# ===========================================

def main():
    """Main entry point"""
    logger.info("๐Ÿš€ Launching ARF Investor Demo v3.6.0")
    logger.info("โœ… Best practices applied")
    logger.info("โœ… Pythonic code structure")
    logger.info("โœ… Investor-grade UX")
    logger.info("โœ… Enhanced visualizations")
    
    demo = create_main_interface()
    demo.launch(
        server_name="0.0.0.0",
        server_port=7860,
        share=False,
        debug=False,
        show_error=True
    )

if __name__ == "__main__":
    main()