petter2025 commited on
Commit
0049149
·
verified ·
1 Parent(s): eddad90

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -5
app.py CHANGED
@@ -2194,9 +2194,50 @@ def create_demo_interface():
2194
  ]
2195
  )
2196
 
2197
- # Run OSS Analysis - FIXED: Now returns DataFrame for incident_table
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2198
  oss_btn.click(
2199
- fn=run_true_arf_analysis,
2200
  inputs=[scenario_dropdown],
2201
  outputs=[
2202
  detection_agent, recall_agent, decision_agent,
@@ -2218,8 +2259,8 @@ def create_demo_interface():
2218
  # Step 1: Update scenario with metrics
2219
  update_result = update_scenario_display_with_metrics(scenario_name)
2220
 
2221
- # Step 2: Run true ARF analysis
2222
- oss_result = await run_true_arf_analysis(scenario_name)
2223
 
2224
  # Step 3: Execute Enterprise (simulation) with boundary context
2225
  await asyncio.sleep(1)
@@ -2554,7 +2595,6 @@ def create_demo_interface():
2554
  logger.info("✅ Demo interface created successfully with boundary awareness, realism panel, and dynamic performance metrics")
2555
 
2556
  return demo
2557
-
2558
  # ===========================================
2559
  # LAUNCH FUNCTION
2560
  # ===========================================
 
2194
  ]
2195
  )
2196
 
2197
+ # ===========================================
2198
+ # FIX: OSS Analysis Button Connection
2199
+ # ===========================================
2200
+ def run_oss_analysis_sync(scenario_name: str) -> tuple:
2201
+ """
2202
+ Synchronous wrapper for run_true_arf_analysis()
2203
+ Gradio buttons need sync functions, not async
2204
+ """
2205
+ logger.info(f"🔍 Running OSS analysis for: {scenario_name}")
2206
+ try:
2207
+ # Run the async function in sync context
2208
+ return AsyncRunner.run_async(run_true_arf_analysis(scenario_name))
2209
+ except Exception as e:
2210
+ logger.error(f"OSS analysis failed: {e}")
2211
+ # Return error state with proper HTML for all agents
2212
+ error_html = f"""
2213
+ <div style="border: 2px solid #ef4444; border-radius: 14px; padding: 18px;
2214
+ background: linear-gradient(135deg, #fef2f2 0%, #ffffff 100%);
2215
+ text-align: center; flex: 1; margin: 5px; min-height: 180px;">
2216
+ <div style="font-size: 32px; margin-bottom: 10px; color: #ef4444;">❌</div>
2217
+ <div style="width: 100%;">
2218
+ <h4 style="margin: 0 0 8px 0; font-size: 16px; color: #1e293b;">Analysis Error</h4>
2219
+ <p style="font-size: 13px; color: #64748b; margin-bottom: 12px; line-height: 1.4;">
2220
+ {str(e)[:100]}
2221
+ </p>
2222
+ </div>
2223
+ </div>
2224
+ """
2225
+
2226
+ error_dict = {
2227
+ "status": "error",
2228
+ "error": str(e),
2229
+ "scenario": scenario_name,
2230
+ "arf_version": "3.3.9"
2231
+ }
2232
+ error_df = pd.DataFrame(columns=["Error", "Message"]).from_records([
2233
+ {"Error": "Analysis Failed", "Message": str(e)}
2234
+ ])
2235
+
2236
+ return error_html, error_html, error_html, error_dict, error_df
2237
+
2238
+ # Run OSS Analysis - FIXED: Now uses synchronous wrapper
2239
  oss_btn.click(
2240
+ fn=run_oss_analysis_sync, # ✅ FIXED: Use sync wrapper
2241
  inputs=[scenario_dropdown],
2242
  outputs=[
2243
  detection_agent, recall_agent, decision_agent,
 
2259
  # Step 1: Update scenario with metrics
2260
  update_result = update_scenario_display_with_metrics(scenario_name)
2261
 
2262
+ # Step 2: Run true ARF analysis using sync wrapper
2263
+ oss_result = run_oss_analysis_sync(scenario_name)
2264
 
2265
  # Step 3: Execute Enterprise (simulation) with boundary context
2266
  await asyncio.sleep(1)
 
2595
  logger.info("✅ Demo interface created successfully with boundary awareness, realism panel, and dynamic performance metrics")
2596
 
2597
  return demo
 
2598
  # ===========================================
2599
  # LAUNCH FUNCTION
2600
  # ===========================================