Spaces:
Runtime error
Runtime error
File size: 1,655 Bytes
fc7db98 9ea8d9d fc7db98 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | """
Download exported model from Hugging Face Hub before API startup.
Set Space secret / env:
HF_MODEL_REPO=your-username/deberta-complexity-lcp
MODEL_PATH=/app/model
"""
from __future__ import annotations
import os
import sys
from pathlib import Path
def main() -> None:
repo = os.environ.get("HF_MODEL_REPO", "").strip()
target = Path(os.environ.get("MODEL_PATH", "/home/user/model"))
if not repo:
print("HF_MODEL_REPO not set — expecting model_weights.pt already on disk.")
weights = target / "model_weights.pt"
if weights.exists():
print(f"Found {weights}")
else:
print(f"WARN: no weights at {weights}", file=sys.stderr)
return
weights = target / "model_weights.pt"
if weights.exists():
print(f"Model already present at {weights}")
return
print(f"Downloading {repo} → {target}")
from huggingface_hub import snapshot_download
token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN")
target.mkdir(parents=True, exist_ok=True)
snapshot_download(
repo_id=repo,
local_dir=str(target),
token=token,
allow_patterns=[
"model_weights.pt",
"config.json",
"tokenizer/*",
"*.json",
],
)
if not weights.exists():
raise FileNotFoundError(
f"Download finished but {weights} missing. "
f"Upload model with: python deploy/huggingface/upload_model_to_hub.py"
)
print(f"Ready: {weights} ({weights.stat().st_size / 1e6:.1f} MB)")
if __name__ == "__main__":
main()
|