petter2025 commited on
Commit
d79de79
Β·
verified Β·
1 Parent(s): 7361c5f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +87 -52
app.py CHANGED
@@ -1976,32 +1976,6 @@ def update_scenario_display_with_metrics(scenario_name: str) -> tuple:
1976
  return (scenario_card, telemetry_fig, impact_fig, timeline_fig,
1977
  detection_time, recall_quality, confidence_score, sequencing_stage) # Changed
1978
 
1979
- # In the create_demo_interface function, update outputs:
1980
- demo_btn.click(
1981
- fn=run_complete_demo_async,
1982
- inputs=[scenario_dropdown],
1983
- outputs=[
1984
- scenario_card, telemetry_viz, impact_viz, timeline_viz,
1985
- detection_time, recall_quality, confidence_score, sequencing_stage, # Changed
1986
- detection_process, recall_process, decision_process,
1987
- oss_results_display,
1988
- enterprise_results_display,
1989
- approval_display,
1990
- incident_table,
1991
- execution_table
1992
- ]
1993
- )
1994
-
1995
- # In the scenario_dropdown.change handler:
1996
- scenario_dropdown.change(
1997
- fn=update_scenario_display_with_metrics,
1998
- inputs=[scenario_dropdown],
1999
- outputs=[
2000
- scenario_card, telemetry_viz, impact_viz, timeline_viz,
2001
- detection_time, recall_quality, confidence_score, sequencing_stage # Changed
2002
- ]
2003
- )
2004
-
2005
  # ===========================================
2006
  # FIXED EXECUTION FUNCTION - Returns DataFrames
2007
  # ===========================================
@@ -2213,9 +2187,6 @@ def create_demo_interface():
2213
  global _demo_css
2214
  _demo_css = css_styles
2215
 
2216
- # Get boundary badges for the interface
2217
- boundary_badges = BoundaryManager.get_boundary_badges()
2218
-
2219
  # Create interface without css parameter (will be added in launch)
