huggingface-hub 0.36.0__py3-none-any.whl → 1.0.0__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.
Potentially problematic release.
This version of huggingface-hub might be problematic. Click here for more details.
- huggingface_hub/__init__.py +33 -45
- huggingface_hub/_commit_api.py +39 -43
- huggingface_hub/_commit_scheduler.py +11 -8
- huggingface_hub/_inference_endpoints.py +8 -8
- huggingface_hub/_jobs_api.py +20 -20
- huggingface_hub/_login.py +17 -43
- huggingface_hub/_oauth.py +8 -8
- huggingface_hub/_snapshot_download.py +135 -50
- huggingface_hub/_space_api.py +4 -4
- huggingface_hub/_tensorboard_logger.py +5 -5
- huggingface_hub/_upload_large_folder.py +18 -32
- huggingface_hub/_webhooks_payload.py +3 -3
- huggingface_hub/_webhooks_server.py +2 -2
- huggingface_hub/cli/__init__.py +0 -14
- huggingface_hub/cli/_cli_utils.py +143 -39
- huggingface_hub/cli/auth.py +105 -171
- huggingface_hub/cli/cache.py +594 -361
- huggingface_hub/cli/download.py +120 -112
- huggingface_hub/cli/hf.py +38 -41
- huggingface_hub/cli/jobs.py +689 -1017
- huggingface_hub/cli/lfs.py +120 -143
- huggingface_hub/cli/repo.py +282 -216
- huggingface_hub/cli/repo_files.py +50 -84
- huggingface_hub/cli/system.py +6 -25
- huggingface_hub/cli/upload.py +198 -220
- huggingface_hub/cli/upload_large_folder.py +91 -106
- huggingface_hub/community.py +5 -5
- huggingface_hub/constants.py +17 -52
- huggingface_hub/dataclasses.py +135 -21
- huggingface_hub/errors.py +47 -30
- huggingface_hub/fastai_utils.py +8 -9
- huggingface_hub/file_download.py +351 -303
- huggingface_hub/hf_api.py +398 -570
- huggingface_hub/hf_file_system.py +101 -66
- huggingface_hub/hub_mixin.py +32 -54
- huggingface_hub/inference/_client.py +177 -162
- huggingface_hub/inference/_common.py +38 -54
- huggingface_hub/inference/_generated/_async_client.py +218 -258
- 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 +16 -16
- 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/sentence_similarity.py +3 -3
- huggingface_hub/inference/_generated/types/summarization.py +2 -2
- huggingface_hub/inference/_generated/types/table_question_answering.py +4 -4
- 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/agent.py +3 -3
- huggingface_hub/inference/_mcp/constants.py +1 -2
- huggingface_hub/inference/_mcp/mcp_client.py +33 -22
- huggingface_hub/inference/_mcp/types.py +10 -10
- huggingface_hub/inference/_mcp/utils.py +4 -4
- huggingface_hub/inference/_providers/__init__.py +12 -4
- huggingface_hub/inference/_providers/_common.py +62 -24
- huggingface_hub/inference/_providers/black_forest_labs.py +6 -6
- huggingface_hub/inference/_providers/cohere.py +3 -3
- huggingface_hub/inference/_providers/fal_ai.py +25 -25
- huggingface_hub/inference/_providers/featherless_ai.py +4 -4
- huggingface_hub/inference/_providers/fireworks_ai.py +3 -3
- huggingface_hub/inference/_providers/hf_inference.py +13 -13
- huggingface_hub/inference/_providers/hyperbolic.py +4 -4
- huggingface_hub/inference/_providers/nebius.py +10 -10
- huggingface_hub/inference/_providers/novita.py +5 -5
- huggingface_hub/inference/_providers/nscale.py +4 -4
- huggingface_hub/inference/_providers/replicate.py +15 -15
- huggingface_hub/inference/_providers/sambanova.py +6 -6
- huggingface_hub/inference/_providers/together.py +7 -7
- huggingface_hub/lfs.py +21 -94
- huggingface_hub/repocard.py +15 -16
- huggingface_hub/repocard_data.py +57 -57
- huggingface_hub/serialization/__init__.py +0 -1
- huggingface_hub/serialization/_base.py +9 -9
- huggingface_hub/serialization/_dduf.py +7 -7
- huggingface_hub/serialization/_torch.py +28 -28
- huggingface_hub/utils/__init__.py +11 -6
- huggingface_hub/utils/_auth.py +5 -5
- huggingface_hub/utils/_cache_manager.py +49 -74
- huggingface_hub/utils/_deprecation.py +1 -1
- huggingface_hub/utils/_dotenv.py +3 -3
- huggingface_hub/utils/_fixes.py +0 -10
- huggingface_hub/utils/_git_credential.py +3 -3
- huggingface_hub/utils/_headers.py +7 -29
- huggingface_hub/utils/_http.py +371 -208
- 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 +59 -23
- huggingface_hub/utils/_safetensors.py +21 -21
- huggingface_hub/utils/_subprocess.py +9 -9
- huggingface_hub/utils/_telemetry.py +3 -3
- huggingface_hub/{commands/_cli_utils.py → utils/_terminal.py} +4 -9
- huggingface_hub/utils/_typing.py +3 -3
- huggingface_hub/utils/_validators.py +53 -72
- huggingface_hub/utils/_xet.py +16 -16
- huggingface_hub/utils/_xet_progress_reporting.py +1 -1
- huggingface_hub/utils/insecure_hashlib.py +3 -9
- huggingface_hub/utils/tqdm.py +3 -3
- {huggingface_hub-0.36.0.dist-info → huggingface_hub-1.0.0.dist-info}/METADATA +16 -35
- huggingface_hub-1.0.0.dist-info/RECORD +152 -0
- {huggingface_hub-0.36.0.dist-info → huggingface_hub-1.0.0.dist-info}/entry_points.txt +0 -1
- huggingface_hub/commands/__init__.py +0 -27
- huggingface_hub/commands/delete_cache.py +0 -476
- huggingface_hub/commands/download.py +0 -204
- huggingface_hub/commands/env.py +0 -39
- huggingface_hub/commands/huggingface_cli.py +0 -65
- huggingface_hub/commands/lfs.py +0 -200
- huggingface_hub/commands/repo.py +0 -151
- huggingface_hub/commands/repo_files.py +0 -132
- huggingface_hub/commands/scan_cache.py +0 -183
- huggingface_hub/commands/tag.py +0 -161
- huggingface_hub/commands/upload.py +0 -318
- huggingface_hub/commands/upload_large_folder.py +0 -131
- huggingface_hub/commands/user.py +0 -208
- huggingface_hub/commands/version.py +0 -40
- huggingface_hub/inference_api.py +0 -217
- huggingface_hub/keras_mixin.py +0 -497
- huggingface_hub/repository.py +0 -1471
- huggingface_hub/serialization/_tensorflow.py +0 -92
- huggingface_hub/utils/_hf_folder.py +0 -68
- huggingface_hub-0.36.0.dist-info/RECORD +0 -170
- {huggingface_hub-0.36.0.dist-info → huggingface_hub-1.0.0.dist-info}/LICENSE +0 -0
- {huggingface_hub-0.36.0.dist-info → huggingface_hub-1.0.0.dist-info}/WHEEL +0 -0
- {huggingface_hub-0.36.0.dist-info → huggingface_hub-1.0.0.dist-info}/top_level.txt +0 -0
huggingface_hub/cli/auth.py
CHANGED
|
@@ -30,184 +30,118 @@ Usage:
|
|
|
30
30
|
hf auth whoami
|
|
31
31
|
"""
|
|
32
32
|
|
|
33
|
-
from
|
|
34
|
-
from typing import List, Optional
|
|
33
|
+
from typing import Annotated, Optional
|
|
35
34
|
|
|
36
|
-
|
|
35
|
+
import typer
|
|
37
36
|
|
|
38
|
-
from huggingface_hub.commands import BaseHuggingfaceCLICommand
|
|
39
37
|
from huggingface_hub.constants import ENDPOINT
|
|
40
|
-
from huggingface_hub.
|
|
38
|
+
from huggingface_hub.errors import HfHubHTTPError
|
|
39
|
+
from huggingface_hub.hf_api import whoami
|
|
41
40
|
|
|
42
41
|
from .._login import auth_list, auth_switch, login, logout
|
|
43
|
-
from ..utils import get_stored_tokens, get_token, logging
|
|
44
|
-
from ._cli_utils import
|
|
42
|
+
from ..utils import ANSI, get_stored_tokens, get_token, logging
|
|
43
|
+
from ._cli_utils import TokenOpt, typer_factory
|
|
45
44
|
|
|
46
45
|
|
|
47
46
|
logger = logging.get_logger(__name__)
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
help="Optional: Name of the access token to log out from.",
|
|
90
|
-
)
|
|
91
|
-
logout_parser.set_defaults(func=lambda args: AuthLogout(args))
|
|
92
|
-
|
|
93
|
-
# Add 'whoami' as a subcommand of 'auth'
|
|
94
|
-
whoami_parser = auth_subparsers.add_parser(
|
|
95
|
-
"whoami", help="Find out which huggingface.co account you are logged in as."
|
|
96
|
-
)
|
|
97
|
-
whoami_parser.set_defaults(func=lambda args: AuthWhoami(args))
|
|
98
|
-
|
|
99
|
-
# Existing subcommands
|
|
100
|
-
auth_switch_parser = auth_subparsers.add_parser("switch", help="Switch between access tokens")
|
|
101
|
-
auth_switch_parser.add_argument(
|
|
102
|
-
"--token-name",
|
|
103
|
-
type=str,
|
|
104
|
-
help="Optional: Name of the access token to switch to.",
|
|
105
|
-
)
|
|
106
|
-
auth_switch_parser.add_argument(
|
|
107
|
-
"--add-to-git-credential",
|
|
108
|
-
action="store_true",
|
|
109
|
-
help="Optional: Save token to git credential helper.",
|
|
110
|
-
)
|
|
111
|
-
auth_switch_parser.set_defaults(func=lambda args: AuthSwitch(args))
|
|
112
|
-
|
|
113
|
-
auth_list_parser = auth_subparsers.add_parser("list", help="List all stored access tokens")
|
|
114
|
-
auth_list_parser.set_defaults(func=lambda args: AuthList(args))
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
class BaseAuthCommand:
|
|
118
|
-
def __init__(self, args):
|
|
119
|
-
self.args = args
|
|
120
|
-
self._api = HfApi()
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
class AuthLogin(BaseAuthCommand):
|
|
124
|
-
def run(self):
|
|
125
|
-
logging.set_verbosity_info()
|
|
126
|
-
login(
|
|
127
|
-
token=self.args.token,
|
|
128
|
-
add_to_git_credential=self.args.add_to_git_credential,
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
class AuthLogout(BaseAuthCommand):
|
|
133
|
-
def run(self):
|
|
134
|
-
logging.set_verbosity_info()
|
|
135
|
-
logout(token_name=self.args.token_name)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
class AuthSwitch(BaseAuthCommand):
|
|
139
|
-
def run(self):
|
|
140
|
-
logging.set_verbosity_info()
|
|
141
|
-
token_name = self.args.token_name
|
|
142
|
-
if token_name is None:
|
|
143
|
-
token_name = self._select_token_name()
|
|
144
|
-
|
|
145
|
-
if token_name is None:
|
|
146
|
-
print("No token name provided. Aborting.")
|
|
147
|
-
exit()
|
|
148
|
-
auth_switch(token_name, add_to_git_credential=self.args.add_to_git_credential)
|
|
149
|
-
|
|
150
|
-
def _select_token_name(self) -> Optional[str]:
|
|
151
|
-
token_names = list(get_stored_tokens().keys())
|
|
152
|
-
|
|
153
|
-
if not token_names:
|
|
154
|
-
logger.error("No stored tokens found. Please login first.")
|
|
155
|
-
return None
|
|
156
|
-
|
|
157
|
-
if _inquirer_py_available:
|
|
158
|
-
return self._select_token_name_tui(token_names)
|
|
159
|
-
# if inquirer is not available, use a simpler terminal UI
|
|
160
|
-
print("Available stored tokens:")
|
|
161
|
-
for i, token_name in enumerate(token_names, 1):
|
|
162
|
-
print(f"{i}. {token_name}")
|
|
163
|
-
while True:
|
|
164
|
-
try:
|
|
165
|
-
choice = input("Enter the number of the token to switch to (or 'q' to quit): ")
|
|
166
|
-
if choice.lower() == "q":
|
|
167
|
-
return None
|
|
168
|
-
index = int(choice) - 1
|
|
169
|
-
if 0 <= index < len(token_names):
|
|
170
|
-
return token_names[index]
|
|
171
|
-
else:
|
|
172
|
-
print("Invalid selection. Please try again.")
|
|
173
|
-
except ValueError:
|
|
174
|
-
print("Invalid input. Please enter a number or 'q' to quit.")
|
|
175
|
-
|
|
176
|
-
def _select_token_name_tui(self, token_names: List[str]) -> Optional[str]:
|
|
177
|
-
choices = [Choice(token_name, name=token_name) for token_name in token_names]
|
|
178
|
-
try:
|
|
179
|
-
return inquirer.select(
|
|
180
|
-
message="Select a token to switch to:",
|
|
181
|
-
choices=choices,
|
|
182
|
-
default=None,
|
|
183
|
-
).execute()
|
|
184
|
-
except KeyboardInterrupt:
|
|
185
|
-
logger.info("Token selection cancelled.")
|
|
186
|
-
return None
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
class AuthList(BaseAuthCommand):
|
|
190
|
-
def run(self):
|
|
191
|
-
logging.set_verbosity_info()
|
|
192
|
-
auth_list()
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
class AuthWhoami(BaseAuthCommand):
|
|
196
|
-
def run(self):
|
|
197
|
-
token = get_token()
|
|
198
|
-
if token is None:
|
|
199
|
-
print("Not logged in")
|
|
200
|
-
exit()
|
|
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:
|
|
201
88
|
try:
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
print(
|
|
210
|
-
except
|
|
211
|
-
print(
|
|
212
|
-
|
|
213
|
-
|
|
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)
|