huggingface-hub 0.20.1__tar.gz → 0.20.2__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.

Files changed (84) hide show
  1. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/PKG-INFO +1 -1
  2. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/__init__.py +1 -1
  3. huggingface_hub-0.20.2/src/huggingface_hub/utils/_token.py +129 -0
  4. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub.egg-info/PKG-INFO +1 -1
  5. huggingface_hub-0.20.1/src/huggingface_hub/utils/_token.py +0 -112
  6. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/LICENSE +0 -0
  7. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/MANIFEST.in +0 -0
  8. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/README.md +0 -0
  9. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/pyproject.toml +0 -0
  10. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/setup.cfg +0 -0
  11. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/setup.py +0 -0
  12. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/_commit_api.py +0 -0
  13. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/_commit_scheduler.py +0 -0
  14. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/_inference_endpoints.py +0 -0
  15. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/_login.py +0 -0
  16. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/_multi_commits.py +0 -0
  17. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/_snapshot_download.py +0 -0
  18. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/_space_api.py +0 -0
  19. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/_tensorboard_logger.py +0 -0
  20. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/_webhooks_payload.py +0 -0
  21. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/_webhooks_server.py +0 -0
  22. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/commands/__init__.py +0 -0
  23. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/commands/_cli_utils.py +0 -0
  24. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/commands/delete_cache.py +0 -0
  25. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/commands/download.py +0 -0
  26. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/commands/env.py +0 -0
  27. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/commands/huggingface_cli.py +0 -0
  28. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/commands/lfs.py +0 -0
  29. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/commands/scan_cache.py +0 -0
  30. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/commands/upload.py +0 -0
  31. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/commands/user.py +0 -0
  32. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/community.py +0 -0
  33. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/constants.py +0 -0
  34. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/fastai_utils.py +0 -0
  35. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/file_download.py +0 -0
  36. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/hf_api.py +0 -0
  37. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/hf_file_system.py +0 -0
  38. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/hub_mixin.py +0 -0
  39. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/inference/__init__.py +0 -0
  40. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/inference/_client.py +0 -0
  41. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/inference/_common.py +0 -0
  42. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/inference/_generated/__init__.py +0 -0
  43. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/inference/_generated/_async_client.py +0 -0
  44. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/inference/_text_generation.py +0 -0
  45. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/inference/_types.py +0 -0
  46. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/inference_api.py +0 -0
  47. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/keras_mixin.py +0 -0
  48. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/lfs.py +0 -0
  49. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/repocard.py +0 -0
  50. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/repocard_data.py +0 -0
  51. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/repository.py +0 -0
  52. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/templates/datasetcard_template.md +0 -0
  53. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/templates/modelcard_template.md +0 -0
  54. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/__init__.py +0 -0
  55. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/_cache_assets.py +0 -0
  56. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/_cache_manager.py +0 -0
  57. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/_chunk_utils.py +0 -0
  58. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/_datetime.py +0 -0
  59. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/_deprecation.py +0 -0
  60. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/_errors.py +0 -0
  61. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/_experimental.py +0 -0
  62. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/_fixes.py +0 -0
  63. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/_git_credential.py +0 -0
  64. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/_headers.py +0 -0
  65. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/_hf_folder.py +0 -0
  66. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/_http.py +0 -0
  67. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/_pagination.py +0 -0
  68. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/_paths.py +0 -0
  69. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/_runtime.py +0 -0
  70. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/_safetensors.py +0 -0
  71. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/_subprocess.py +0 -0
  72. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/_telemetry.py +0 -0
  73. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/_typing.py +0 -0
  74. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/_validators.py +0 -0
  75. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/endpoint_helpers.py +0 -0
  76. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/insecure_hashlib.py +0 -0
  77. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/logging.py +0 -0
  78. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/sha.py +0 -0
  79. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub/utils/tqdm.py +0 -0
  80. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub.egg-info/SOURCES.txt +0 -0
  81. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub.egg-info/dependency_links.txt +0 -0
  82. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub.egg-info/entry_points.txt +0 -0
  83. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/src/huggingface_hub.egg-info/requires.txt +0 -0
  84. {huggingface_hub-0.20.1 → huggingface_hub-0.20.2}/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.1
3
+ Version: 0.20.2
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.
@@ -46,7 +46,7 @@ import sys
46
46
  from typing import TYPE_CHECKING
47
47
 
48
48
 
49
- __version__ = "0.20.1"
49
+ __version__ = "0.20.2"
50
50
 
51
51
  # Alphabetical order of definitions is ensured in tests
52
52
  # WARNING: any comment added in this dictionary definition will be lost when
@@ -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.1
3
+ Version: 0.20.2
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