From ff59b435338080fac476b8a73afff8f20ae226db Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Sat, 4 Jul 2026 04:31:09 +0000 Subject: [PATCH] Fail clearly when a local Krea 2 dir lacks model_index.json Falling through to hf_hub_download with a filesystem path as the repo id raised an opaque HFValidationError; a local dir without the file now raises FileNotFoundError naming the directory --- studio/backend/core/inference/diffusion_krea2.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/studio/backend/core/inference/diffusion_krea2.py b/studio/backend/core/inference/diffusion_krea2.py index 4475559cdb..86a1d0413c 100644 --- a/studio/backend/core/inference/diffusion_krea2.py +++ b/studio/backend/core/inference/diffusion_krea2.py @@ -85,12 +85,20 @@ def load_krea2_text_encoder( def _load_model_index(repo_id: str, hf_token: Optional[str] = None) -> dict[str, Any]: """model_index.json as a dict, from a local path or the Hub cache.""" + is_local_dir = False try: - local = Path(repo_id).expanduser() / "model_index.json" + root = Path(repo_id).expanduser() + is_local_dir = root.is_dir() + local = root / "model_index.json" if local.is_file(): return json.loads(local.read_text()) except OSError: pass + if is_local_dir: + # A local checkpoint dir without the file must fail clearly here: falling through + # to hf_hub_download with a filesystem path as the repo id would die with an + # opaque HFValidationError instead. + raise FileNotFoundError(f"model_index.json not found in local model dir {repo_id}") from huggingface_hub import hf_hub_download path = hf_hub_download(repo_id, "model_index.json", token = hf_token or None)