Joey / run.py
Joey Callanan
Creating new Space
43e7ae4
#!/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()