2220
  with gr.Blocks(
2221
  title=f"πŸš€ ARF Investor Demo v3.3.9 - TRUE ARF OSS Integration"
@@ -2233,23 +2204,88 @@ def create_demo_interface():
2233
 
2234
  # TAB 1: Live Incident Demo - NOW WITH DOCTRINAL COMPONENTS
2235
  with gr.TabItem("πŸ”₯ Live Incident Demo", id="tab1"):
2236
- # ===== SURGICAL FIX: LINE 2739 UNPACKING CONTRACT UPDATE =====
2237
- # OLD (incorrect - expecting 24 values):
2238
- # (scenario_dropdown, scenario_card, telemetry_viz, impact_viz,
2239
- # workflow_header, detection_agent, recall_agent, decision_agent,
2240
- # oss_section, enterprise_section, oss_btn, enterprise_btn,
2241
- # approval_toggle, mcp_mode, timeline_viz, realism_panel,
2242
- # detection_time, mttr, auto_heal, savings,
2243
- # oss_results_display, enterprise_results_display, approval_display, demo_btn) = components["create_tab1_incident_demo"]()
2244
-
2245
- # NEW (correct - expecting 26 doctrinal values):
2246
- (scenario_dropdown, historical_panel, scenario_card, telemetry_viz, impact_viz,
2247
- observation_gate_placeholder, sequencing_panel, workflow_header,
2248
- detection_process, recall_process, decision_process,
2249
- oss_section, enterprise_section, oss_btn, enterprise_btn,
2250
- approval_toggle, mcp_mode, timeline_viz,
2251
- detection_time, mttr, auto_heal, savings,
2252
- oss_results_display, enterprise_results_display, approval_display, demo_btn) = components["create_tab1_incident_demo"]()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2253
  # ===== END SURGICAL FIX =====
2254
 
2255
  # TAB 2: Business ROI
@@ -2280,12 +2316,11 @@ def create_demo_interface():
2280
 
2281
  # Update scenario display when dropdown changes - NOW INCLUDES PERFORMANCE METRICS
2282
  scenario_dropdown.change(
2283
- fn=update_scenario_display_with_metrics, # ← Changed to combined function
2284
  inputs=[scenario_dropdown],
2285
  outputs=[
2286
  scenario_card, telemetry_viz, impact_viz, timeline_viz,
2287
- detection_time, mttr, auto_heal, savings # 4 new outputs for metrics
2288
- # Note: realism_panel removed as it's now replaced by doctrinal components
2289
  ]
2290
  )
2291
 
@@ -2511,7 +2546,7 @@ def create_demo_interface():
2511
 
2512
  # Combine all results
2513
  return (
2514
- *update_result, # 8 outputs: scenario_card, telemetry_viz, impact_viz, timeline_viz, detection_time, mttr, auto_heal, savings
2515
  *oss_result[:3], # 3 outputs: detection_process, recall_process, decision_process
2516
  oss_result[3], # 1 output: oss_results_display
2517
  enterprise_results, # 1 output: enterprise_results_display
@@ -2526,7 +2561,7 @@ def create_demo_interface():
2526
  inputs=[scenario_dropdown],
2527
  outputs=[
2528
  scenario_card, telemetry_viz, impact_viz, timeline_viz,
2529
- detection_time, mttr, auto_heal, savings, # 8
2530
  detection_process, recall_process, decision_process, # 3
2531
  oss_results_display, # 1
2532
  enterprise_results_display, # 1
@@ -2646,7 +2681,7 @@ def create_demo_interface():
2646
  inputs=[],
2647
  outputs=[
2648
  scenario_card, telemetry_viz, impact_viz, timeline_viz,
2649
- detection_time, mttr, auto_heal, savings
2650
  ]
2651
  )
2652
 
 
1976
  return (scenario_card, telemetry_fig, impact_fig, timeline_fig,
1977
  detection_time, recall_quality, confidence_score, sequencing_stage) # Changed
1978
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1979
  # ===========================================
1980
  # FIXED EXECUTION FUNCTION - Returns DataFrames
1981
  # ===========================================
 
2187
  global _demo_css
2188
  _demo_css = css_styles
2189
 
 
 
 
2190
  # Create interface without css parameter (will be added in launch)
2191
  with gr.Blocks(
2192
  title=f"πŸš€ ARF Investor Demo v3.3.9 - TRUE ARF OSS Integration"
 
2204
 
2205
  # TAB 1: Live Incident Demo - NOW WITH DOCTRINAL COMPONENTS
2206
  with gr.TabItem("πŸ”₯ Live Incident Demo", id="tab1"):
2207
+ # ===== SURGICAL FIX: SAFE UNPACKING WITH ERROR HANDLING =====
2208
+ try:
2209
+ logger.info("πŸ”§ Extracting Tab1 components with safe unpacking...")
2210
+
2211
+ # Get the raw result tuple
2212
+ tab1_result = components["create_tab1_incident_demo"]()
2213
+
2214
+ # Debug logging for contract verification
2215
+ logger.info(f"πŸ“Š Tab1 result type: {type(tab1_result)}")
2216
+ if hasattr(tab1_result, '__len__'):
2217
+ logger.info(f"πŸ“Š Tab1 result length: {len(tab1_result)}")
2218
+ for i, item in enumerate(tab1_result):
2219
+ item_type = type(item).__name__ if hasattr(item, '__name__') else type(item)
2220
+ logger.debug(f" Index {i}: {item_type}")
2221
+
2222
+ # MANUAL INDEX-BASED UNPACKING (CONTRACT ENFORCEMENT)
2223
+ # Indices verified against components.py return statement
2224
+ scenario_dropdown = tab1_result[0]
2225
+ historical_panel = tab1_result[1]
2226
+ scenario_card = tab1_result[2]
2227
+ telemetry_viz = tab1_result[3]
2228
+ impact_viz = tab1_result[4]
2229
+ observation_gate_placeholder = tab1_result[5]
2230
+ sequencing_panel = tab1_result[6]
2231
+ workflow_header = tab1_result[7]
2232
+ detection_process = tab1_result[8]
2233
+ recall_process = tab1_result[9]
2234
+ decision_process = tab1_result[10]
2235
+ oss_section = tab1_result[11]
2236
+ enterprise_section = tab1_result[12]
2237
+ oss_btn = tab1_result[13]
2238
+ enterprise_btn = tab1_result[14]
2239
+ approval_toggle = tab1_result[15]
2240
+ mcp_mode = tab1_result[16]
2241
+ timeline_viz = tab1_result[17]
2242
+ detection_time = tab1_result[18]
2243
+ recall_quality = tab1_result[19] # ← CRITICAL: WAS mttr
2244
+ confidence_score = tab1_result[20] # ← CRITICAL: WAS auto_heal
2245
+ sequencing_stage = tab1_result[21] # ← CRITICAL: WAS savings
2246
+ oss_results_display = tab1_result[22]
2247
+ enterprise_results_display = tab1_result[23]
2248
+ approval_display = tab1_result[24]
2249
+ demo_btn = tab1_result[25] # ← CRITICAL: Index 25 MUST be demo_btn
2250
+
2251
+ logger.info("βœ… Tab1 components successfully extracted with correct contract")
2252
+
2253
+ except Exception as e:
2254
+ logger.error(f"❌ Tab1 component extraction failed: {e}")
2255
+ logger.error("πŸ”„ Creating fallback components to maintain system integrity...")
2256
+
2257
+ # FALLBACK CREATION (Minimal viable components)
2258
+ import gradio as gr
2259
+
2260
+ # Create minimal placeholder components
2261
+ scenario_dropdown = gr.Dropdown(choices=["Error Mode"], value="Error Mode")
2262
+ historical_panel = gr.DataFrame(value=[["System in recovery mode"]])
2263
+ scenario_card = gr.Markdown("### System Initialization Issue")
2264
+ telemetry_viz = gr.Plot()
2265
+ impact_viz = gr.Plot()
2266
+ observation_gate_placeholder = gr.Markdown("**Observation Gate:** System integrity check")
2267
+ sequencing_panel = gr.Markdown("**Sequencing:** Initializing...")
2268
+ workflow_header = gr.Markdown("### Policy Recovery Mode")
2269
+ detection_process = gr.Textbox(value="DETECTION: ERROR")
2270
+ recall_process = gr.Textbox(value="RECALL: ERROR")
2271
+ decision_process = gr.Textbox(value="DECISION: ERROR")
2272
+ oss_section = gr.Markdown("#### OSS: Unavailable")
2273
+ enterprise_section = gr.Markdown("#### Enterprise: Unavailable")
2274
+ oss_btn = gr.Button("Unavailable", variant="secondary")
2275
+ enterprise_btn = gr.Button("Unavailable", variant="secondary")
2276
+ approval_toggle = gr.Checkbox(label="Approval: Error", value=False)
2277
+ mcp_mode = gr.Radio(choices=["Error"], value="Error")
2278
+ timeline_viz = gr.Plot()
2279
+ detection_time = gr.Number(value=0)
2280
+ recall_quality = gr.Number(value=0) # ← CORRECT VARIABLE NAME
2281
+ confidence_score = gr.Number(value=0) # ← CORRECT VARIABLE NAME
2282
+ sequencing_stage = gr.Textbox(value="Error") # ← CORRECT VARIABLE NAME
2283
+ oss_results_display = gr.Markdown("### Results: Unavailable")
2284
+ enterprise_results_display = gr.Markdown("### Results: Unavailable")
2285
+ approval_display = gr.Markdown("**Status:** System recovery in progress")
2286
+ demo_btn = gr.Button("πŸ”„ System Recovery Required", variant="secondary", size="lg")
2287
+
2288
+ logger.warning("⚠️ Using fallback components - full functionality limited")
2289
  # ===== END SURGICAL FIX =====
2290
 
2291
  # TAB 2: Business ROI
 
2316
 
2317
  # Update scenario display when dropdown changes - NOW INCLUDES PERFORMANCE METRICS
2318
  scenario_dropdown.change(
2319
+ fn=update_scenario_display_with_metrics,
2320
  inputs=[scenario_dropdown],
2321
  outputs=[
2322
  scenario_card, telemetry_viz, impact_viz, timeline_viz,
2323
+ detection_time, recall_quality, confidence_score, sequencing_stage # ← CHANGED FROM mttr, auto_heal, savings
 
2324
  ]
2325
  )
2326
 
 
2546
 
2547
  # Combine all results
2548
  return (
2549
+ *update_result, # 8 outputs: scenario_card, telemetry_viz, impact_viz, timeline_viz, detection_time, recall_quality, confidence_score, sequencing_stage
2550
  *oss_result[:3], # 3 outputs: detection_process, recall_process, decision_process
2551
  oss_result[3], # 1 output: oss_results_display
2552
  enterprise_results, # 1 output: enterprise_results_display
 
2561
  inputs=[scenario_dropdown],
2562
  outputs=[
2563
  scenario_card, telemetry_viz, impact_viz, timeline_viz,
2564
+ detection_time, recall_quality, confidence_score, sequencing_stage, # 8
2565
  detection_process, recall_process, decision_process, # 3
2566
  oss_results_display, # 1
2567
  enterprise_results_display, # 1
 
2681
  inputs=[],
2682
  outputs=[
2683
  scenario_card, telemetry_viz, impact_viz, timeline_viz,
2684
+ detection_time, recall_quality, confidence_score, sequencing_stage
2685
  ]
2686
  )
2687