Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated use_auth_token with token #621

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/hub/push_evaluations_to_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docs/source/base_evaluator.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 13 additions & 12 deletions src/evaluate/utils/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Loading