diff --git a/.github/hub/push_evaluations_to_hub.py b/.github/hub/push_evaluations_to_hub.py index 73bde44ce..866afb3ce 100644 --- a/.github/hub/push_evaluations_to_hub.py +++ b/.github/hub/push_evaluations_to_hub.py @@ -75,7 +75,7 @@ def push_module_to_hub(module_path, type, token, commit_hash, tag=None): # make sure we don't accidentally expose token raise OSError(f"Could not clone from '{clean_repo_url}'") - repo = Repository(local_dir=repo_path / module_name, use_auth_token=token) + repo = Repository(local_dir=repo_path / module_name, token=token) copy_recursive(module_path, repo_path / module_name) update_evaluate_dependency(repo_path / module_name / "requirements.txt", commit_hash) diff --git a/docs/source/base_evaluator.mdx b/docs/source/base_evaluator.mdx index 043c82518..921fb9366 100644 --- a/docs/source/base_evaluator.mdx +++ b/docs/source/base_evaluator.mdx @@ -275,7 +275,7 @@ Let's have a look at how can evaluate image classification models on large datas The evaluator can be used on large datasets! Below, an example shows how to use it on ImageNet-1k for image classification. Beware that this example will require to download ~150 GB. ```python -data = load_dataset("imagenet-1k", split="validation", use_auth_token=True) +data = load_dataset("imagenet-1k", split="validation", token=True) pipe = pipeline( task="image-classification", diff --git a/src/evaluate/utils/file_utils.py b/src/evaluate/utils/file_utils.py index c52d44a95..f021ef4fa 100644 --- a/src/evaluate/utils/file_utils.py +++ b/src/evaluate/utils/file_utils.py @@ -182,7 +182,7 @@ def cached_path( local_files_only=download_config.local_files_only, use_etag=download_config.use_etag, max_retries=download_config.max_retries, - use_auth_token=download_config.use_auth_token, + token=download_config.token, ignore_url_params=download_config.ignore_url_params, download_desc=download_config.download_desc, ) @@ -223,14 +223,15 @@ def get_datasets_user_agent(user_agent: Optional[Union[str, dict]] = None) -> st return ua -def get_authentication_headers_for_url(url: str, use_auth_token: Optional[Union[str, bool]] = None) -> dict: +def get_authentication_headers_for_url(url: str, token: Optional[Union[str, bool]] = None) -> dict: """Handle the HF authentication""" headers = {} if url.startswith(config.HF_ENDPOINT): - token = None - if isinstance(use_auth_token, str): - token = use_auth_token - elif bool(use_auth_token): + if token is False: + token = None + elif isinstance(token, str): + token = token + else: from huggingface_hub import hf_api token = hf_api.HfFolder.get_token() @@ -388,8 +389,8 @@ def http_head( return response -def request_etag(url: str, use_auth_token: Optional[Union[str, bool]] = None) -> Optional[str]: - headers = get_authentication_headers_for_url(url, use_auth_token=use_auth_token) +def request_etag(url: str, token: Optional[Union[str, bool]] = None) -> Optional[str]: + headers = get_authentication_headers_for_url(url, token=token) response = http_head(url, headers=headers, max_retries=3) response.raise_for_status() etag = response.headers.get("ETag") if response.ok else None @@ -407,7 +408,7 @@ def get_from_cache( local_files_only=False, use_etag=True, max_retries=0, - use_auth_token=None, + token=None, ignore_url_params=False, download_desc=None, ) -> str: @@ -452,7 +453,7 @@ def get_from_cache( return cache_path # Prepare headers for authentication - headers = get_authentication_headers_for_url(url, use_auth_token=use_auth_token) + headers = get_authentication_headers_for_url(url, token=token) if user_agent is not None: headers["user-agent"] = user_agent @@ -495,9 +496,9 @@ def get_from_cache( ): connected = True logger.info(f"Couldn't get ETag version for url {url}") - elif response.status_code == 401 and config.HF_ENDPOINT in url and use_auth_token is None: + elif response.status_code == 401 and config.HF_ENDPOINT in url and token is None: raise ConnectionError( - f"Unauthorized for URL {url}. Please use the parameter ``use_auth_token=True`` after logging in with ``huggingface-cli login``" + f"Unauthorized for URL {url}. Please use the parameter ``token=True`` after logging in with ``huggingface-cli login``" ) except (OSError, requests.exceptions.Timeout) as e: # not connected