File size: 3,371 Bytes
404d784
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python3
"""

Launcher script for ColiFormer Streamlit GUI



This script sets up the environment and launches the Streamlit application.

"""

import os
import sys
import subprocess
from pathlib import Path

def main():
    """Launch the Streamlit GUI application"""

    # Get the directory containing this script
    script_dir = Path(__file__).parent

    # Add the parent directory to Python path so we can import CodonTransformer
    parent_dir = script_dir.parent
    sys.path.insert(0, str(parent_dir))

    # Set working directory to parent directory so model paths work correctly
    os.chdir(parent_dir)

    print("Starting ENCOT GUI...")
    print(f"   Working directory: {parent_dir}")
    print(f"   Python path includes: {parent_dir}")

    # Check for model checkpoint
    model_path = parent_dir / "models" / "alm-enhanced-training" / "balanced_alm_finetune.ckpt"
    if model_path.exists():
        print(f"Found fine-tuned model: {model_path}")
    else:
        print("Fine-tuned model not found, will use base model")

    # Check for virtual environment
    venv_path = parent_dir / "codon_env"
    if venv_path.exists():
        # Set up virtual environment paths
        venv_bin = venv_path / "bin"
        venv_python = venv_bin / "python"

        if venv_python.exists():
            print(f"Found virtual environment: {venv_path}")
            # Update PATH to include virtual environment
            current_path = os.environ.get("PATH", "")
            os.environ["PATH"] = f"{venv_bin}:{current_path}"
            # Use virtual environment Python
            python_executable = str(venv_python)
        else:
            print("Virtual environment found but Python executable missing")
            python_executable = sys.executable
    else:
        print("No virtual environment found, using system Python")
        python_executable = sys.executable

    print(f"   Using Python: {python_executable}")
    print()

    # Check if streamlit is installed
    try:
        import streamlit
        print(f"Streamlit version: {streamlit.__version__}")
    except ImportError:
        print("Streamlit not found. Please install requirements:")
        print("   pip install -r requirements.txt")
        return 1

    # Check if torch is available
    try:
        import torch
        device = "GPU" if torch.cuda.is_available() else "CPU"
        print(f"PyTorch available, using: {device}")
    except ImportError:
        print("PyTorch not found. Please install requirements:")
        print("   pip install -r requirements.txt")
        return 1

    print()
    print("Launching GUI...")
    print("   The application will open in your default web browser")
    print("   Press Ctrl+C to stop the server")
    print()

    # Launch streamlit
    try:
        subprocess.run([
            python_executable, "-m", "streamlit", "run", "streamlit_gui/app.py",
            "--server.headless", "false",
            "--server.port", "8501",
            "--server.address", "0.0.0.0"
        ])
    except KeyboardInterrupt:
        print("\nShutting down ENCOT GUI...")
        return 0
    except Exception as e:
        print(f"Error launching Streamlit: {e}")
        return 1

if __name__ == "__main__":
    exit(main())