huggingface-hub 0.34.4__py3-none-any.whl → 1.0.0rc0__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 +46 -45
- huggingface_hub/_commit_api.py +28 -28
- huggingface_hub/_commit_scheduler.py +11 -8
- huggingface_hub/_inference_endpoints.py +8 -8
- huggingface_hub/_jobs_api.py +167 -10
- huggingface_hub/_login.py +13 -39
- huggingface_hub/_oauth.py +8 -8
- huggingface_hub/_snapshot_download.py +14 -28
- huggingface_hub/_space_api.py +4 -4
- huggingface_hub/_tensorboard_logger.py +13 -14
- huggingface_hub/_upload_large_folder.py +15 -15
- huggingface_hub/_webhooks_payload.py +3 -3
- huggingface_hub/_webhooks_server.py +2 -2
- huggingface_hub/cli/_cli_utils.py +2 -2
- huggingface_hub/cli/auth.py +5 -6
- huggingface_hub/cli/cache.py +14 -20
- huggingface_hub/cli/download.py +4 -4
- huggingface_hub/cli/jobs.py +560 -11
- huggingface_hub/cli/lfs.py +4 -4
- huggingface_hub/cli/repo.py +7 -7
- huggingface_hub/cli/repo_files.py +2 -2
- huggingface_hub/cli/upload.py +4 -4
- huggingface_hub/cli/upload_large_folder.py +3 -3
- huggingface_hub/commands/_cli_utils.py +2 -2
- huggingface_hub/commands/delete_cache.py +13 -13
- huggingface_hub/commands/download.py +4 -13
- huggingface_hub/commands/lfs.py +4 -4
- huggingface_hub/commands/repo_files.py +2 -2
- huggingface_hub/commands/scan_cache.py +1 -1
- huggingface_hub/commands/tag.py +1 -3
- huggingface_hub/commands/upload.py +4 -4
- huggingface_hub/commands/upload_large_folder.py +3 -3
- huggingface_hub/commands/user.py +5 -6
- huggingface_hub/community.py +5 -5
- huggingface_hub/constants.py +3 -41
- huggingface_hub/dataclasses.py +16 -19
- huggingface_hub/errors.py +42 -29
- huggingface_hub/fastai_utils.py +8 -9
- huggingface_hub/file_download.py +153 -252
- huggingface_hub/hf_api.py +815 -600
- huggingface_hub/hf_file_system.py +98 -62
- huggingface_hub/hub_mixin.py +37 -57
- huggingface_hub/inference/_client.py +177 -325
- huggingface_hub/inference/_common.py +110 -124
- huggingface_hub/inference/_generated/_async_client.py +226 -432
- 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 +18 -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/_cli_hacks.py +3 -3
- huggingface_hub/inference/_mcp/agent.py +3 -3
- huggingface_hub/inference/_mcp/cli.py +1 -1
- huggingface_hub/inference/_mcp/constants.py +2 -3
- huggingface_hub/inference/_mcp/mcp_client.py +58 -30
- huggingface_hub/inference/_mcp/types.py +10 -7
- huggingface_hub/inference/_mcp/utils.py +11 -7
- huggingface_hub/inference/_providers/__init__.py +2 -2
- huggingface_hub/inference/_providers/_common.py +49 -25
- 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 +28 -20
- 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 +20 -31
- huggingface_hub/repocard.py +18 -18
- huggingface_hub/repocard_data.py +56 -56
- 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 +10 -4
- huggingface_hub/utils/_auth.py +5 -5
- huggingface_hub/utils/_cache_manager.py +31 -31
- 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 +4 -4
- huggingface_hub/utils/_headers.py +7 -29
- huggingface_hub/utils/_http.py +366 -208
- huggingface_hub/utils/_pagination.py +4 -4
- huggingface_hub/utils/_paths.py +5 -5
- huggingface_hub/utils/_runtime.py +15 -13
- huggingface_hub/utils/_safetensors.py +21 -21
- huggingface_hub/utils/_subprocess.py +9 -9
- huggingface_hub/utils/_telemetry.py +3 -3
- huggingface_hub/utils/_typing.py +25 -5
- huggingface_hub/utils/_validators.py +53 -72
- huggingface_hub/utils/_xet.py +16 -16
- huggingface_hub/utils/_xet_progress_reporting.py +32 -11
- huggingface_hub/utils/insecure_hashlib.py +3 -9
- huggingface_hub/utils/tqdm.py +3 -3
- {huggingface_hub-0.34.4.dist-info → huggingface_hub-1.0.0rc0.dist-info}/METADATA +18 -29
- huggingface_hub-1.0.0rc0.dist-info/RECORD +161 -0
- 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.34.4.dist-info/RECORD +0 -166
- {huggingface_hub-0.34.4.dist-info → huggingface_hub-1.0.0rc0.dist-info}/LICENSE +0 -0
- {huggingface_hub-0.34.4.dist-info → huggingface_hub-1.0.0rc0.dist-info}/WHEEL +0 -0
- {huggingface_hub-0.34.4.dist-info → huggingface_hub-1.0.0rc0.dist-info}/entry_points.txt +0 -0
- {huggingface_hub-0.34.4.dist-info → huggingface_hub-1.0.0rc0.dist-info}/top_level.txt +0 -0
|
@@ -24,7 +24,7 @@ import traceback
|
|
|
24
24
|
from datetime import datetime
|
|
25
25
|
from pathlib import Path
|
|
26
26
|
from threading import Lock
|
|
27
|
-
from typing import TYPE_CHECKING, Any,
|
|
27
|
+
from typing import TYPE_CHECKING, Any, Optional, Union
|
|
28
28
|
from urllib.parse import quote
|
|
29
29
|
|
|
30
30
|
from . import constants
|
|
@@ -44,7 +44,7 @@ logger = logging.getLogger(__name__)
|
|
|
44
44
|
|
|
45
45
|
WAITING_TIME_IF_NO_TASKS = 10 # seconds
|
|
46
46
|
MAX_NB_FILES_FETCH_UPLOAD_MODE = 100
|
|
47
|
-
COMMIT_SIZE_SCALE:
|
|
47
|
+
COMMIT_SIZE_SCALE: list[int] = [20, 50, 75, 100, 125, 200, 250, 400, 600, 1000]
|
|
48
48
|
|
|
49
49
|
UPLOAD_BATCH_SIZE_XET = 256 # Max 256 files per upload batch for XET-enabled repos
|
|
50
50
|
UPLOAD_BATCH_SIZE_LFS = 1 # Otherwise, batches of 1 for regular LFS upload
|
|
@@ -56,7 +56,7 @@ MAX_FILE_SIZE_GB = 50 # Hard limit for individual file size
|
|
|
56
56
|
RECOMMENDED_FILE_SIZE_GB = 20 # Recommended maximum for individual file size
|
|
57
57
|
|
|
58
58
|
|
|
59
|
-
def _validate_upload_limits(paths_list:
|
|
59
|
+
def _validate_upload_limits(paths_list: list[LocalUploadFilePaths]) -> None:
|
|
60
60
|
"""
|
|
61
61
|
Validate upload against repository limits and warn about potential issues.
|
|
62
62
|
|
|
@@ -85,7 +85,7 @@ def _validate_upload_limits(paths_list: List[LocalUploadFilePaths]) -> None:
|
|
|
85
85
|
# Track immediate children (files and subdirs) for each folder
|
|
86
86
|
from collections import defaultdict
|
|
87
87
|
|
|
88
|
-
entries_per_folder:
|
|
88
|
+
entries_per_folder: dict[str, Any] = defaultdict(lambda: {"files": 0, "subdirs": set()})
|
|
89
89
|
|
|
90
90
|
for paths in paths_list:
|
|
91
91
|
path = Path(paths.path_in_repo)
|
|
@@ -160,8 +160,8 @@ def upload_large_folder_internal(
|
|
|
160
160
|
repo_type: str, # Repo type is required!
|
|
161
161
|
revision: Optional[str] = None,
|
|
162
162
|
private: Optional[bool] = None,
|
|
163
|
-
allow_patterns: Optional[Union[
|
|
164
|
-
ignore_patterns: Optional[Union[
|
|
163
|
+
allow_patterns: Optional[Union[list[str], str]] = None,
|
|
164
|
+
ignore_patterns: Optional[Union[list[str], str]] = None,
|
|
165
165
|
num_workers: Optional[int] = None,
|
|
166
166
|
print_report: bool = True,
|
|
167
167
|
print_report_every: int = 60,
|
|
@@ -284,13 +284,13 @@ class WorkerJob(enum.Enum):
|
|
|
284
284
|
WAIT = enum.auto() # if no tasks are available but we don't want to exit
|
|
285
285
|
|
|
286
286
|
|
|
287
|
-
JOB_ITEM_T =
|
|
287
|
+
JOB_ITEM_T = tuple[LocalUploadFilePaths, LocalUploadFileMetadata]
|
|
288
288
|
|
|
289
289
|
|
|
290
290
|
class LargeUploadStatus:
|
|
291
291
|
"""Contains information, queues and tasks for a large upload process."""
|
|
292
292
|
|
|
293
|
-
def __init__(self, items:
|
|
293
|
+
def __init__(self, items: list[JOB_ITEM_T], upload_batch_size: int = 1):
|
|
294
294
|
self.items = items
|
|
295
295
|
self.queue_sha256: "queue.Queue[JOB_ITEM_T]" = queue.Queue()
|
|
296
296
|
self.queue_get_upload_mode: "queue.Queue[JOB_ITEM_T]" = queue.Queue()
|
|
@@ -423,7 +423,7 @@ def _worker_job(
|
|
|
423
423
|
Read `upload_large_folder` docstring for more information on how tasks are prioritized.
|
|
424
424
|
"""
|
|
425
425
|
while True:
|
|
426
|
-
next_job: Optional[
|
|
426
|
+
next_job: Optional[tuple[WorkerJob, list[JOB_ITEM_T]]] = None
|
|
427
427
|
|
|
428
428
|
# Determine next task
|
|
429
429
|
next_job = _determine_next_job(status)
|
|
@@ -516,7 +516,7 @@ def _worker_job(
|
|
|
516
516
|
status.nb_workers_waiting -= 1
|
|
517
517
|
|
|
518
518
|
|
|
519
|
-
def _determine_next_job(status: LargeUploadStatus) -> Optional[
|
|
519
|
+
def _determine_next_job(status: LargeUploadStatus) -> Optional[tuple[WorkerJob, list[JOB_ITEM_T]]]:
|
|
520
520
|
with status.lock:
|
|
521
521
|
# 1. Commit if more than 5 minutes since last commit attempt (and at least 1 file)
|
|
522
522
|
if (
|
|
@@ -639,7 +639,7 @@ def _compute_sha256(item: JOB_ITEM_T) -> None:
|
|
|
639
639
|
metadata.save(paths)
|
|
640
640
|
|
|
641
641
|
|
|
642
|
-
def _get_upload_mode(items:
|
|
642
|
+
def _get_upload_mode(items: list[JOB_ITEM_T], api: "HfApi", repo_id: str, repo_type: str, revision: str) -> None:
|
|
643
643
|
"""Get upload mode for each file and update metadata.
|
|
644
644
|
|
|
645
645
|
Also receive info if the file should be ignored.
|
|
@@ -661,7 +661,7 @@ def _get_upload_mode(items: List[JOB_ITEM_T], api: "HfApi", repo_id: str, repo_t
|
|
|
661
661
|
metadata.save(paths)
|
|
662
662
|
|
|
663
663
|
|
|
664
|
-
def _preupload_lfs(items:
|
|
664
|
+
def _preupload_lfs(items: list[JOB_ITEM_T], api: "HfApi", repo_id: str, repo_type: str, revision: str) -> None:
|
|
665
665
|
"""Preupload LFS files and update metadata."""
|
|
666
666
|
additions = [_build_hacky_operation(item) for item in items]
|
|
667
667
|
api.preupload_lfs_files(
|
|
@@ -676,7 +676,7 @@ def _preupload_lfs(items: List[JOB_ITEM_T], api: "HfApi", repo_id: str, repo_typ
|
|
|
676
676
|
metadata.save(paths)
|
|
677
677
|
|
|
678
678
|
|
|
679
|
-
def _commit(items:
|
|
679
|
+
def _commit(items: list[JOB_ITEM_T], api: "HfApi", repo_id: str, repo_type: str, revision: str) -> None:
|
|
680
680
|
"""Commit files to the repo."""
|
|
681
681
|
additions = [_build_hacky_operation(item) for item in items]
|
|
682
682
|
api.create_commit(
|
|
@@ -721,11 +721,11 @@ def _build_hacky_operation(item: JOB_ITEM_T) -> HackyCommitOperationAdd:
|
|
|
721
721
|
####################
|
|
722
722
|
|
|
723
723
|
|
|
724
|
-
def _get_one(queue: "queue.Queue[JOB_ITEM_T]") ->
|
|
724
|
+
def _get_one(queue: "queue.Queue[JOB_ITEM_T]") -> list[JOB_ITEM_T]:
|
|
725
725
|
return [queue.get()]
|
|
726
726
|
|
|
727
727
|
|
|
728
|
-
def _get_n(queue: "queue.Queue[JOB_ITEM_T]", n: int) ->
|
|
728
|
+
def _get_n(queue: "queue.Queue[JOB_ITEM_T]", n: int) -> list[JOB_ITEM_T]:
|
|
729
729
|
return [queue.get() for _ in range(min(queue.qsize(), n))]
|
|
730
730
|
|
|
731
731
|
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
"""Contains data structures to parse the webhooks payload."""
|
|
16
16
|
|
|
17
|
-
from typing import
|
|
17
|
+
from typing import Literal, Optional
|
|
18
18
|
|
|
19
19
|
from .utils import is_pydantic_available
|
|
20
20
|
|
|
@@ -116,7 +116,7 @@ class WebhookPayloadRepo(ObjectId):
|
|
|
116
116
|
name: str
|
|
117
117
|
private: bool
|
|
118
118
|
subdomain: Optional[str] = None
|
|
119
|
-
tags: Optional[
|
|
119
|
+
tags: Optional[list[str]] = None
|
|
120
120
|
type: Literal["dataset", "model", "space"]
|
|
121
121
|
url: WebhookPayloadUrl
|
|
122
122
|
|
|
@@ -134,4 +134,4 @@ class WebhookPayload(BaseModel):
|
|
|
134
134
|
comment: Optional[WebhookPayloadComment] = None
|
|
135
135
|
webhook: WebhookPayloadWebhook
|
|
136
136
|
movedTo: Optional[WebhookPayloadMovedTo] = None
|
|
137
|
-
updatedRefs: Optional[
|
|
137
|
+
updatedRefs: Optional[list[WebhookPayloadUpdatedRef]] = None
|
|
@@ -18,7 +18,7 @@ import atexit
|
|
|
18
18
|
import inspect
|
|
19
19
|
import os
|
|
20
20
|
from functools import wraps
|
|
21
|
-
from typing import TYPE_CHECKING, Any, Callable,
|
|
21
|
+
from typing import TYPE_CHECKING, Any, Callable, Optional
|
|
22
22
|
|
|
23
23
|
from .utils import experimental, is_fastapi_available, is_gradio_available
|
|
24
24
|
|
|
@@ -115,7 +115,7 @@ class WebhooksServer:
|
|
|
115
115
|
self._ui = ui
|
|
116
116
|
|
|
117
117
|
self.webhook_secret = webhook_secret or os.getenv("WEBHOOK_SECRET")
|
|
118
|
-
self.registered_webhooks:
|
|
118
|
+
self.registered_webhooks: dict[str, Callable] = {}
|
|
119
119
|
_warn_on_empty_secret(self.webhook_secret)
|
|
120
120
|
|
|
121
121
|
def add_webhook(self, path: Optional[str] = None) -> Callable:
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"""Contains a utility for good-looking prints."""
|
|
15
15
|
|
|
16
16
|
import os
|
|
17
|
-
from typing import
|
|
17
|
+
from typing import Union
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
class ANSI:
|
|
@@ -52,7 +52,7 @@ class ANSI:
|
|
|
52
52
|
return f"{code}{s}{cls._reset}"
|
|
53
53
|
|
|
54
54
|
|
|
55
|
-
def tabulate(rows:
|
|
55
|
+
def tabulate(rows: list[list[Union[str, int]]], headers: list[str]) -> str:
|
|
56
56
|
"""
|
|
57
57
|
Inspired by:
|
|
58
58
|
|
huggingface_hub/cli/auth.py
CHANGED
|
@@ -31,12 +31,11 @@ Usage:
|
|
|
31
31
|
"""
|
|
32
32
|
|
|
33
33
|
from argparse import _SubParsersAction
|
|
34
|
-
from typing import
|
|
35
|
-
|
|
36
|
-
from requests.exceptions import HTTPError
|
|
34
|
+
from typing import Optional
|
|
37
35
|
|
|
38
36
|
from huggingface_hub.commands import BaseHuggingfaceCLICommand
|
|
39
37
|
from huggingface_hub.constants import ENDPOINT
|
|
38
|
+
from huggingface_hub.errors import HfHubHTTPError
|
|
40
39
|
from huggingface_hub.hf_api import HfApi
|
|
41
40
|
|
|
42
41
|
from .._login import auth_list, auth_switch, login, logout
|
|
@@ -173,7 +172,7 @@ class AuthSwitch(BaseAuthCommand):
|
|
|
173
172
|
except ValueError:
|
|
174
173
|
print("Invalid input. Please enter a number or 'q' to quit.")
|
|
175
174
|
|
|
176
|
-
def _select_token_name_tui(self, token_names:
|
|
175
|
+
def _select_token_name_tui(self, token_names: list[str]) -> Optional[str]:
|
|
177
176
|
choices = [Choice(token_name, name=token_name) for token_name in token_names]
|
|
178
177
|
try:
|
|
179
178
|
return inquirer.select(
|
|
@@ -200,14 +199,14 @@ class AuthWhoami(BaseAuthCommand):
|
|
|
200
199
|
exit()
|
|
201
200
|
try:
|
|
202
201
|
info = self._api.whoami(token)
|
|
203
|
-
print(info["name"])
|
|
202
|
+
print(ANSI.bold("user: "), info["name"])
|
|
204
203
|
orgs = [org["name"] for org in info["orgs"]]
|
|
205
204
|
if orgs:
|
|
206
205
|
print(ANSI.bold("orgs: "), ",".join(orgs))
|
|
207
206
|
|
|
208
207
|
if ENDPOINT != "https://huggingface.co":
|
|
209
208
|
print(f"Authenticated through private endpoint: {ENDPOINT}")
|
|
210
|
-
except
|
|
209
|
+
except HfHubHTTPError as e:
|
|
211
210
|
print(e)
|
|
212
211
|
print(ANSI.red(e.response.text))
|
|
213
212
|
exit(1)
|
huggingface_hub/cli/cache.py
CHANGED
|
@@ -19,15 +19,9 @@ import time
|
|
|
19
19
|
from argparse import Namespace, _SubParsersAction
|
|
20
20
|
from functools import wraps
|
|
21
21
|
from tempfile import mkstemp
|
|
22
|
-
from typing import Any, Callable, Iterable,
|
|
23
|
-
|
|
24
|
-
from ..utils import
|
|
25
|
-
CachedRepoInfo,
|
|
26
|
-
CachedRevisionInfo,
|
|
27
|
-
CacheNotFound,
|
|
28
|
-
HFCacheInfo,
|
|
29
|
-
scan_cache_dir,
|
|
30
|
-
)
|
|
22
|
+
from typing import Any, Callable, Iterable, Literal, Optional, Union
|
|
23
|
+
|
|
24
|
+
from ..utils import CachedRepoInfo, CachedRevisionInfo, CacheNotFound, HFCacheInfo, scan_cache_dir
|
|
31
25
|
from . import BaseHuggingfaceCLICommand
|
|
32
26
|
from ._cli_utils import ANSI, tabulate
|
|
33
27
|
|
|
@@ -52,7 +46,7 @@ def require_inquirer_py(fn: Callable) -> Callable:
|
|
|
52
46
|
if not _inquirer_py_available:
|
|
53
47
|
raise ImportError(
|
|
54
48
|
"The 'cache delete' command requires extra dependencies for the TUI.\n"
|
|
55
|
-
"Please run 'pip install huggingface_hub[cli]' to install them.\n"
|
|
49
|
+
"Please run 'pip install \"huggingface_hub[cli]\"' to install them.\n"
|
|
56
50
|
"Otherwise, disable TUI using the '--disable-tui' flag."
|
|
57
51
|
)
|
|
58
52
|
return fn(*args, **kwargs)
|
|
@@ -149,7 +143,7 @@ class CacheCommand(BaseHuggingfaceCLICommand):
|
|
|
149
143
|
if self.verbosity >= 3:
|
|
150
144
|
print(ANSI.gray(message))
|
|
151
145
|
for warning in hf_cache_info.warnings:
|
|
152
|
-
print(ANSI.gray(warning))
|
|
146
|
+
print(ANSI.gray(str(warning)))
|
|
153
147
|
else:
|
|
154
148
|
print(ANSI.gray(message + " Use -vvv to print details."))
|
|
155
149
|
|
|
@@ -249,8 +243,8 @@ def _get_repo_sorting_key(repo: CachedRepoInfo, sort_by: Optional[SortingOption_
|
|
|
249
243
|
|
|
250
244
|
@require_inquirer_py
|
|
251
245
|
def _manual_review_tui(
|
|
252
|
-
hf_cache_info: HFCacheInfo, preselected:
|
|
253
|
-
) ->
|
|
246
|
+
hf_cache_info: HFCacheInfo, preselected: list[str], sort_by: Optional[SortingOption_T] = None
|
|
247
|
+
) -> list[str]:
|
|
254
248
|
choices = _get_tui_choices_from_scan(repos=hf_cache_info.repos, preselected=preselected, sort_by=sort_by)
|
|
255
249
|
checkbox = inquirer.checkbox(
|
|
256
250
|
message="Select revisions to delete:",
|
|
@@ -283,9 +277,9 @@ def _ask_for_confirmation_tui(message: str, default: bool = True) -> bool:
|
|
|
283
277
|
|
|
284
278
|
|
|
285
279
|
def _get_tui_choices_from_scan(
|
|
286
|
-
repos: Iterable[CachedRepoInfo], preselected:
|
|
287
|
-
) ->
|
|
288
|
-
choices:
|
|
280
|
+
repos: Iterable[CachedRepoInfo], preselected: list[str], sort_by: Optional[SortingOption_T] = None
|
|
281
|
+
) -> list:
|
|
282
|
+
choices: list[Union["Choice", "Separator"]] = []
|
|
289
283
|
choices.append(
|
|
290
284
|
Choice(
|
|
291
285
|
_CANCEL_DELETION_STR, name="None of the following (if selected, nothing will be deleted).", enabled=False
|
|
@@ -312,8 +306,8 @@ def _get_tui_choices_from_scan(
|
|
|
312
306
|
|
|
313
307
|
|
|
314
308
|
def _manual_review_no_tui(
|
|
315
|
-
hf_cache_info: HFCacheInfo, preselected:
|
|
316
|
-
) ->
|
|
309
|
+
hf_cache_info: HFCacheInfo, preselected: list[str], sort_by: Optional[SortingOption_T] = None
|
|
310
|
+
) -> list[str]:
|
|
317
311
|
fd, tmp_path = mkstemp(suffix=".txt")
|
|
318
312
|
os.close(fd)
|
|
319
313
|
lines = []
|
|
@@ -364,14 +358,14 @@ def _ask_for_confirmation_no_tui(message: str, default: bool = True) -> bool:
|
|
|
364
358
|
print(f"Invalid input. Must be one of {ALL}")
|
|
365
359
|
|
|
366
360
|
|
|
367
|
-
def _get_expectations_str(hf_cache_info: HFCacheInfo, selected_hashes:
|
|
361
|
+
def _get_expectations_str(hf_cache_info: HFCacheInfo, selected_hashes: list[str]) -> str:
|
|
368
362
|
if _CANCEL_DELETION_STR in selected_hashes:
|
|
369
363
|
return "Nothing will be deleted."
|
|
370
364
|
strategy = hf_cache_info.delete_revisions(*selected_hashes)
|
|
371
365
|
return f"{len(selected_hashes)} revisions selected counting for {strategy.expected_freed_size_str}."
|
|
372
366
|
|
|
373
367
|
|
|
374
|
-
def _read_manual_review_tmp_file(tmp_path: str) ->
|
|
368
|
+
def _read_manual_review_tmp_file(tmp_path: str) -> list[str]:
|
|
375
369
|
with open(tmp_path) as f:
|
|
376
370
|
content = f.read()
|
|
377
371
|
lines = [line.strip() for line in content.split("\n")]
|
huggingface_hub/cli/download.py
CHANGED
|
@@ -38,7 +38,7 @@ Usage:
|
|
|
38
38
|
|
|
39
39
|
import warnings
|
|
40
40
|
from argparse import Namespace, _SubParsersAction
|
|
41
|
-
from typing import
|
|
41
|
+
from typing import Optional
|
|
42
42
|
|
|
43
43
|
from huggingface_hub import logging
|
|
44
44
|
from huggingface_hub._snapshot_download import snapshot_download
|
|
@@ -113,11 +113,11 @@ class DownloadCommand(BaseHuggingfaceCLICommand):
|
|
|
113
113
|
def __init__(self, args: Namespace) -> None:
|
|
114
114
|
self.token = args.token
|
|
115
115
|
self.repo_id: str = args.repo_id
|
|
116
|
-
self.filenames:
|
|
116
|
+
self.filenames: list[str] = args.filenames
|
|
117
117
|
self.repo_type: str = args.repo_type
|
|
118
118
|
self.revision: Optional[str] = args.revision
|
|
119
|
-
self.include: Optional[
|
|
120
|
-
self.exclude: Optional[
|
|
119
|
+
self.include: Optional[list[str]] = args.include
|
|
120
|
+
self.exclude: Optional[list[str]] = args.exclude
|
|
121
121
|
self.cache_dir: Optional[str] = args.cache_dir
|
|
122
122
|
self.local_dir: Optional[str] = args.local_dir
|
|
123
123
|
self.force_download: bool = args.force_download
|