huggingface-hub 0.31.0rc0__py3-none-any.whl → 1.1.3__py3-none-any.whl
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.
- huggingface_hub/__init__.py +145 -46
- huggingface_hub/_commit_api.py +168 -119
- huggingface_hub/_commit_scheduler.py +15 -15
- huggingface_hub/_inference_endpoints.py +15 -12
- huggingface_hub/_jobs_api.py +301 -0
- huggingface_hub/_local_folder.py +18 -3
- huggingface_hub/_login.py +31 -63
- huggingface_hub/_oauth.py +460 -0
- huggingface_hub/_snapshot_download.py +239 -80
- huggingface_hub/_space_api.py +5 -5
- huggingface_hub/_tensorboard_logger.py +15 -19
- huggingface_hub/_upload_large_folder.py +172 -76
- huggingface_hub/_webhooks_payload.py +3 -3
- huggingface_hub/_webhooks_server.py +13 -25
- huggingface_hub/{commands → cli}/__init__.py +1 -15
- huggingface_hub/cli/_cli_utils.py +173 -0
- huggingface_hub/cli/auth.py +147 -0
- huggingface_hub/cli/cache.py +841 -0
- huggingface_hub/cli/download.py +189 -0
- huggingface_hub/cli/hf.py +60 -0
- huggingface_hub/cli/inference_endpoints.py +377 -0
- huggingface_hub/cli/jobs.py +772 -0
- huggingface_hub/cli/lfs.py +175 -0
- huggingface_hub/cli/repo.py +315 -0
- huggingface_hub/cli/repo_files.py +94 -0
- huggingface_hub/{commands/env.py → cli/system.py} +10 -13
- huggingface_hub/cli/upload.py +294 -0
- huggingface_hub/cli/upload_large_folder.py +117 -0
- huggingface_hub/community.py +20 -12
- huggingface_hub/constants.py +38 -53
- huggingface_hub/dataclasses.py +609 -0
- huggingface_hub/errors.py +80 -30
- huggingface_hub/fastai_utils.py +30 -41
- huggingface_hub/file_download.py +435 -351
- huggingface_hub/hf_api.py +2050 -1124
- huggingface_hub/hf_file_system.py +269 -152
- huggingface_hub/hub_mixin.py +43 -63
- huggingface_hub/inference/_client.py +347 -434
- huggingface_hub/inference/_common.py +133 -121
- huggingface_hub/inference/_generated/_async_client.py +397 -541
- huggingface_hub/inference/_generated/types/__init__.py +5 -1
- huggingface_hub/inference/_generated/types/automatic_speech_recognition.py +3 -3
- huggingface_hub/inference/_generated/types/base.py +10 -7
- huggingface_hub/inference/_generated/types/chat_completion.py +59 -23
- huggingface_hub/inference/_generated/types/depth_estimation.py +2 -2
- huggingface_hub/inference/_generated/types/document_question_answering.py +2 -2
- huggingface_hub/inference/_generated/types/feature_extraction.py +2 -2
- huggingface_hub/inference/_generated/types/fill_mask.py +2 -2
- huggingface_hub/inference/_generated/types/image_to_image.py +6 -2
- huggingface_hub/inference/_generated/types/image_to_video.py +60 -0
- huggingface_hub/inference/_generated/types/sentence_similarity.py +3 -3
- huggingface_hub/inference/_generated/types/summarization.py +2 -2
- huggingface_hub/inference/_generated/types/table_question_answering.py +5 -5
- huggingface_hub/inference/_generated/types/text2text_generation.py +2 -2
- huggingface_hub/inference/_generated/types/text_generation.py +10 -10
- huggingface_hub/inference/_generated/types/text_to_video.py +2 -2
- huggingface_hub/inference/_generated/types/token_classification.py +2 -2
- huggingface_hub/inference/_generated/types/translation.py +2 -2
- huggingface_hub/inference/_generated/types/zero_shot_classification.py +2 -2
- huggingface_hub/inference/_generated/types/zero_shot_image_classification.py +2 -2
- huggingface_hub/inference/_generated/types/zero_shot_object_detection.py +1 -3
- huggingface_hub/inference/_mcp/__init__.py +0 -0
- huggingface_hub/inference/_mcp/_cli_hacks.py +88 -0
- huggingface_hub/inference/_mcp/agent.py +100 -0
- huggingface_hub/inference/_mcp/cli.py +247 -0
- huggingface_hub/inference/_mcp/constants.py +81 -0
- huggingface_hub/inference/_mcp/mcp_client.py +395 -0
- huggingface_hub/inference/_mcp/types.py +45 -0
- huggingface_hub/inference/_mcp/utils.py +128 -0
- huggingface_hub/inference/_providers/__init__.py +82 -7
- huggingface_hub/inference/_providers/_common.py +129 -27
- huggingface_hub/inference/_providers/black_forest_labs.py +6 -6
- huggingface_hub/inference/_providers/cerebras.py +1 -1
- huggingface_hub/inference/_providers/clarifai.py +13 -0
- huggingface_hub/inference/_providers/cohere.py +20 -3
- huggingface_hub/inference/_providers/fal_ai.py +183 -56
- huggingface_hub/inference/_providers/featherless_ai.py +38 -0
- huggingface_hub/inference/_providers/fireworks_ai.py +18 -0
- huggingface_hub/inference/_providers/groq.py +9 -0
- huggingface_hub/inference/_providers/hf_inference.py +69 -30
- huggingface_hub/inference/_providers/hyperbolic.py +4 -4
- huggingface_hub/inference/_providers/nebius.py +33 -5
- huggingface_hub/inference/_providers/novita.py +5 -5
- huggingface_hub/inference/_providers/nscale.py +44 -0
- huggingface_hub/inference/_providers/openai.py +3 -1
- huggingface_hub/inference/_providers/publicai.py +6 -0
- huggingface_hub/inference/_providers/replicate.py +31 -13
- huggingface_hub/inference/_providers/sambanova.py +18 -4
- huggingface_hub/inference/_providers/scaleway.py +28 -0
- huggingface_hub/inference/_providers/together.py +20 -5
- huggingface_hub/inference/_providers/wavespeed.py +138 -0
- huggingface_hub/inference/_providers/zai_org.py +17 -0
- huggingface_hub/lfs.py +33 -100
- huggingface_hub/repocard.py +34 -38
- huggingface_hub/repocard_data.py +57 -57
- huggingface_hub/serialization/__init__.py +0 -1
- huggingface_hub/serialization/_base.py +12 -15
- huggingface_hub/serialization/_dduf.py +8 -8
- huggingface_hub/serialization/_torch.py +69 -69
- huggingface_hub/utils/__init__.py +19 -8
- huggingface_hub/utils/_auth.py +7 -7
- huggingface_hub/utils/_cache_manager.py +92 -147
- huggingface_hub/utils/_chunk_utils.py +2 -3
- huggingface_hub/utils/_deprecation.py +1 -1
- huggingface_hub/utils/_dotenv.py +55 -0
- huggingface_hub/utils/_experimental.py +7 -5
- huggingface_hub/utils/_fixes.py +0 -10
- huggingface_hub/utils/_git_credential.py +5 -5
- huggingface_hub/utils/_headers.py +8 -30
- huggingface_hub/utils/_http.py +398 -239
- huggingface_hub/utils/_pagination.py +4 -4
- huggingface_hub/utils/_parsing.py +98 -0
- huggingface_hub/utils/_paths.py +5 -5
- huggingface_hub/utils/_runtime.py +61 -24
- huggingface_hub/utils/_safetensors.py +21 -21
- huggingface_hub/utils/_subprocess.py +9 -9
- huggingface_hub/utils/_telemetry.py +4 -4
- huggingface_hub/{commands/_cli_utils.py → utils/_terminal.py} +4 -4
- huggingface_hub/utils/_typing.py +25 -5
- huggingface_hub/utils/_validators.py +55 -74
- huggingface_hub/utils/_verification.py +167 -0
- huggingface_hub/utils/_xet.py +64 -17
- huggingface_hub/utils/_xet_progress_reporting.py +162 -0
- huggingface_hub/utils/insecure_hashlib.py +3 -5
- huggingface_hub/utils/logging.py +8 -11
- huggingface_hub/utils/tqdm.py +5 -4
- {huggingface_hub-0.31.0rc0.dist-info → huggingface_hub-1.1.3.dist-info}/METADATA +94 -85
- huggingface_hub-1.1.3.dist-info/RECORD +155 -0
- {huggingface_hub-0.31.0rc0.dist-info → huggingface_hub-1.1.3.dist-info}/WHEEL +1 -1
- huggingface_hub-1.1.3.dist-info/entry_points.txt +6 -0
- huggingface_hub/commands/delete_cache.py +0 -474
- huggingface_hub/commands/download.py +0 -200
- huggingface_hub/commands/huggingface_cli.py +0 -61
- huggingface_hub/commands/lfs.py +0 -200
- huggingface_hub/commands/repo_files.py +0 -128
- huggingface_hub/commands/scan_cache.py +0 -181
- huggingface_hub/commands/tag.py +0 -159
- huggingface_hub/commands/upload.py +0 -314
- huggingface_hub/commands/upload_large_folder.py +0 -129
- huggingface_hub/commands/user.py +0 -304
- huggingface_hub/commands/version.py +0 -37
- huggingface_hub/inference_api.py +0 -217
- huggingface_hub/keras_mixin.py +0 -500
- huggingface_hub/repository.py +0 -1477
- huggingface_hub/serialization/_tensorflow.py +0 -95
- huggingface_hub/utils/_hf_folder.py +0 -68
- huggingface_hub-0.31.0rc0.dist-info/RECORD +0 -135
- huggingface_hub-0.31.0rc0.dist-info/entry_points.txt +0 -6
- {huggingface_hub-0.31.0rc0.dist-info → huggingface_hub-1.1.3.dist-info/licenses}/LICENSE +0 -0
- {huggingface_hub-0.31.0rc0.dist-info → huggingface_hub-1.1.3.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# Copyright 2022 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 CLI utilities (styling, helpers)."""
|
|
15
|
+
|
|
16
|
+
import importlib.metadata
|
|
17
|
+
import os
|
|
18
|
+
import time
|
|
19
|
+
from enum import Enum
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
from typing import TYPE_CHECKING, Annotated, Optional
|
|
22
|
+
|
|
23
|
+
import click
|
|
24
|
+
import typer
|
|
25
|
+
|
|
26
|
+
from huggingface_hub import __version__, constants
|
|
27
|
+
from huggingface_hub.utils import ANSI, get_session, hf_raise_for_status, installation_method, logging
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
logger = logging.get_logger()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
if TYPE_CHECKING:
|
|
34
|
+
from huggingface_hub.hf_api import HfApi
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def get_hf_api(token: Optional[str] = None) -> "HfApi":
|
|
38
|
+
# Import here to avoid circular import
|
|
39
|
+
from huggingface_hub.hf_api import HfApi
|
|
40
|
+
|
|
41
|
+
return HfApi(token=token, library_name="huggingface-cli", library_version=__version__)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
#### TYPER UTILS
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class AlphabeticalMixedGroup(typer.core.TyperGroup):
|
|
48
|
+
"""
|
|
49
|
+
Typer Group that lists commands and sub-apps mixed and alphabetically.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
def list_commands(self, ctx: click.Context) -> list[str]: # type: ignore[name-defined]
|
|
53
|
+
# click.Group stores both commands and subgroups in `self.commands`
|
|
54
|
+
return sorted(self.commands.keys())
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def typer_factory(help: str) -> typer.Typer:
|
|
58
|
+
return typer.Typer(
|
|
59
|
+
help=help,
|
|
60
|
+
add_completion=True,
|
|
61
|
+
no_args_is_help=True,
|
|
62
|
+
cls=AlphabeticalMixedGroup,
|
|
63
|
+
# Disable rich completely for consistent experience
|
|
64
|
+
rich_markup_mode=None,
|
|
65
|
+
rich_help_panel=None,
|
|
66
|
+
pretty_exceptions_enable=False,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class RepoType(str, Enum):
|
|
71
|
+
model = "model"
|
|
72
|
+
dataset = "dataset"
|
|
73
|
+
space = "space"
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
RepoIdArg = Annotated[
|
|
77
|
+
str,
|
|
78
|
+
typer.Argument(
|
|
79
|
+
help="The ID of the repo (e.g. `username/repo-name`).",
|
|
80
|
+
),
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
RepoTypeOpt = Annotated[
|
|
85
|
+
RepoType,
|
|
86
|
+
typer.Option(
|
|
87
|
+
help="The type of repository (model, dataset, or space).",
|
|
88
|
+
),
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
TokenOpt = Annotated[
|
|
92
|
+
Optional[str],
|
|
93
|
+
typer.Option(
|
|
94
|
+
help="A User Access Token generated from https://huggingface.co/settings/tokens.",
|
|
95
|
+
),
|
|
96
|
+
]
|
|
97
|
+
|
|
98
|
+
PrivateOpt = Annotated[
|
|
99
|
+
bool,
|
|
100
|
+
typer.Option(
|
|
101
|
+
help="Whether to create a private repo if repo doesn't exist on the Hub. Ignored if the repo already exists.",
|
|
102
|
+
),
|
|
103
|
+
]
|
|
104
|
+
|
|
105
|
+
RevisionOpt = Annotated[
|
|
106
|
+
Optional[str],
|
|
107
|
+
typer.Option(
|
|
108
|
+
help="Git revision id which can be a branch name, a tag, or a commit hash.",
|
|
109
|
+
),
|
|
110
|
+
]
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
### PyPI VERSION CHECKER
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def check_cli_update() -> None:
|
|
117
|
+
"""
|
|
118
|
+
Check whether a newer version of `huggingface_hub` is available on PyPI.
|
|
119
|
+
|
|
120
|
+
If a newer version is found, notify the user and suggest updating.
|
|
121
|
+
If current version is a pre-release (e.g. `1.0.0.rc1`), or a dev version (e.g. `1.0.0.dev1`), no check is performed.
|
|
122
|
+
|
|
123
|
+
This function is called at the entry point of the CLI. It only performs the check once every 24 hours, and any error
|
|
124
|
+
during the check is caught and logged, to avoid breaking the CLI.
|
|
125
|
+
"""
|
|
126
|
+
try:
|
|
127
|
+
_check_cli_update()
|
|
128
|
+
except Exception:
|
|
129
|
+
# We don't want the CLI to fail on version checks, no matter the reason.
|
|
130
|
+
logger.debug("Error while checking for CLI update.", exc_info=True)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _check_cli_update() -> None:
|
|
134
|
+
current_version = importlib.metadata.version("huggingface_hub")
|
|
135
|
+
|
|
136
|
+
# Skip if current version is a pre-release or dev version
|
|
137
|
+
if any(tag in current_version for tag in ["rc", "dev"]):
|
|
138
|
+
return
|
|
139
|
+
|
|
140
|
+
# Skip if already checked in the last 24 hours
|
|
141
|
+
if os.path.exists(constants.CHECK_FOR_UPDATE_DONE_PATH):
|
|
142
|
+
mtime = os.path.getmtime(constants.CHECK_FOR_UPDATE_DONE_PATH)
|
|
143
|
+
if (time.time() - mtime) < 24 * 3600:
|
|
144
|
+
return
|
|
145
|
+
|
|
146
|
+
# Touch the file to mark that we did the check now
|
|
147
|
+
Path(constants.CHECK_FOR_UPDATE_DONE_PATH).touch()
|
|
148
|
+
|
|
149
|
+
# Check latest version from PyPI
|
|
150
|
+
response = get_session().get("https://pypi.org/pypi/huggingface_hub/json", timeout=2)
|
|
151
|
+
hf_raise_for_status(response)
|
|
152
|
+
data = response.json()
|
|
153
|
+
latest_version = data["info"]["version"]
|
|
154
|
+
|
|
155
|
+
# If latest version is different from current, notify user
|
|
156
|
+
if current_version != latest_version:
|
|
157
|
+
method = installation_method()
|
|
158
|
+
if method == "brew":
|
|
159
|
+
update_command = "brew upgrade huggingface-cli"
|
|
160
|
+
elif method == "hf_installer" and os.name == "nt":
|
|
161
|
+
update_command = 'powershell -NoProfile -Command "iwr -useb https://hf.co/cli/install.ps1 | iex"'
|
|
162
|
+
elif method == "hf_installer":
|
|
163
|
+
update_command = "curl -LsSf https://hf.co/cli/install.sh | bash -"
|
|
164
|
+
else: # unknown => likely pip
|
|
165
|
+
update_command = "pip install -U huggingface_hub"
|
|
166
|
+
|
|
167
|
+
click.echo(
|
|
168
|
+
ANSI.yellow(
|
|
169
|
+
f"A new version of huggingface_hub ({latest_version}) is available! "
|
|
170
|
+
f"You are using version {current_version}.\n"
|
|
171
|
+
f"To update, run: {ANSI.bold(update_command)}\n",
|
|
172
|
+
)
|
|
173
|
+
)
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Copyright 2020 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 commands to authenticate to the Hugging Face Hub and interact with your repositories.
|
|
15
|
+
|
|
16
|
+
Usage:
|
|
17
|
+
# login and save token locally.
|
|
18
|
+
hf auth login --token=hf_*** --add-to-git-credential
|
|
19
|
+
|
|
20
|
+
# switch between tokens
|
|
21
|
+
hf auth switch
|
|
22
|
+
|
|
23
|
+
# list all tokens
|
|
24
|
+
hf auth list
|
|
25
|
+
|
|
26
|
+
# logout from all tokens
|
|
27
|
+
hf auth logout
|
|
28
|
+
|
|
29
|
+
# check which account you are logged in as
|
|
30
|
+
hf auth whoami
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
from typing import Annotated, Optional
|
|
34
|
+
|
|
35
|
+
import typer
|
|
36
|
+
|
|
37
|
+
from huggingface_hub.constants import ENDPOINT
|
|
38
|
+
from huggingface_hub.errors import HfHubHTTPError
|
|
39
|
+
from huggingface_hub.hf_api import whoami
|
|
40
|
+
|
|
41
|
+
from .._login import auth_list, auth_switch, login, logout
|
|
42
|
+
from ..utils import ANSI, get_stored_tokens, get_token, logging
|
|
43
|
+
from ._cli_utils import TokenOpt, typer_factory
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
logger = logging.get_logger(__name__)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
auth_cli = typer_factory(help="Manage authentication (login, logout, etc.).")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@auth_cli.command("login", help="Login using a token from huggingface.co/settings/tokens")
|
|
53
|
+
def auth_login(
|
|
54
|
+
token: TokenOpt = None,
|
|
55
|
+
add_to_git_credential: Annotated[
|
|
56
|
+
bool,
|
|
57
|
+
typer.Option(
|
|
58
|
+
help="Save to git credential helper. Useful only if you plan to run git commands directly.",
|
|
59
|
+
),
|
|
60
|
+
] = False,
|
|
61
|
+
) -> None:
|
|
62
|
+
login(token=token, add_to_git_credential=add_to_git_credential)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@auth_cli.command("logout", help="Logout from a specific token")
|
|
66
|
+
def auth_logout(
|
|
67
|
+
token_name: Annotated[
|
|
68
|
+
Optional[str],
|
|
69
|
+
typer.Option(
|
|
70
|
+
help="Name of token to logout",
|
|
71
|
+
),
|
|
72
|
+
] = None,
|
|
73
|
+
) -> None:
|
|
74
|
+
logout(token_name=token_name)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _select_token_name() -> Optional[str]:
|
|
78
|
+
token_names = list(get_stored_tokens().keys())
|
|
79
|
+
|
|
80
|
+
if not token_names:
|
|
81
|
+
logger.error("No stored tokens found. Please login first.")
|
|
82
|
+
return None
|
|
83
|
+
|
|
84
|
+
print("Available stored tokens:")
|
|
85
|
+
for i, token_name in enumerate(token_names, 1):
|
|
86
|
+
print(f"{i}. {token_name}")
|
|
87
|
+
while True:
|
|
88
|
+
try:
|
|
89
|
+
choice = input("Enter the number of the token to switch to (or 'q' to quit): ")
|
|
90
|
+
if choice.lower() == "q":
|
|
91
|
+
return None
|
|
92
|
+
index = int(choice) - 1
|
|
93
|
+
if 0 <= index < len(token_names):
|
|
94
|
+
return token_names[index]
|
|
95
|
+
else:
|
|
96
|
+
print("Invalid selection. Please try again.")
|
|
97
|
+
except ValueError:
|
|
98
|
+
print("Invalid input. Please enter a number or 'q' to quit.")
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@auth_cli.command("switch", help="Switch between access tokens")
|
|
102
|
+
def auth_switch_cmd(
|
|
103
|
+
token_name: Annotated[
|
|
104
|
+
Optional[str],
|
|
105
|
+
typer.Option(
|
|
106
|
+
help="Name of the token to switch to",
|
|
107
|
+
),
|
|
108
|
+
] = None,
|
|
109
|
+
add_to_git_credential: Annotated[
|
|
110
|
+
bool,
|
|
111
|
+
typer.Option(
|
|
112
|
+
help="Save to git credential helper. Useful only if you plan to run git commands directly.",
|
|
113
|
+
),
|
|
114
|
+
] = False,
|
|
115
|
+
) -> None:
|
|
116
|
+
if token_name is None:
|
|
117
|
+
token_name = _select_token_name()
|
|
118
|
+
if token_name is None:
|
|
119
|
+
print("No token name provided. Aborting.")
|
|
120
|
+
raise typer.Exit()
|
|
121
|
+
auth_switch(token_name, add_to_git_credential=add_to_git_credential)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
@auth_cli.command("list", help="List all stored access tokens")
|
|
125
|
+
def auth_list_cmd() -> None:
|
|
126
|
+
auth_list()
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
@auth_cli.command("whoami", help="Find out which huggingface.co account you are logged in as.")
|
|
130
|
+
def auth_whoami() -> None:
|
|
131
|
+
token = get_token()
|
|
132
|
+
if token is None:
|
|
133
|
+
print("Not logged in")
|
|
134
|
+
raise typer.Exit()
|
|
135
|
+
try:
|
|
136
|
+
info = whoami(token)
|
|
137
|
+
print(ANSI.bold("user: "), info["name"])
|
|
138
|
+
orgs = [org["name"] for org in info["orgs"]]
|
|
139
|
+
if orgs:
|
|
140
|
+
print(ANSI.bold("orgs: "), ",".join(orgs))
|
|
141
|
+
|
|
142
|
+
if ENDPOINT != "https://huggingface.co":
|
|
143
|
+
print(f"Authenticated through private endpoint: {ENDPOINT}")
|
|
144
|
+
except HfHubHTTPError as e:
|
|
145
|
+
print(e)
|
|
146
|
+
print(ANSI.red(e.response.text))
|
|
147
|
+
raise typer.Exit(code=1)
|