File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change 22import re
33import typing
44from typing import Literal , Optional , Tuple
5+ from urllib .parse import urljoin
56
67
78# Possible values for env variables
@@ -63,9 +64,11 @@ def _as_int(value: Optional[str]) -> Optional[int]:
6364
6465_HF_DEFAULT_ENDPOINT = "https://huggingface.co"
6566_HF_DEFAULT_STAGING_ENDPOINT = "https://hub-ci.huggingface.co"
66- ENDPOINT = os .getenv ("HF_ENDPOINT" ) or (_HF_DEFAULT_STAGING_ENDPOINT if _staging_mode else _HF_DEFAULT_ENDPOINT )
67+ ENDPOINT = os .getenv ("HF_ENDPOINT" , "" ).rstrip ("/" ) or (
68+ _HF_DEFAULT_STAGING_ENDPOINT if _staging_mode else _HF_DEFAULT_ENDPOINT
69+ )
6770
68- HUGGINGFACE_CO_URL_TEMPLATE = ENDPOINT + "/{repo_id}/resolve/{revision}/{filename}"
71+ HUGGINGFACE_CO_URL_TEMPLATE = urljoin ( ENDPOINT , "/{repo_id}/resolve/{revision}/{filename}" )
6972HUGGINGFACE_HEADER_X_REPO_COMMIT = "X-Repo-Commit"
7073HUGGINGFACE_HEADER_X_LINKED_ETAG = "X-Linked-Etag"
7174HUGGINGFACE_HEADER_X_LINKED_SIZE = "X-Linked-Size"
Original file line number Diff line number Diff line change @@ -338,9 +338,9 @@ def fix_hf_endpoint_in_url(url: str, endpoint: Optional[str]) -> str:
338338
339339 This is useful when using a proxy and the Hugging Face Hub returns a URL with the default endpoint.
340340 """
341- endpoint = endpoint or constants .ENDPOINT
341+ endpoint = endpoint . rstrip ( "/" ) if endpoint else constants .ENDPOINT
342342 # check if a proxy has been set => if yes, update the returned URL to use the proxy
343- if endpoint not in (None , constants ._HF_DEFAULT_ENDPOINT , constants ._HF_DEFAULT_STAGING_ENDPOINT ):
343+ if endpoint not in (constants ._HF_DEFAULT_ENDPOINT , constants ._HF_DEFAULT_STAGING_ENDPOINT ):
344344 url = url .replace (constants ._HF_DEFAULT_ENDPOINT , endpoint )
345345 url = url .replace (constants ._HF_DEFAULT_STAGING_ENDPOINT , endpoint )
346346 return url
You can’t perform that action at this time.
0 commit comments