"""Locate Bhed weight files on disk or on the Hub.""" from pathlib import Path _ROOT = Path(__file__).resolve().parent.parent _WEIGHT_MARKERS = ("adapter_model.safetensors", "model.safetensors") def _looks_like_model_dir(path: Path) -> bool: if not path.is_dir(): return False has_weights = any((path / name).is_file() for name in _WEIGHT_MARKERS) has_tokenizer = (path / "tokenizer.json").is_file() or (path / "tokenizer_config.json").is_file() return has_weights and has_tokenizer def model_dir() -> Path: """Directory that holds the Bhed weight files.""" for candidate in (_ROOT, Path(__file__).resolve().parent): if _looks_like_model_dir(candidate): return candidate raise FileNotFoundError( "Bhed model files were not found next to the package. " "Install from the model directory with: pip install -e ." ) def resolve_source(source=None) -> str: """Local model directory, or a Hugging Face repo id such as ``MindMapDigital/Bhed-v0.1``.""" if source is None: return str(model_dir()) source = str(source) path = Path(source) if _looks_like_model_dir(path): return str(path.resolve()) return source