huggingface-hub 0.20.1__tar.gz → 0.20.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of huggingface-hub might be problematic. Click here for more details.
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/PKG-INFO +1 -1
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/__init__.py +1 -1
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_hf_folder.py +4 -23
- huggingface_hub-0.20.3/src/huggingface_hub/utils/_token.py +129 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub.egg-info/PKG-INFO +1 -1
- huggingface_hub-0.20.1/src/huggingface_hub/utils/_token.py +0 -112
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/LICENSE +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/MANIFEST.in +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/README.md +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/pyproject.toml +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/setup.cfg +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/setup.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/_commit_api.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/_commit_scheduler.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/_inference_endpoints.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/_login.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/_multi_commits.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/_snapshot_download.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/_space_api.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/_tensorboard_logger.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/_webhooks_payload.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/_webhooks_server.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/commands/__init__.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/commands/_cli_utils.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/commands/delete_cache.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/commands/download.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/commands/env.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/commands/huggingface_cli.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/commands/lfs.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/commands/scan_cache.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/commands/upload.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/commands/user.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/community.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/constants.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/fastai_utils.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/file_download.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/hf_api.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/hf_file_system.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/hub_mixin.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/inference/__init__.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/inference/_client.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/inference/_common.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/inference/_generated/__init__.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/inference/_generated/_async_client.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/inference/_text_generation.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/inference/_types.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/inference_api.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/keras_mixin.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/lfs.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/repocard.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/repocard_data.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/repository.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/templates/datasetcard_template.md +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/templates/modelcard_template.md +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/__init__.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_cache_assets.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_cache_manager.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_chunk_utils.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_datetime.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_deprecation.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_errors.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_experimental.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_fixes.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_git_credential.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_headers.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_http.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_pagination.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_paths.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_runtime.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_safetensors.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_subprocess.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_telemetry.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_typing.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_validators.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/endpoint_helpers.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/insecure_hashlib.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/logging.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/sha.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/tqdm.py +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub.egg-info/SOURCES.txt +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub.egg-info/dependency_links.txt +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub.egg-info/entry_points.txt +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub.egg-info/requires.txt +0 -0
- {huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: huggingface_hub
|
|
3
|
-
Version: 0.20.
|
|
3
|
+
Version: 0.20.3
|
|
4
4
|
Summary: Client library to download and publish models, datasets and other repos on the huggingface.co hub
|
|
5
5
|
Home-page: https://github.com/huggingface/huggingface_hub
|
|
6
6
|
Author: Hugging Face, Inc.
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
# See the License for the specific language governing permissions and
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
"""Contain helper class to retrieve/store token from/to local cache."""
|
|
16
|
-
import os
|
|
17
16
|
import warnings
|
|
18
17
|
from pathlib import Path
|
|
19
18
|
from typing import Optional
|
|
20
19
|
|
|
21
20
|
from .. import constants
|
|
21
|
+
from ._token import get_token
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
class HfFolder:
|
|
@@ -50,12 +50,8 @@ class HfFolder:
|
|
|
50
50
|
"""
|
|
51
51
|
Get token or None if not existent.
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
Token is saved in the huggingface home folder. You can configure it by setting
|
|
56
|
-
the `HF_HOME` environment variable. Previous location was `~/.huggingface/token`.
|
|
57
|
-
If token is found in old location but not in new location, it is copied there first.
|
|
58
|
-
For more details, see https://github.com/huggingface/huggingface_hub/issues/1232.
|
|
53
|
+
This method is deprecated in favor of [`huggingface_hub.get_token`] but is kept for backward compatibility.
|
|
54
|
+
Its behavior is the same as [`huggingface_hub.get_token`].
|
|
59
55
|
|
|
60
56
|
Returns:
|
|
61
57
|
`str` or `None`: The token, `None` if it doesn't exist.
|
|
@@ -66,22 +62,7 @@ class HfFolder:
|
|
|
66
62
|
except Exception: # if not possible (e.g. PermissionError), do not raise
|
|
67
63
|
pass
|
|
68
64
|
|
|
69
|
-
|
|
70
|
-
token: Optional[str] = os.environ.get("HF_TOKEN")
|
|
71
|
-
if token is None: # Ensure backward compatibility but doesn't have priority
|
|
72
|
-
token = os.environ.get("HUGGING_FACE_HUB_TOKEN")
|
|
73
|
-
if token is not None:
|
|
74
|
-
token = token.replace("\r", "").replace("\n", "").strip()
|
|
75
|
-
if token != "":
|
|
76
|
-
return token
|
|
77
|
-
|
|
78
|
-
# 2. Is it set in token path ?
|
|
79
|
-
try:
|
|
80
|
-
token = cls.path_token.read_text()
|
|
81
|
-
token = token.replace("\r", "").replace("\n", "").strip()
|
|
82
|
-
return token
|
|
83
|
-
except FileNotFoundError:
|
|
84
|
-
return None
|
|
65
|
+
return get_token()
|
|
85
66
|
|
|
86
67
|
# TODO: deprecate when adapted in transformers/datasets/gradio
|
|
87
68
|
# @_deprecate_method(version="1.0", message="Use `huggingface_hub.logout` instead.")
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Copyright 2023 The HuggingFace Team. All rights reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
"""Contains an helper to get the token from machine (env variable, secret or config file)."""
|
|
15
|
+
import os
|
|
16
|
+
import warnings
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from threading import Lock
|
|
19
|
+
from typing import Optional
|
|
20
|
+
|
|
21
|
+
from .. import constants
|
|
22
|
+
from ._runtime import is_google_colab
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
_IS_GOOGLE_COLAB_CHECKED = False
|
|
26
|
+
_GOOGLE_COLAB_SECRET_LOCK = Lock()
|
|
27
|
+
_GOOGLE_COLAB_SECRET: Optional[str] = None
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def get_token() -> Optional[str]:
|
|
31
|
+
"""
|
|
32
|
+
Get token if user is logged in.
|
|
33
|
+
|
|
34
|
+
Note: in most cases, you should use [`huggingface_hub.utils.build_hf_headers`] instead. This method is only useful
|
|
35
|
+
if you want to retrieve the token for other purposes than sending an HTTP request.
|
|
36
|
+
|
|
37
|
+
Token is retrieved in priority from the `HF_TOKEN` environment variable. Otherwise, we read the token file located
|
|
38
|
+
in the Hugging Face home folder. Returns None if user is not logged in. To log in, use [`login`] or
|
|
39
|
+
`huggingface-cli login`.
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
`str` or `None`: The token, `None` if it doesn't exist.
|
|
43
|
+
"""
|
|
44
|
+
return _get_token_from_google_colab() or _get_token_from_environment() or _get_token_from_file()
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _get_token_from_google_colab() -> Optional[str]:
|
|
48
|
+
"""Get token from Google Colab secrets vault using `google.colab.userdata.get(...)`.
|
|
49
|
+
|
|
50
|
+
Token is read from the vault only once per session and then stored in a global variable to avoid re-requesting
|
|
51
|
+
access to the vault.
|
|
52
|
+
"""
|
|
53
|
+
if not is_google_colab():
|
|
54
|
+
return None
|
|
55
|
+
|
|
56
|
+
# `google.colab.userdata` is not thread-safe
|
|
57
|
+
# This can lead to a deadlock if multiple threads try to access it at the same time
|
|
58
|
+
# (typically when using `snapshot_download`)
|
|
59
|
+
# => use a lock
|
|
60
|
+
# See https://github.com/huggingface/huggingface_hub/issues/1952 for more details.
|
|
61
|
+
with _GOOGLE_COLAB_SECRET_LOCK:
|
|
62
|
+
global _GOOGLE_COLAB_SECRET
|
|
63
|
+
global _IS_GOOGLE_COLAB_CHECKED
|
|
64
|
+
|
|
65
|
+
if _IS_GOOGLE_COLAB_CHECKED: # request access only once
|
|
66
|
+
return _GOOGLE_COLAB_SECRET
|
|
67
|
+
|
|
68
|
+
try:
|
|
69
|
+
from google.colab import userdata
|
|
70
|
+
from google.colab.errors import Error as ColabError
|
|
71
|
+
except ImportError:
|
|
72
|
+
return None
|
|
73
|
+
|
|
74
|
+
try:
|
|
75
|
+
token = userdata.get("HF_TOKEN")
|
|
76
|
+
_GOOGLE_COLAB_SECRET = _clean_token(token)
|
|
77
|
+
except userdata.NotebookAccessError:
|
|
78
|
+
# Means the user has a secret call `HF_TOKEN` and got a popup "please grand access to HF_TOKEN" and refused it
|
|
79
|
+
# => warn user but ignore error => do not re-request access to user
|
|
80
|
+
warnings.warn(
|
|
81
|
+
"\nAccess to the secret `HF_TOKEN` has not been granted on this notebook."
|
|
82
|
+
"\nYou will not be requested again."
|
|
83
|
+
"\nPlease restart the session if you want to be prompted again."
|
|
84
|
+
)
|
|
85
|
+
_GOOGLE_COLAB_SECRET = None
|
|
86
|
+
except userdata.SecretNotFoundError:
|
|
87
|
+
# Means the user did not define a `HF_TOKEN` secret => warn
|
|
88
|
+
warnings.warn(
|
|
89
|
+
"\nThe secret `HF_TOKEN` does not exist in your Colab secrets."
|
|
90
|
+
"\nTo authenticate with the Hugging Face Hub, create a token in your settings tab "
|
|
91
|
+
"(https://huggingface.co/settings/tokens), set it as secret in your Google Colab and restart your session."
|
|
92
|
+
"\nYou will be able to reuse this secret in all of your notebooks."
|
|
93
|
+
"\nPlease note that authentication is recommended but still optional to access public models or datasets."
|
|
94
|
+
)
|
|
95
|
+
_GOOGLE_COLAB_SECRET = None
|
|
96
|
+
except ColabError as e:
|
|
97
|
+
# Something happen but we don't know what => recommend to open a GitHub issue
|
|
98
|
+
warnings.warn(
|
|
99
|
+
f"\nError while fetching `HF_TOKEN` secret value from your vault: '{str(e)}'."
|
|
100
|
+
"\nYou are not authenticated with the Hugging Face Hub in this notebook."
|
|
101
|
+
"\nIf the error persists, please let us know by opening an issue on GitHub "
|
|
102
|
+
"(https://github.com/huggingface/huggingface_hub/issues/new)."
|
|
103
|
+
)
|
|
104
|
+
_GOOGLE_COLAB_SECRET = None
|
|
105
|
+
|
|
106
|
+
_IS_GOOGLE_COLAB_CHECKED = True
|
|
107
|
+
return _GOOGLE_COLAB_SECRET
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _get_token_from_environment() -> Optional[str]:
|
|
111
|
+
# `HF_TOKEN` has priority (keep `HUGGING_FACE_HUB_TOKEN` for backward compatibility)
|
|
112
|
+
return _clean_token(os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN"))
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _get_token_from_file() -> Optional[str]:
|
|
116
|
+
try:
|
|
117
|
+
return _clean_token(Path(constants.HF_TOKEN_PATH).read_text())
|
|
118
|
+
except FileNotFoundError:
|
|
119
|
+
return None
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _clean_token(token: Optional[str]) -> Optional[str]:
|
|
123
|
+
"""Clean token by removing trailing and leading spaces and newlines.
|
|
124
|
+
|
|
125
|
+
If token is an empty string, return None.
|
|
126
|
+
"""
|
|
127
|
+
if token is None:
|
|
128
|
+
return None
|
|
129
|
+
return token.replace("\r", "").replace("\n", "").strip() or None
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: huggingface-hub
|
|
3
|
-
Version: 0.20.
|
|
3
|
+
Version: 0.20.3
|
|
4
4
|
Summary: Client library to download and publish models, datasets and other repos on the huggingface.co hub
|
|
5
5
|
Home-page: https://github.com/huggingface/huggingface_hub
|
|
6
6
|
Author: Hugging Face, Inc.
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
# Copyright 2023 The HuggingFace Team. All rights reserved.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
"""Contains an helper to get the token from machine (env variable, secret or config file)."""
|
|
15
|
-
import os
|
|
16
|
-
import warnings
|
|
17
|
-
from pathlib import Path
|
|
18
|
-
from typing import Optional
|
|
19
|
-
|
|
20
|
-
from .. import constants
|
|
21
|
-
from ._runtime import is_google_colab
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
_CHECK_GOOGLE_COLAB_SECRET = True
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def get_token() -> Optional[str]:
|
|
28
|
-
"""
|
|
29
|
-
Get token if user is logged in.
|
|
30
|
-
|
|
31
|
-
Note: in most cases, you should use [`huggingface_hub.utils.build_hf_headers`] instead. This method is only useful
|
|
32
|
-
if you want to retrieve the token for other purposes than sending an HTTP request.
|
|
33
|
-
|
|
34
|
-
Token is retrieved in priority from the `HF_TOKEN` environment variable. Otherwise, we read the token file located
|
|
35
|
-
in the Hugging Face home folder. Returns None if user is not logged in. To log in, use [`login`] or
|
|
36
|
-
`huggingface-cli login`.
|
|
37
|
-
|
|
38
|
-
Returns:
|
|
39
|
-
`str` or `None`: The token, `None` if it doesn't exist.
|
|
40
|
-
"""
|
|
41
|
-
return _get_token_from_google_colab() or _get_token_from_environment() or _get_token_from_file()
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
def _get_token_from_google_colab() -> Optional[str]:
|
|
45
|
-
if not is_google_colab():
|
|
46
|
-
return None
|
|
47
|
-
|
|
48
|
-
global _CHECK_GOOGLE_COLAB_SECRET
|
|
49
|
-
if not _CHECK_GOOGLE_COLAB_SECRET: # request access only once
|
|
50
|
-
return None
|
|
51
|
-
|
|
52
|
-
try:
|
|
53
|
-
from google.colab import userdata
|
|
54
|
-
from google.colab.errors import Error as ColabError
|
|
55
|
-
except ImportError:
|
|
56
|
-
return None
|
|
57
|
-
|
|
58
|
-
try:
|
|
59
|
-
token = userdata.get("HF_TOKEN")
|
|
60
|
-
except userdata.NotebookAccessError:
|
|
61
|
-
# Means the user has a secret call `HF_TOKEN` and got a popup "please grand access to HF_TOKEN" and refused it
|
|
62
|
-
# => warn user but ignore error => do not re-request access to user
|
|
63
|
-
warnings.warn(
|
|
64
|
-
"\nAccess to the secret `HF_TOKEN` has not been granted on this notebook."
|
|
65
|
-
"\nYou will not be requested again."
|
|
66
|
-
"\nPlease restart the session if you want to be prompted again."
|
|
67
|
-
)
|
|
68
|
-
_CHECK_GOOGLE_COLAB_SECRET = False
|
|
69
|
-
return None
|
|
70
|
-
except userdata.SecretNotFoundError:
|
|
71
|
-
# Means the user did not define a `HF_TOKEN` secret => warn
|
|
72
|
-
warnings.warn(
|
|
73
|
-
"\nThe secret `HF_TOKEN` does not exist in your Colab secrets."
|
|
74
|
-
"\nTo authenticate with the Hugging Face Hub, create a token in your settings tab "
|
|
75
|
-
"(https://huggingface.co/settings/tokens), set it as secret in your Google Colab and restart your session."
|
|
76
|
-
"\nYou will be able to reuse this secret in all of your notebooks."
|
|
77
|
-
"\nPlease note that authentication is recommended but still optional to access public models or datasets."
|
|
78
|
-
)
|
|
79
|
-
return None
|
|
80
|
-
except ColabError as e:
|
|
81
|
-
# Something happen but we don't know what => recommend to open a GitHub issue
|
|
82
|
-
warnings.warn(
|
|
83
|
-
f"\nError while fetching `HF_TOKEN` secret value from your vault: '{str(e)}'."
|
|
84
|
-
"\nYou are not authenticated with the Hugging Face Hub in this notebook."
|
|
85
|
-
"\nIf the error persists, please let us know by opening an issue on GitHub "
|
|
86
|
-
"(https://github.com/huggingface/huggingface_hub/issues/new)."
|
|
87
|
-
)
|
|
88
|
-
return None
|
|
89
|
-
|
|
90
|
-
return _clean_token(token)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
def _get_token_from_environment() -> Optional[str]:
|
|
94
|
-
# `HF_TOKEN` has priority (keep `HUGGING_FACE_HUB_TOKEN` for backward compatibility)
|
|
95
|
-
return _clean_token(os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN"))
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
def _get_token_from_file() -> Optional[str]:
|
|
99
|
-
try:
|
|
100
|
-
return _clean_token(Path(constants.HF_TOKEN_PATH).read_text())
|
|
101
|
-
except FileNotFoundError:
|
|
102
|
-
return None
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
def _clean_token(token: Optional[str]) -> Optional[str]:
|
|
106
|
-
"""Clean token by removing trailing and leading spaces and newlines.
|
|
107
|
-
|
|
108
|
-
If token is an empty string, return None.
|
|
109
|
-
"""
|
|
110
|
-
if token is None:
|
|
111
|
-
return None
|
|
112
|
-
return token.replace("\r", "").replace("\n", "").strip() or None
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/_inference_endpoints.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/_tensorboard_logger.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/commands/_cli_utils.py
RENAMED
|
File without changes
|
{huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/commands/delete_cache.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/commands/huggingface_cli.py
RENAMED
|
File without changes
|
|
File without changes
|
{huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/commands/scan_cache.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/inference/_text_generation.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_cache_assets.py
RENAMED
|
File without changes
|
{huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_cache_manager.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_experimental.py
RENAMED
|
File without changes
|
|
File without changes
|
{huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/_git_credential.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/endpoint_helpers.py
RENAMED
|
File without changes
|
{huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub/utils/insecure_hashlib.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub.egg-info/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|
{huggingface_hub-0.20.1 → huggingface_hub-0.20.3}/src/huggingface_hub.egg-info/top_level.txt
RENAMED
|
File without changes
|