The code in
ignores the
HF_ENDPOINT environment variable (e.g.,
HF_ENDPOINT=https://hf-mirror.com).
This breaks usage in regions where direct access to huggingface.co is unavailable, even when a valid mirror is configured.
✅ Fix suggestion:
Use the official huggingface_hub API to get the effective endpoint:
from huggingface_hub import HfApi
hf_endpoint = HfApi().endpoint.rstrip("/")
model_id_url = f"{hf_endpoint}/{model_id}"