Skip to content

Commit

Permalink
Fix uploading to HF proxy (#2120)
Browse files Browse the repository at this point in the history
* Fix uploading to HF proxy

* fix test
  • Loading branch information
Wauplin authored Mar 15, 2024
1 parent 62c5313 commit cdd5289
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/huggingface_hub/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def _as_int(value: Optional[str]) -> Optional[int]:

_staging_mode = _is_true(os.environ.get("HUGGINGFACE_CO_STAGING"))

ENDPOINT = os.getenv("HF_ENDPOINT") or ("https://hub-ci.huggingface.co" if _staging_mode else "https://huggingface.co")
_HF_DEFAULT_ENDPOINT = "https://huggingface.co"
_HF_DEFAULT_STAGING_ENDPOINT = "https://hub-ci.huggingface.co"
ENDPOINT = os.getenv("HF_ENDPOINT") or (_HF_DEFAULT_STAGING_ENDPOINT if _staging_mode else _HF_DEFAULT_ENDPOINT)

HUGGINGFACE_CO_URL_TEMPLATE = ENDPOINT + "/{repo_id}/resolve/{revision}/{filename}"
HUGGINGFACE_HEADER_X_REPO_COMMIT = "X-Repo-Commit"
Expand Down
8 changes: 8 additions & 0 deletions src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
deserialize_event,
)
from .constants import (
_HF_DEFAULT_ENDPOINT,
_HF_DEFAULT_STAGING_ENDPOINT,
DEFAULT_ETAG_TIMEOUT,
DEFAULT_REQUEST_TIMEOUT,
DEFAULT_REVISION,
Expand Down Expand Up @@ -182,6 +184,12 @@ def repo_type_and_id_from_hf_id(hf_id: str, hub_url: Optional[str] = None) -> Tu
If `repo_type` is unknown.
"""
input_hf_id = hf_id

# check if a proxy has been set => if yes, update the returned URL to use the proxy
if ENDPOINT not in (_HF_DEFAULT_ENDPOINT, _HF_DEFAULT_STAGING_ENDPOINT):
hf_id = hf_id.replace(_HF_DEFAULT_ENDPOINT, ENDPOINT)
hf_id = hf_id.replace(_HF_DEFAULT_STAGING_ENDPOINT, ENDPOINT)

hub_url = re.sub(r"https?://", "", hub_url if hub_url is not None else ENDPOINT)
is_hf_url = hub_url in hf_id and "@" not in hf_id

Expand Down

0 comments on commit cdd5289

Please sign in to comment.