"""Utility for finding OpenFace weight files""" import os from pathlib import Path from glob import glob def find_weight(filename: str) -> str: """Find weight file in various possible locations""" # Check environment variable env_dir = os.environ.get("OPENFACE_WEIGHT_DIR") if env_dir: p = Path(env_dir) / filename if p.is_file(): return str(p) # Check package installation try: import openface as _of site_w = Path(_of.__path__[0]) / "weights" / filename if site_w.is_file(): return str(site_w) except: pass # Check HuggingFace cache user_home = Path(os.environ.get("USERPROFILE", str(Path.home()))) hf_root = user_home / ".cache" / "huggingface" / "hub" if hf_root.exists(): hits = glob(str(hf_root / "**" / filename), recursive=True) if hits: return hits[0] # Check local weights directory local = Path("weights") / filename if local.is_file(): return str(local) raise FileNotFoundError(f"Weight not found: {filename}")