Spaces:
Sleeping
Sleeping
Fix: a public model repo needs no token -- is_available/download no longer hide BarScript when no HF_TOKEN secret is set
Browse files- softchart/sc2_loader.py +22 -3
softchart/sc2_loader.py
CHANGED
|
@@ -298,9 +298,12 @@ def download_from_hub(repo_id=None, revision=None, token=None):
|
|
| 298 |
"""
|
| 299 |
repo_id = repo_id or hub_repo_id()
|
| 300 |
revision = revision or os.environ.get("SC2_REPO_REVISION") or None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
resolved = resolve_token(token)
|
| 302 |
-
if resolved is None:
|
| 303 |
-
raise _no_token_error(repo_id)
|
| 304 |
try:
|
| 305 |
from huggingface_hub import snapshot_download
|
| 306 |
except ImportError as exc:
|
|
@@ -312,6 +315,14 @@ def download_from_hub(repo_id=None, revision=None, token=None):
|
|
| 312 |
revision=revision, token=resolved,
|
| 313 |
allow_patterns=list(PACKAGE_FILES))
|
| 314 |
except Exception as exc: # noqa: BLE001 -- re-raised as PackageError
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
raise _hub_download_error(repo_id, exc) from exc
|
| 316 |
missing = [n for n in REQUIRED_FILES
|
| 317 |
if not os.path.isfile(os.path.join(path, n))]
|
|
@@ -1045,7 +1056,15 @@ def is_available(package_dir=None):
|
|
| 1045 |
return True
|
| 1046 |
offline = os.environ.get("HF_HUB_OFFLINE", "").strip().lower() \
|
| 1047 |
in ("1", "true", "yes")
|
| 1048 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1049 |
|
| 1050 |
|
| 1051 |
__all__ = ["SoftChart2", "SlotExportError", "PackageError", "load",
|
|
|
|
| 298 |
"""
|
| 299 |
repo_id = repo_id or hub_repo_id()
|
| 300 |
revision = revision or os.environ.get("SC2_REPO_REVISION") or None
|
| 301 |
+
# The repo is PUBLIC, so a token is optional. Refusing before the request
|
| 302 |
+
# (as this did while it was private) turns "no credential configured" into
|
| 303 |
+
# "model unavailable" on every deployment without a secret. Try the
|
| 304 |
+
# download; _no_token_error is raised only if the Hub actually refuses,
|
| 305 |
+
# which is when the credential really is the problem.
|
| 306 |
resolved = resolve_token(token)
|
|
|
|
|
|
|
| 307 |
try:
|
| 308 |
from huggingface_hub import snapshot_download
|
| 309 |
except ImportError as exc:
|
|
|
|
| 315 |
revision=revision, token=resolved,
|
| 316 |
allow_patterns=list(PACKAGE_FILES))
|
| 317 |
except Exception as exc: # noqa: BLE001 -- re-raised as PackageError
|
| 318 |
+
# 401/403/404 with no credential in hand: the repo is private (or was
|
| 319 |
+
# made private again) and this IS a credentials problem -- say so with
|
| 320 |
+
# the actionable message instead of a bare transport error.
|
| 321 |
+
denied = any(t in f"{type(exc).__name__} {exc}"
|
| 322 |
+
for t in ("401", "403", "404", "RepositoryNotFound",
|
| 323 |
+
"GatedRepo", "Unauthorized"))
|
| 324 |
+
if denied and resolved is None:
|
| 325 |
+
raise _no_token_error(repo_id) from exc
|
| 326 |
raise _hub_download_error(repo_id, exc) from exc
|
| 327 |
missing = [n for n in REQUIRED_FILES
|
| 328 |
if not os.path.isfile(os.path.join(path, n))]
|
|
|
|
| 1056 |
return True
|
| 1057 |
offline = os.environ.get("HF_HUB_OFFLINE", "").strip().lower() \
|
| 1058 |
in ("1", "true", "yes")
|
| 1059 |
+
if offline:
|
| 1060 |
+
return False
|
| 1061 |
+
# A PUBLIC repo needs no token. Requiring one here (as this did while the
|
| 1062 |
+
# repo was private) silently drops the entry from the model list on any
|
| 1063 |
+
# deployment without a secret -- which is exactly the failure mode this
|
| 1064 |
+
# function's docstring says to avoid. Offer it whenever the Hub is
|
| 1065 |
+
# reachable at all; download_from_hub still raises a named error if the
|
| 1066 |
+
# repo turns out to be private and no credential is present.
|
| 1067 |
+
return True
|
| 1068 |
|
| 1069 |
|
| 1070 |
__all__ = ["SoftChart2", "SlotExportError", "PackageError", "load",
|