Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """ | |
| CLI Runner for DReamMachine | |
| Quick command-line interface for running dream rounds | |
| """ | |
| import os | |
| import argparse | |
| import logging | |
| from orchestrator import DreamOrchestrator | |
| # Configure logging | |
| logging.basicConfig( | |
| level=logging.INFO, | |
| format='%(asctime)s - %(levelname)s - %(message)s' | |
| ) | |
| def main(): | |
| parser = argparse.ArgumentParser( | |
| description='DReamMachine - LLM Brainstorm System CLI', | |
| formatter_class=argparse.RawDescriptionHelpFormatter, | |
| epilog=""" | |
| Examples: | |
| # Run a single dream round | |
| python run_cli.py --single | |
| # Run with specific life stage | |
| python run_cli.py --single --stage mid_26_50 | |
| # Run batch mode with 5 rounds | |
| python run_cli.py --batch 5 | |
| # Run batch with custom interval | |
| python run_cli.py --batch 10 --interval 60 | |
| # Run scheduled mode (until max runtime) | |
| python run_cli.py --scheduled | |
| """ | |
| ) | |
| parser.add_argument( | |
| '--single', | |
| action='store_true', | |
| help='Run a single dream round' | |
| ) | |
| parser.add_argument( | |
| '--batch', | |
| type=int, | |
| metavar='N', | |
| help='Run N dream rounds in batch mode' | |
| ) | |
| parser.add_argument( | |
| '--scheduled', | |
| action='store_true', | |
| help='Run in scheduled mode (continuous until max runtime)' | |
| ) | |
| parser.add_argument( | |
| '--stage', | |
| choices=['init_1_25', 'mid_26_50', 'late_51_75', 'final_76_100'], | |
| default='init_1_25', | |
| help='Life stage to run (default: init_1_25)' | |
| ) | |
| parser.add_argument( | |
| '--interval', | |
| type=int, | |
| default=10, | |
| metavar='SECONDS', | |
| help='Seconds to sleep between batch rounds (default: 10)' | |
| ) | |
| parser.add_argument( | |
| '--config', | |
| default='config.yaml', | |
| help='Path to configuration file (default: config.yaml)' | |
| ) | |
| parser.add_argument( | |
| '--token', | |
| help='HuggingFace API token (overrides HF_TOKEN env var)' | |
| ) | |
| args = parser.parse_args() | |
| # Get HuggingFace token | |
| hf_token = args.token or os.getenv('HF_TOKEN') | |
| if not hf_token: | |
| print("Error: HuggingFace token required. Set HF_TOKEN environment variable or use --token") | |
| return 1 | |
| # Initialize orchestrator | |
| print(f"Initializing DReamMachine with config: {args.config}") | |
| orchestrator = DreamOrchestrator(config_path=args.config, hf_token=hf_token) | |
| # Run based on mode | |
| if args.single: | |
| print(f"\nRunning single dream round (stage: {args.stage})") | |
| result = orchestrator.run_dream_round(stage=args.stage) | |
| print("\n" + "=" * 80) | |
| print("RESULTS") | |
| print("=" * 80) | |
| print(f"Session ID: {result.get('session_id')}") | |
| print(f"Originality: {result['curator_scorecard'].get('originality')}/10") | |
| print(f"Feasibility: {result['curator_scorecard'].get('feasibility')}/10") | |
| print(f"Global Impact: {result['curator_scorecard'].get('global_impact')}/10") | |
| print(f"Reforge Flag: {result['curator_scorecard'].get('reforge_flag')}") | |
| print(f"\nNext Action: {result['next_action'].get('type')}") | |
| print(f"Reason: {result['next_action'].get('reason')}") | |
| print("=" * 80) | |
| elif args.batch: | |
| print(f"\nRunning batch mode: {args.batch} rounds (interval: {args.interval}s)") | |
| results = orchestrator.run_batch_mode( | |
| num_rounds=args.batch, | |
| sleep_between=args.interval | |
| ) | |
| print("\n" + "=" * 80) | |
| print("BATCH RESULTS") | |
| print("=" * 80) | |
| print(f"Total rounds: {len(results)}") | |
| reforge_count = sum(1 for r in results if r.get('curator_scorecard', {}).get('reforge_flag')) | |
| print(f"Reforge-eligible: {reforge_count}") | |
| if results: | |
| avg_orig = sum(r.get('curator_scorecard', {}).get('originality', 0) for r in results) / len(results) | |
| avg_feas = sum(r.get('curator_scorecard', {}).get('feasibility', 0) for r in results) / len(results) | |
| print(f"\nAverage Originality: {avg_orig:.1f}/10") | |
| print(f"Average Feasibility: {avg_feas:.1f}/10") | |
| print("=" * 80) | |
| elif args.scheduled: | |
| print("\nRunning in scheduled mode (continuous until max runtime)") | |
| orchestrator.run_scheduled_mode() | |
| else: | |
| parser.print_help() | |
| return 1 | |
| print("\n✓ Complete!") | |
| return 0 | |
| if __name__ == '__main__': | |
| exit(main()) | |