codelion commited on
Commit
1205bb5
·
verified ·
1 Parent(s): c1d7cbf

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -9
app.py CHANGED
@@ -650,15 +650,48 @@ def optimize_prompt(initial_prompt: str, dataset_name: str, dataset_split: str,
650
  os.makedirs(output_dir, exist_ok=True)
651
 
652
  try:
653
- # Run evolution
654
- # Note: OpenEvolve may show "Initialized process parallel controller" warnings
655
- # but they are harmless in this single-worker configuration
656
- result = run_evolution(
657
- initial_program=initial_prompt_path,
658
- evaluator=evaluator_path,
659
- config=config_path,
660
- output_dir=output_dir
661
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
662
 
663
  progress(0.80, desc="Parsing evolution history...")
664
 
 
650
  os.makedirs(output_dir, exist_ok=True)
651
 
652
  try:
653
+ # Monkey-patch to disable process pool in Gradio environment
654
+ # This prevents "signal only works in main thread" errors
655
+ import sys
656
+ import openevolve.controller.parallel_controller as pc_module
657
+
658
+ # Save original class
659
+ OriginalProcessController = pc_module.ProcessParallelController
660
+
661
+ # Create a no-op version that doesn't use multiprocessing
662
+ class NoOpProcessController:
663
+ def __init__(self, *args, **kwargs):
664
+ self.num_workers = 1
665
+ pass
666
+
667
+ def __enter__(self):
668
+ return self
669
+
670
+ def __exit__(self, *args):
671
+ pass
672
+
673
+ def submit(self, func, *args, **kwargs):
674
+ # Execute directly instead of in subprocess
675
+ return func(*args, **kwargs)
676
+
677
+ def map(self, func, *args):
678
+ # Execute directly instead of in subprocess
679
+ return [func(*a) for a in zip(*args)]
680
+
681
+ # Replace the process controller
682
+ pc_module.ProcessParallelController = NoOpProcessController
683
+
684
+ try:
685
+ # Run evolution
686
+ result = run_evolution(
687
+ initial_program=initial_prompt_path,
688
+ evaluator=evaluator_path,
689
+ config=config_path,
690
+ output_dir=output_dir
691
+ )
692
+ finally:
693
+ # Restore original class
694
+ pc_module.ProcessParallelController = OriginalProcessController
695
 
696
  progress(0.80, desc="Parsing evolution history...")
697