Spaces:
Configuration error
Configuration error
Delete model_runtime.py
Browse files- model_runtime.py +0 -54
model_runtime.py
DELETED
|
@@ -1,54 +0,0 @@
|
|
| 1 |
-
from __future__ import annotations
|
| 2 |
-
|
| 3 |
-
import os
|
| 4 |
-
from pathlib import Path
|
| 5 |
-
from typing import Callable
|
| 6 |
-
|
| 7 |
-
from huggingface_hub import snapshot_download
|
| 8 |
-
|
| 9 |
-
TARGET_OMNI_MODEL = os.getenv("PB3D_TARGET_MODEL", "tencent/Hunyuan3D-Omni")
|
| 10 |
-
DEFAULT_CACHE_ROOT = Path(os.getenv("PB3D_MODEL_CACHE", "./models"))
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def get_target_model_dir(model_id: str = TARGET_OMNI_MODEL) -> Path:
|
| 14 |
-
safe = model_id.replace("/", "--")
|
| 15 |
-
return DEFAULT_CACHE_ROOT / safe
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
def ensure_target_model_cached(
|
| 19 |
-
model_id: str = TARGET_OMNI_MODEL,
|
| 20 |
-
progress: Callable[[str], None] | None = None,
|
| 21 |
-
) -> dict:
|
| 22 |
-
"""
|
| 23 |
-
Best-effort local cache of the upstream target model repo.
|
| 24 |
-
|
| 25 |
-
This fetches the model repo into the Space filesystem so later integration work
|
| 26 |
-
can call the upstream inference stack directly. It does not assume internal file
|
| 27 |
-
names beyond the official repo id.
|
| 28 |
-
"""
|
| 29 |
-
target_dir = get_target_model_dir(model_id)
|
| 30 |
-
target_dir.mkdir(parents=True, exist_ok=True)
|
| 31 |
-
|
| 32 |
-
if progress:
|
| 33 |
-
progress(f"Checking local cache for {model_id}…")
|
| 34 |
-
|
| 35 |
-
try:
|
| 36 |
-
local_path = snapshot_download(
|
| 37 |
-
repo_id=model_id,
|
| 38 |
-
local_dir=str(target_dir),
|
| 39 |
-
local_dir_use_symlinks=False,
|
| 40 |
-
resume_download=True,
|
| 41 |
-
)
|
| 42 |
-
return {
|
| 43 |
-
"ok": True,
|
| 44 |
-
"model_id": model_id,
|
| 45 |
-
"local_path": local_path,
|
| 46 |
-
"message": f"Cached {model_id} in {local_path}",
|
| 47 |
-
}
|
| 48 |
-
except Exception as exc: # pragma: no cover
|
| 49 |
-
return {
|
| 50 |
-
"ok": False,
|
| 51 |
-
"model_id": model_id,
|
| 52 |
-
"local_path": str(target_dir),
|
| 53 |
-
"message": f"Could not cache {model_id}: {exc}",
|
| 54 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|