CoolFace
Apppublic

BioinstLab/gmass-demo

sourceHugging Faceapache-2.0updated 2d agoView on Hugging Face
0likes
check_environment.py161 linesDownload Raw Back to scripts
1# scripts/check_environment.py2# G-MASS environment validation script3#4# Run this to verify the project environment is ready for use.5#6# Usage:7#   python scripts/check_environment.py8 9import importlib.util10import os11import shutil12import subprocess13import sys14import sysconfig15 16 17def module_available(module_name):18    try:19        return importlib.util.find_spec(module_name) is not None20    except ModuleNotFoundError:21        return False22 23 24print("\n" + "=" * 60)25print("  G-MASS Project - Environment Setup Check")26print("=" * 60 + "\n")27 28errors = []29 30print("Checking Python version...")31major, minor = sys.version_info.major, sys.version_info.minor32if major == 3 and minor >= 10:33    print(f"  OK Python {major}.{minor}\n")34else:35    print(f"  FAIL Python {major}.{minor} - Need Python 3.10 or higher")36    print("    Download from: python.org\n")37    errors.append("Python version too old")38 39print("Checking installed packages...")40packages = {41    "openai": "pip install -r requirements.txt",42    "google.genai": "pip install -r requirements.txt",43    "huggingface_hub": "pip install -r requirements.txt",44    "requests": "pip install -r requirements.txt",45    "dotenv": "pip install -r requirements.txt",46    "yaml": "pip install -r requirements.txt",47    "numpy": "pip install -r requirements.txt",48    "fasttext": "pip install -r requirements.txt",49    "openpyxl": "pip install -r requirements.txt",50    "pandas": "pip install -r requirements.txt",51    "jsonlines": "pip install -r requirements.txt",52}53 54for pkg, install_cmd in packages.items():55    if module_available(pkg):56        print(f"  OK {pkg}")57    else:58        print(f"  FAIL {pkg} - Run: {install_cmd}")59        errors.append(f"Missing package: {pkg}")60 61print()62 63print("Checking installed G-MASS CLI...")64scripts_dir = sysconfig.get_path("scripts")65gmass_exe = "gmass.exe" if os.name == "nt" else "gmass"66gmass_script = os.path.join(scripts_dir, gmass_exe) if scripts_dir else ""67gmass_cmd = (gmass_script if gmass_script and os.path.exists(gmass_script) else None) or shutil.which("gmass")68if gmass_cmd:69    result = subprocess.run(70        [gmass_cmd, "--help"],71        stdout=subprocess.DEVNULL,72        stderr=subprocess.PIPE,73        text=True,74        timeout=15,75    )76    if result.returncode == 0:77        print("  OK gmass CLI found")78    else:79        print("  WARN gmass CLI file found, but its launcher did not run")80        print("    Fallback: python -m run_bilingual_eval --help")81        print("    If this virtualenv was copied or moved, recreate it and rerun setup.sh.")82else:83    print("  FAIL gmass CLI not found - Run: python -m pip install -e .")84    errors.append("gmass CLI missing")85print()86 87print("Checking .env file...")88if not os.path.exists(".env"):89    print("  FAIL .env file not found in current directory")90    if os.path.exists(".env.example"):91        print("    Run setup.sh to generate a local .env from .env.example, then fill in your API keys.\n")92    else:93        print("    Create .env from your own environment or add .env.example to the repo.\n")94    errors.append(".env file missing")95else:96    if module_available("dotenv"):97        from dotenv import load_dotenv98 99        load_dotenv()100    else:101        print("  FAIL python-dotenv is not installed")102        errors.append("Missing package: dotenv")103 104    keys = {105        "HF_TOKEN": "huggingface.co -> Settings -> Access Tokens",106        "OPENAI_API_KEY": "platform.openai.com/api-keys",107        "GEMINI_API_KEY": "aistudio.google.com -> Get API Key",108    }109 110    for key, source in keys.items():111        value = os.getenv(key)112        if not value or "your_" in value.lower() or value.strip() == "" or value.lower() in {"changeme", "replace-me"}:113            print(f"  FAIL {key} - not set or is a placeholder")114            print(f"    Get it from: {source}")115            errors.append(f"Missing key: {key}")116        else:117            print(f"  OK {key} is set")118 119    print()120 121    if os.getenv("SCORER_BACKEND", "").lower() == "transformers" or any(122        os.getenv(key, "").lower() == "transformers"123        for key in ("PHI3_BACKEND", "BIOMISTRAL_BACKEND", "LOCAL_MODEL_BACKEND")124    ):125        print("Checking local Transformers packages...")126        local_packages = {127            "torch": "pip install -r requirements-local.txt",128            "transformers": "pip install -r requirements-local.txt",129            "accelerate": "pip install -r requirements-local.txt",130            "safetensors": "pip install -r requirements-local.txt",131            "sentencepiece": "pip install -r requirements-local.txt",132        }133        for pkg, install_cmd in local_packages.items():134            if module_available(pkg):135                print(f"  OK {pkg}")136            else:137                print(f"  FAIL {pkg} - Run: {install_cmd}")138                errors.append(f"Missing local package: {pkg}")139        print()140 141print("Checking folder structure...")142folders = ["models", "scorer", "probes", "outputs", "tests", "configs"]143for folder in folders:144    if os.path.isdir(folder):145        print(f"  OK {folder}/")146    else:147        os.makedirs(folder, exist_ok=True)148        print(f"  OK {folder}/ - created")149 150print()151 152print("=" * 60)153if not errors:154    print("  Environment ready. Run: gmass --help")155else:156    print(f"  {len(errors)} issue(s) to fix before running tests:\n")157    for i, err in enumerate(errors, 1):158        print(f"    {i}. {err}")159    print("\n  Fix these, then run: python scripts/check_environment.py again")160print("=" * 60 + "\n")161