#!/usr/bin/env python3 """ Launch script for Mini SpecsComply Pro. This script sets up and runs the application in one step. """ import os import sys import subprocess import argparse from pathlib import Path def run_command(command, check=True): """Run a shell command.""" print(f"Running: {' '.join(command)}") return subprocess.run(command, check=check) def check_env_file(): """Check if .env file exists and has required keys.""" if not os.path.exists(".env"): print("Error: .env file not found. Running setup...") run_command([sys.executable, "setup.py"]) return False required_keys = [ "COHERE_API_KEY", "GROQ_API_KEY", "PINECONE_API_KEY" ] with open(".env", "r") as f: env_content = f.read() missing_keys = [] for key in required_keys: if f"{key}=" not in env_content or f"{key}=your_{key.lower()}" in env_content: missing_keys.append(key) if missing_keys: print(f"Error: The following API keys are missing or not set in .env: {', '.join(missing_keys)}") print("Please edit the .env file to add your API keys.") return False return True def main(): """Main function.""" parser = argparse.ArgumentParser(description="Launch Mini SpecsComply Pro") parser.add_argument("--host", default="0.0.0.0", help="Host to bind") parser.add_argument("--port", type=int, default=8000, help="Port to bind") parser.add_argument("--debug", action="store_true", help="Enable debug mode") parser.add_argument("--setup", action="store_true", help="Run setup before launching") args = parser.parse_args() # Run setup if requested # Check environment file if not check_env_file(): return 1 # Run the application print(f"Launching Mini SpecsComply Pro on {args.host}:{args.port}...") cmd = [ sys.executable, "run.py", "--host", args.host, "--port", str(args.port) ] if args.debug: cmd.append("--debug") try: run_command(cmd) except KeyboardInterrupt: print("\nApplication stopped by user.") except Exception as e: print(f"Error running application: {str(e)}") return 1 return 0 if __name__ == "__main__": sys.exit(main())