DocUA commited on
Commit
8a12473
·
1 Parent(s): 4956668

Fix mode switching in enhanced verification interface

Browse files

- Fix output mismatch in mode selection buttons (was returning 10 values, expected 6)
- Create direct_mode_switch helper function for simple mode switching
- Update all mode selection buttons to use consistent outputs
- Properly update interface visibility when switching modes
- Resolves 'A function returned too many output values' warning

src/interface/enhanced_verification_interface.py CHANGED
@@ -265,7 +265,17 @@ class EnhancedVerificationInterface:
265
  )
266
  else:
267
  # Direct switch (no progress to preserve)
268
- return perform_mode_switch(mode_type, current_session_val)
 
 
 
 
 
 
 
 
 
 
269
 
270
  except Exception as e:
271
  return (
@@ -391,42 +401,62 @@ class EnhancedVerificationInterface:
391
  ]
392
  )
393
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
394
  # Bind mode selection buttons
395
  enhanced_dataset_btn.click(
396
- lambda cm, cs: switch_to_mode("enhanced_dataset", cm, cs),
397
- inputs=[current_mode_state, current_session_state],
398
  outputs=[
399
- mode_switch_dialog,
400
- switch_warning_text,
401
- pending_mode_switch_state,
 
402
  current_mode_state,
403
- current_session_state,
404
  status_message
405
  ]
406
  )
407
 
408
  manual_input_btn.click(
409
- lambda cm, cs: switch_to_mode("manual_input", cm, cs),
410
- inputs=[current_mode_state, current_session_state],
411
  outputs=[
412
- mode_switch_dialog,
413
- switch_warning_text,
414
- pending_mode_switch_state,
 
415
  current_mode_state,
416
- current_session_state,
417
  status_message
418
  ]
419
  )
420
 
421
  file_upload_btn.click(
422
- lambda cm, cs: switch_to_mode("file_upload", cm, cs),
423
- inputs=[current_mode_state, current_session_state],
424
  outputs=[
425
- mode_switch_dialog,
426
- switch_warning_text,
427
- pending_mode_switch_state,
 
428
  current_mode_state,
429
- current_session_state,
430
  status_message
431
  ]
432
  )
 
265
  )
266
  else:
267
  # Direct switch (no progress to preserve)
268
+ # Return only the 6 values expected by the button click handler
269
+ result = perform_mode_switch(mode_type, current_session_val)
270
+ # Extract only the values needed for the 6-output handler
271
+ return (
272
+ result[4], # mode_switch_dialog visibility
273
+ result[5], # switch_warning_text
274
+ result[6], # pending_mode_switch_state
275
+ result[7], # current_mode_state
276
+ result[8], # current_session_state
277
+ result[9] # status_message
278
+ )
279
 
280
  except Exception as e:
281
  return (
 
401
  ]
402
  )
403
 
404
+ # Helper function for direct mode switch (no confirmation needed)
405
+ def direct_mode_switch(mode_type: str):
406
+ """Directly switch to a mode without confirmation."""
407
+ mode_selection_visible = False
408
+ enhanced_dataset_visible = mode_type == "enhanced_dataset"
409
+ manual_input_visible = mode_type == "manual_input"
410
+ file_upload_visible = mode_type == "file_upload"
411
+
412
+ mode_title = EnhancedVerificationUIComponents.MODE_OPTIONS.get(mode_type, {}).get('title', 'Unknown')
413
+ status_msg = f"✅ Switched to {mode_title} mode"
414
+
415
+ return (
416
+ gr.Row(visible=mode_selection_visible), # mode_selection_section
417
+ gr.Row(visible=enhanced_dataset_visible), # enhanced_dataset_interface
418
+ gr.Row(visible=manual_input_visible), # manual_input_interface
419
+ gr.Row(visible=file_upload_visible), # file_upload_interface
420
+ mode_type, # current_mode_state
421
+ status_msg # status_message
422
+ )
423
+
424
  # Bind mode selection buttons
425
  enhanced_dataset_btn.click(
426
+ lambda: direct_mode_switch("enhanced_dataset"),
427
+ inputs=[],
428
  outputs=[
429
+ mode_selection_section,
430
+ enhanced_dataset_interface,
431
+ manual_input_interface,
432
+ file_upload_interface,
433
  current_mode_state,
 
434
  status_message
435
  ]
436
  )
437
 
438
  manual_input_btn.click(
439
+ lambda: direct_mode_switch("manual_input"),
440
+ inputs=[],
441
  outputs=[
442
+ mode_selection_section,
443
+ enhanced_dataset_interface,
444
+ manual_input_interface,
445
+ file_upload_interface,
446
  current_mode_state,
 
447
  status_message
448
  ]
449
  )
450
 
451
  file_upload_btn.click(
452
+ lambda: direct_mode_switch("file_upload"),
453
+ inputs=[],
454
  outputs=[
455
+ mode_selection_section,
456
+ enhanced_dataset_interface,
457
+ manual_input_interface,
458
+ file_upload_interface,
459
  current_mode_state,
 
460
  status_message
461
  ]
462
  )