#!/usr/bin/env python3 """ HITL Drug Discovery Application Launcher This script launches the modular drug discovery application. It handles virtual environment activation and provides clear feedback. """ import sys import os import subprocess from pathlib import Path def check_virtual_env(): """Check if we're in a virtual environment.""" return hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix) def activate_venv_and_run(): """Activate virtual environment and run the application.""" project_dir = Path(__file__).parent venv_path = project_dir / "venv" if not venv_path.exists(): print("āŒ Virtual environment not found!") print("Please run: python -m venv venv") print("Then: source venv/bin/activate") print("Finally: pip install -r requirements.txt") return False # Try to run with virtual environment try: if os.name == 'nt': # Windows activate_script = venv_path / "Scripts" / "activate.bat" python_exe = venv_path / "Scripts" / "python.exe" else: # Unix/Linux/macOS activate_script = venv_path / "bin" / "activate" python_exe = venv_path / "bin" / "python" if python_exe.exists(): print("šŸš€ Starting HITL Drug Discovery (Modular Version)...") print("šŸ“ Using virtual environment:", venv_path) print("🌐 Application will be available at: http://localhost:7860") print("ā¹ļø Press Ctrl+C to stop the application") print("-" * 60) # Run the application subprocess.run([str(python_exe), "app.py"], cwd=project_dir) return True else: print("āŒ Python executable not found in virtual environment!") return False except Exception as e: print(f"āŒ Error running application: {e}") return False def main(): """Main launcher function.""" print("🧬 HITL Drug Discovery Application Launcher") print("=" * 50) if check_virtual_env(): print("āœ… Virtual environment detected") print("šŸš€ Starting application...") try: import app print("🌐 Application available at: http://localhost:7860") print("ā¹ļø Press Ctrl+C to stop") except ImportError as e: print(f"āŒ Import error: {e}") print("šŸ’” Try running: pip install -r requirements.txt") except Exception as e: print(f"āŒ Error: {e}") else: print("āš ļø No virtual environment detected") print("šŸ”„ Attempting to activate virtual environment...") if not activate_venv_and_run(): print("\nšŸ’” Manual setup required:") print("1. python -m venv venv") print("2. source venv/bin/activate # (or venv\\Scripts\\activate on Windows)") print("3. pip install -r requirements.txt") print("4. python app.py") if __name__ == "__main__": main()