huggingface-hub 1.0.0rc0__py3-none-any.whl → 1.0.0rc2__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.

Files changed (48) hide show
  1. huggingface_hub/__init__.py +4 -4
  2. huggingface_hub/_commit_api.py +126 -66
  3. huggingface_hub/_commit_scheduler.py +4 -7
  4. huggingface_hub/_login.py +9 -15
  5. huggingface_hub/_tensorboard_logger.py +2 -5
  6. huggingface_hub/_webhooks_server.py +8 -20
  7. huggingface_hub/cli/__init__.py +0 -14
  8. huggingface_hub/cli/_cli_utils.py +79 -2
  9. huggingface_hub/cli/auth.py +104 -149
  10. huggingface_hub/cli/cache.py +97 -121
  11. huggingface_hub/cli/download.py +93 -110
  12. huggingface_hub/cli/hf.py +37 -41
  13. huggingface_hub/cli/jobs.py +687 -1014
  14. huggingface_hub/cli/lfs.py +116 -139
  15. huggingface_hub/cli/repo.py +290 -214
  16. huggingface_hub/cli/repo_files.py +50 -84
  17. huggingface_hub/cli/system.py +6 -25
  18. huggingface_hub/cli/upload.py +198 -212
  19. huggingface_hub/cli/upload_large_folder.py +90 -105
  20. huggingface_hub/dataclasses.py +3 -12
  21. huggingface_hub/errors.py +1 -1
  22. huggingface_hub/fastai_utils.py +22 -32
  23. huggingface_hub/file_download.py +18 -21
  24. huggingface_hub/hf_api.py +258 -410
  25. huggingface_hub/hf_file_system.py +17 -44
  26. huggingface_hub/inference/_client.py +25 -47
  27. huggingface_hub/inference/_generated/_async_client.py +25 -47
  28. huggingface_hub/inference/_mcp/agent.py +2 -5
  29. huggingface_hub/inference/_mcp/mcp_client.py +2 -5
  30. huggingface_hub/inference/_providers/__init__.py +11 -0
  31. huggingface_hub/inference/_providers/_common.py +1 -0
  32. huggingface_hub/inference/_providers/publicai.py +6 -0
  33. huggingface_hub/inference/_providers/scaleway.py +28 -0
  34. huggingface_hub/lfs.py +14 -8
  35. huggingface_hub/repocard.py +12 -16
  36. huggingface_hub/serialization/_base.py +3 -6
  37. huggingface_hub/serialization/_torch.py +16 -34
  38. huggingface_hub/utils/__init__.py +1 -1
  39. huggingface_hub/utils/_cache_manager.py +41 -71
  40. huggingface_hub/utils/_chunk_utils.py +2 -3
  41. huggingface_hub/utils/_http.py +32 -35
  42. huggingface_hub/utils/logging.py +8 -11
  43. {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/METADATA +7 -2
  44. {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/RECORD +48 -46
  45. {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/LICENSE +0 -0
  46. {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/WHEEL +0 -0
  47. {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/entry_points.txt +0 -0
  48. {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/top_level.txt +0 -0
huggingface_hub/hf_api.py CHANGED
@@ -15,7 +15,6 @@
15
15
  from __future__ import annotations
16
16
 
17
17
  import inspect
18
- import io
19
18
  import json
20
19
  import re
21
20
  import struct
@@ -42,7 +41,7 @@ from typing import (
42
41
  Union,
43
42
  overload,
44
43
  )
45
- from urllib.parse import quote, unquote
44
+ from urllib.parse import quote
46
45
 
47
46
  import httpx
48
47
  from tqdm.auto import tqdm as base_tqdm
@@ -57,8 +56,7 @@ from ._commit_api import (
57
56
  _fetch_files_to_copy,
58
57
  _fetch_upload_modes,
59
58
  _prepare_commit_payload,
60
- _upload_lfs_files,
61
- _upload_xet_files,
59
+ _upload_files,
62
60
  _warn_on_overwriting_operations,
63
61
  )
64
62
  from ._inference_endpoints import InferenceEndpoint, InferenceEndpointType
@@ -104,13 +102,8 @@ from .utils import (
104
102
  validate_hf_hub_args,
105
103
  )
106
104
  from .utils import tqdm as hf_tqdm
107
- from .utils._auth import (
108
- _get_token_from_environment,
109
- _get_token_from_file,
110
- _get_token_from_google_colab,
111
- )
105
+ from .utils._auth import _get_token_from_environment, _get_token_from_file, _get_token_from_google_colab
112
106
  from .utils._deprecation import _deprecate_arguments
113
- from .utils._runtime import is_xet_available
114
107
  from .utils._typing import CallableT
115
108
  from .utils.endpoint_helpers import _is_emission_within_threshold
116
109
 
@@ -562,15 +555,12 @@ class RepoSibling:
562
555
  """
563
556
  Contains basic information about a repo file inside a repo on the Hub.
564
557
 
565
- <Tip>
566
-
567
- All attributes of this class are optional except `rfilename`. This is because only the file names are returned when
568
- listing repositories on the Hub (with [`list_models`], [`list_datasets`] or [`list_spaces`]). If you need more
569
- information like file size, blob id or lfs details, you must request them specifically from one repo at a time
570
- (using [`model_info`], [`dataset_info`] or [`space_info`]) as it adds more constraints on the backend server to
571
- retrieve these.
572
-
573
- </Tip>
558
+ > [!TIP]
559
+ > All attributes of this class are optional except `rfilename`. This is because only the file names are returned when
560
+ > listing repositories on the Hub (with [`list_models`], [`list_datasets`] or [`list_spaces`]). If you need more
561
+ > information like file size, blob id or lfs details, you must request them specifically from one repo at a time
562
+ > (using [`model_info`], [`dataset_info`] or [`space_info`]) as it adds more constraints on the backend server to
563
+ > retrieve these.
574
564
 
575
565
  Attributes:
576
566
  rfilename (str):
@@ -711,13 +701,10 @@ class ModelInfo:
711
701
  """
712
702
  Contains information about a model on the Hub. This object is returned by [`model_info`] and [`list_models`].
713
703
 
714
- <Tip>
715
-
716
- Most attributes of this class are optional. This is because the data returned by the Hub depends on the query made.
717
- In general, the more specific the query, the more information is returned. On the contrary, when listing models
718
- using [`list_models`] only a subset of the attributes are returned.
719
-
720
- </Tip>
704
+ > [!TIP]
705
+ > Most attributes of this class are optional. This is because the data returned by the Hub depends on the query made.
706
+ > In general, the more specific the query, the more information is returned. On the contrary, when listing models
707
+ > using [`list_models`] only a subset of the attributes are returned.
721
708
 
722
709
  Attributes:
723
710
  id (`str`):
@@ -910,13 +897,10 @@ class DatasetInfo:
910
897
  """
911
898
  Contains information about a dataset on the Hub. This object is returned by [`dataset_info`] and [`list_datasets`].
912
899
 
913
- <Tip>
914
-
915
- Most attributes of this class are optional. This is because the data returned by the Hub depends on the query made.
916
- In general, the more specific the query, the more information is returned. On the contrary, when listing datasets
917
- using [`list_datasets`] only a subset of the attributes are returned.
918
-
919
- </Tip>
900
+ > [!TIP]
901
+ > Most attributes of this class are optional. This is because the data returned by the Hub depends on the query made.
902
+ > In general, the more specific the query, the more information is returned. On the contrary, when listing datasets
903
+ > using [`list_datasets`] only a subset of the attributes are returned.
920
904
 
921
905
  Attributes:
922
906
  id (`str`):
@@ -1029,13 +1013,10 @@ class SpaceInfo:
1029
1013
  """
1030
1014
  Contains information about a Space on the Hub. This object is returned by [`space_info`] and [`list_spaces`].
1031
1015
 
1032
- <Tip>
1033
-
1034
- Most attributes of this class are optional. This is because the data returned by the Hub depends on the query made.
1035
- In general, the more specific the query, the more information is returned. On the contrary, when listing spaces
1036
- using [`list_spaces`] only a subset of the attributes are returned.
1037
-
1038
- </Tip>
1016
+ > [!TIP]
1017
+ > Most attributes of this class are optional. This is because the data returned by the Hub depends on the query made.
1018
+ > In general, the more specific the query, the more information is returned. On the contrary, when listing spaces
1019
+ > using [`list_spaces`] only a subset of the attributes are returned.
1039
1020
 
1040
1021
  Attributes:
1041
1022
  id (`str`):
@@ -2512,17 +2493,14 @@ class HfApi:
2512
2493
  Returns:
2513
2494
  [`huggingface_hub.hf_api.ModelInfo`]: The model repository information.
2514
2495
 
2515
- <Tip>
2516
-
2517
- Raises the following errors:
2518
-
2519
- - [`~utils.RepositoryNotFoundError`]
2520
- If the repository to download from cannot be found. This may be because it doesn't exist,
2521
- or because it is set to `private` and you do not have access.
2522
- - [`~utils.RevisionNotFoundError`]
2523
- If the revision to download from cannot be found.
2524
-
2525
- </Tip>
2496
+ > [!TIP]
2497
+ > Raises the following errors:
2498
+ >
2499
+ > - [`~utils.RepositoryNotFoundError`]
2500
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
2501
+ > or because it is set to `private` and you do not have access.
2502
+ > - [`~utils.RevisionNotFoundError`]
2503
+ > If the revision to download from cannot be found.
2526
2504
  """
2527
2505
  if expand and (securityStatus or files_metadata):
2528
2506
  raise ValueError("`expand` cannot be used if `securityStatus` or `files_metadata` are set.")
@@ -2586,17 +2564,14 @@ class HfApi:
2586
2564
  Returns:
2587
2565
  [`hf_api.DatasetInfo`]: The dataset repository information.
2588
2566
 
2589
- <Tip>
2590
-
2591
- Raises the following errors:
2592
-
2593
- - [`~utils.RepositoryNotFoundError`]
2594
- If the repository to download from cannot be found. This may be because it doesn't exist,
2595
- or because it is set to `private` and you do not have access.
2596
- - [`~utils.RevisionNotFoundError`]
2597
- If the revision to download from cannot be found.
2598
-
2599
- </Tip>
2567
+ > [!TIP]
2568
+ > Raises the following errors:
2569
+ >
2570
+ > - [`~utils.RepositoryNotFoundError`]
2571
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
2572
+ > or because it is set to `private` and you do not have access.
2573
+ > - [`~utils.RevisionNotFoundError`]
2574
+ > If the revision to download from cannot be found.
2600
2575
  """
2601
2576
  if expand and files_metadata:
2602
2577
  raise ValueError("`expand` cannot be used if `files_metadata` is set.")
@@ -2659,17 +2634,14 @@ class HfApi:
2659
2634
  Returns:
2660
2635
  [`~hf_api.SpaceInfo`]: The space repository information.
2661
2636
 
2662
- <Tip>
2663
-
2664
- Raises the following errors:
2665
-
2666
- - [`~utils.RepositoryNotFoundError`]
2667
- If the repository to download from cannot be found. This may be because it doesn't exist,
2668
- or because it is set to `private` and you do not have access.
2669
- - [`~utils.RevisionNotFoundError`]
2670
- If the revision to download from cannot be found.
2671
-
2672
- </Tip>
2637
+ > [!TIP]
2638
+ > Raises the following errors:
2639
+ >
2640
+ > - [`~utils.RepositoryNotFoundError`]
2641
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
2642
+ > or because it is set to `private` and you do not have access.
2643
+ > - [`~utils.RevisionNotFoundError`]
2644
+ > If the revision to download from cannot be found.
2673
2645
  """
2674
2646
  if expand and files_metadata:
2675
2647
  raise ValueError("`expand` cannot be used if `files_metadata` is set.")
@@ -2736,17 +2708,14 @@ class HfApi:
2736
2708
  [`huggingface_hub.hf_api.DatasetInfo`], [`huggingface_hub.hf_api.ModelInfo`]
2737
2709
  or [`huggingface_hub.hf_api.SpaceInfo`] object.
2738
2710
 
2739
- <Tip>
2740
-
2741
- Raises the following errors:
2742
-
2743
- - [`~utils.RepositoryNotFoundError`]
2744
- If the repository to download from cannot be found. This may be because it doesn't exist,
2745
- or because it is set to `private` and you do not have access.
2746
- - [`~utils.RevisionNotFoundError`]
2747
- If the revision to download from cannot be found.
2748
-
2749
- </Tip>
2711
+ > [!TIP]
2712
+ > Raises the following errors:
2713
+ >
2714
+ > - [`~utils.RepositoryNotFoundError`]
2715
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
2716
+ > or because it is set to `private` and you do not have access.
2717
+ > - [`~utils.RevisionNotFoundError`]
2718
+ > If the revision to download from cannot be found.
2750
2719
  """
2751
2720
  if repo_type is None or repo_type == "model":
2752
2721
  method = self.model_info
@@ -3333,18 +3302,12 @@ class HfApi:
3333
3302
  Squashing the repo history is useful when you know you'll make hundreds of commits and you don't want to
3334
3303
  clutter the history. Squashing commits can only be performed from the head of a branch.
3335
3304
 
3336
- <Tip warning={true}>
3337
-
3338
- Once squashed, the commit history cannot be retrieved. This is a non-revertible operation.
3305
+ > [!WARNING]
3306
+ > Once squashed, the commit history cannot be retrieved. This is a non-revertible operation.
3339
3307
 
3340
- </Tip>
3341
-
3342
- <Tip warning={true}>
3343
-
3344
- Once the history of a branch has been squashed, it is not possible to merge it back into another branch since
3345
- their history will have diverged.
3346
-
3347
- </Tip>
3308
+ > [!WARNING]
3309
+ > Once the history of a branch has been squashed, it is not possible to merge it back into another branch since
3310
+ > their history will have diverged.
3348
3311
 
3349
3312
  Args:
3350
3313
  repo_id (`str`):
@@ -3471,12 +3434,9 @@ class HfApi:
3471
3434
  """
3472
3435
  Permanently delete LFS files from a repo on the Hub.
3473
3436
 
3474
- <Tip warning={true}>
3475
-
3476
- This is a permanent action that will affect all commits referencing the deleted files and might corrupt your
3477
- repository. This is a non-revertible operation. Use it only if you know what you are doing.
3478
-
3479
- </Tip>
3437
+ > [!WARNING]
3438
+ > This is a permanent action that will affect all commits referencing the deleted files and might corrupt your
3439
+ > repository. This is a non-revertible operation. Use it only if you know what you are doing.
3480
3440
 
3481
3441
  Args:
3482
3442
  repo_id (`str`):
@@ -3841,15 +3801,12 @@ class HfApi:
3841
3801
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
3842
3802
  To disable authentication, pass `False`.
3843
3803
 
3844
- <Tip>
3845
-
3846
- Raises the following errors:
3847
-
3848
- - [`~utils.RepositoryNotFoundError`]
3849
- If the repository to download from cannot be found. This may be because it doesn't exist,
3850
- or because it is set to `private` and you do not have access.
3851
-
3852
- </Tip>
3804
+ > [!TIP]
3805
+ > Raises the following errors:
3806
+ >
3807
+ > - [`~utils.RepositoryNotFoundError`]
3808
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
3809
+ > or because it is set to `private` and you do not have access.
3853
3810
  """
3854
3811
  if len(from_id.split("/")) != 2:
3855
3812
  raise ValueError(f"Invalid repo_id: {from_id}. It should have a namespace (:namespace:/:repo_name:)")
@@ -3928,27 +3885,18 @@ class HfApi:
3928
3885
  """
3929
3886
  Creates a commit in the given repo, deleting & uploading files as needed.
3930
3887
 
3931
- <Tip warning={true}>
3932
-
3933
- The input list of `CommitOperation` will be mutated during the commit process. Do not reuse the same objects
3934
- for multiple commits.
3935
-
3936
- </Tip>
3937
-
3938
- <Tip warning={true}>
3939
-
3940
- `create_commit` assumes that the repo already exists on the Hub. If you get a
3941
- Client error 404, please make sure you are authenticated and that `repo_id` and
3942
- `repo_type` are set correctly. If repo does not exist, create it first using
3943
- [`~hf_api.create_repo`].
3888
+ > [!WARNING]
3889
+ > The input list of `CommitOperation` will be mutated during the commit process. Do not reuse the same objects
3890
+ > for multiple commits.
3944
3891
 
3945
- </Tip>
3892
+ > [!WARNING]
3893
+ > `create_commit` assumes that the repo already exists on the Hub. If you get a
3894
+ > Client error 404, please make sure you are authenticated and that `repo_id` and
3895
+ > `repo_type` are set correctly. If repo does not exist, create it first using
3896
+ > [`~hf_api.create_repo`].
3946
3897
 
3947
- <Tip warning={true}>
3948
-
3949
- `create_commit` is limited to 25k LFS files and a 1GB payload for regular files.
3950
-
3951
- </Tip>
3898
+ > [!WARNING]
3899
+ > `create_commit` is limited to 25k LFS files and a 1GB payload for regular files.
3952
3900
 
3953
3901
  Args:
3954
3902
  repo_id (`str`):
@@ -4222,21 +4170,15 @@ class HfApi:
4222
4170
  This method is useful if you are generating the files to upload on-the-fly and you don't want to store them
4223
4171
  in memory before uploading them all at once.
4224
4172
 
4225
- <Tip warning={true}>
4226
-
4227
- This is a power-user method. You shouldn't need to call it directly to make a normal commit.
4228
- Use [`create_commit`] directly instead.
4229
-
4230
- </Tip>
4173
+ > [!WARNING]
4174
+ > This is a power-user method. You shouldn't need to call it directly to make a normal commit.
4175
+ > Use [`create_commit`] directly instead.
4231
4176
 
4232
- <Tip warning={true}>
4233
-
4234
- Commit operations will be mutated during the process. In particular, the attached `path_or_fileobj` will be
4235
- removed after the upload to save memory (and replaced by an empty `bytes` object). Do not reuse the same
4236
- objects except to pass them to [`create_commit`]. If you don't want to remove the attached content from the
4237
- commit operation object, pass `free_memory=False`.
4238
-
4239
- </Tip>
4177
+ > [!WARNING]
4178
+ > Commit operations will be mutated during the process. In particular, the attached `path_or_fileobj` will be
4179
+ > removed after the upload to save memory (and replaced by an empty `bytes` object). Do not reuse the same
4180
+ > objects except to pass them to [`create_commit`]. If you don't want to remove the attached content from the
4181
+ > commit operation object, pass `free_memory=False`.
4240
4182
 
4241
4183
  Args:
4242
4184
  repo_id (`str`):
@@ -4342,6 +4284,10 @@ class HfApi:
4342
4284
  f"Skipped upload for {len(new_lfs_additions) - len(new_lfs_additions_to_upload)} LFS file(s) "
4343
4285
  "(ignored by gitignore file)."
4344
4286
  )
4287
+ # If no LFS files remain to upload, keep previous behavior and log explicitly
4288
+ if len(new_lfs_additions_to_upload) == 0:
4289
+ logger.debug("No LFS files to upload.")
4290
+ return
4345
4291
  # Prepare upload parameters
4346
4292
  upload_kwargs = {
4347
4293
  "additions": new_lfs_additions_to_upload,
@@ -4354,32 +4300,7 @@ class HfApi:
4354
4300
  # PR (i.e. `revision`).
4355
4301
  "revision": revision if not create_pr else None,
4356
4302
  }
4357
- # Upload files using Xet protocol if all of the following are true:
4358
- # - xet is enabled for the repo,
4359
- # - the files are provided as str or paths objects,
4360
- # - the library is installed.
4361
- # Otherwise, default back to LFS.
4362
- xet_enabled = self.repo_info(
4363
- repo_id=repo_id,
4364
- repo_type=repo_type,
4365
- revision=unquote(revision) if revision is not None else revision,
4366
- expand="xetEnabled",
4367
- token=token,
4368
- ).xet_enabled
4369
- has_buffered_io_data = any(
4370
- isinstance(addition.path_or_fileobj, io.BufferedIOBase) for addition in new_lfs_additions_to_upload
4371
- )
4372
- if xet_enabled and not has_buffered_io_data and is_xet_available():
4373
- logger.debug("Uploading files using Xet Storage..")
4374
- _upload_xet_files(**upload_kwargs, create_pr=create_pr) # type: ignore [arg-type]
4375
- else:
4376
- if xet_enabled and is_xet_available():
4377
- if has_buffered_io_data:
4378
- logger.warning(
4379
- "Uploading files as a binary IO buffer is not supported by Xet Storage. "
4380
- "Falling back to HTTP upload."
4381
- )
4382
- _upload_lfs_files(**upload_kwargs, num_threads=num_threads) # type: ignore [arg-type]
4303
+ _upload_files(**upload_kwargs, num_threads=num_threads, create_pr=create_pr) # type: ignore [arg-type]
4383
4304
  for addition in new_lfs_additions_to_upload:
4384
4305
  addition._is_uploaded = True
4385
4306
  if free_memory:
@@ -4489,30 +4410,24 @@ class HfApi:
4489
4410
  Instance of [`CommitInfo`] containing information about the newly created commit (commit hash, commit
4490
4411
  url, pr url, commit message,...). If `run_as_future=True` is passed, returns a Future object which will
4491
4412
  contain the result when executed.
4492
- <Tip>
4493
-
4494
- Raises the following errors:
4495
-
4496
- - [`HfHubHTTPError`]
4497
- if the HuggingFace API returned an error
4498
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
4499
- if some parameter value is invalid
4500
- - [`~utils.RepositoryNotFoundError`]
4501
- If the repository to download from cannot be found. This may be because it doesn't exist,
4502
- or because it is set to `private` and you do not have access.
4503
- - [`~utils.RevisionNotFoundError`]
4504
- If the revision to download from cannot be found.
4505
-
4506
- </Tip>
4507
-
4508
- <Tip warning={true}>
4509
-
4510
- `upload_file` assumes that the repo already exists on the Hub. If you get a
4511
- Client error 404, please make sure you are authenticated and that `repo_id` and
4512
- `repo_type` are set correctly. If repo does not exist, create it first using
4513
- [`~hf_api.create_repo`].
4514
-
4515
- </Tip>
4413
+ > [!TIP]
4414
+ > Raises the following errors:
4415
+ >
4416
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
4417
+ > if the HuggingFace API returned an error
4418
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
4419
+ > if some parameter value is invalid
4420
+ > - [`~utils.RepositoryNotFoundError`]
4421
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
4422
+ > or because it is set to `private` and you do not have access.
4423
+ > - [`~utils.RevisionNotFoundError`]
4424
+ > If the revision to download from cannot be found.
4425
+
4426
+ > [!WARNING]
4427
+ > `upload_file` assumes that the repo already exists on the Hub. If you get a
4428
+ > Client error 404, please make sure you are authenticated and that `repo_id` and
4429
+ > `repo_type` are set correctly. If repo does not exist, create it first using
4430
+ > [`~hf_api.create_repo`].
4516
4431
 
4517
4432
  Example:
4518
4433
 
@@ -4705,30 +4620,21 @@ class HfApi:
4705
4620
  url, pr url, commit message,...). If `run_as_future=True` is passed, returns a Future object which will
4706
4621
  contain the result when executed.
4707
4622
 
4708
- <Tip>
4623
+ > [!TIP]
4624
+ > Raises the following errors:
4625
+ >
4626
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
4627
+ > if the HuggingFace API returned an error
4628
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
4629
+ > if some parameter value is invalid
4709
4630
 
4710
- Raises the following errors:
4631
+ > [!WARNING]
4632
+ > `upload_folder` assumes that the repo already exists on the Hub. If you get a Client error 404, please make
4633
+ > sure you are authenticated and that `repo_id` and `repo_type` are set correctly. If repo does not exist, create
4634
+ > it first using [`~hf_api.create_repo`].
4711
4635
 
4712
- - [`HfHubHTTPError`]
4713
- if the HuggingFace API returned an error
4714
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
4715
- if some parameter value is invalid
4716
-
4717
- </Tip>
4718
-
4719
- <Tip warning={true}>
4720
-
4721
- `upload_folder` assumes that the repo already exists on the Hub. If you get a Client error 404, please make
4722
- sure you are authenticated and that `repo_id` and `repo_type` are set correctly. If repo does not exist, create
4723
- it first using [`~hf_api.create_repo`].
4724
-
4725
- </Tip>
4726
-
4727
- <Tip>
4728
-
4729
- When dealing with a large folder (thousands of files or hundreds of GB), we recommend using [`~hf_api.upload_large_folder`] instead.
4730
-
4731
- </Tip>
4636
+ > [!TIP]
4637
+ > When dealing with a large folder (thousands of files or hundreds of GB), we recommend using [`~hf_api.upload_large_folder`] instead.
4732
4638
 
4733
4639
  Example:
4734
4640
 
@@ -4871,23 +4777,20 @@ class HfApi:
4871
4777
  especially useful if the repo is updated / committed to concurrently.
4872
4778
 
4873
4779
 
4874
- <Tip>
4875
-
4876
- Raises the following errors:
4877
-
4878
- - [`HfHubHTTPError`]
4879
- if the HuggingFace API returned an error
4880
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
4881
- if some parameter value is invalid
4882
- - [`~utils.RepositoryNotFoundError`]
4883
- If the repository to download from cannot be found. This may be because it doesn't exist,
4884
- or because it is set to `private` and you do not have access.
4885
- - [`~utils.RevisionNotFoundError`]
4886
- If the revision to download from cannot be found.
4887
- - [`~utils.RemoteEntryNotFoundError`]
4888
- If the file to download cannot be found.
4889
-
4890
- </Tip>
4780
+ > [!TIP]
4781
+ > Raises the following errors:
4782
+ >
4783
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
4784
+ > if the HuggingFace API returned an error
4785
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
4786
+ > if some parameter value is invalid
4787
+ > - [`~utils.RepositoryNotFoundError`]
4788
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
4789
+ > or because it is set to `private` and you do not have access.
4790
+ > - [`~utils.RevisionNotFoundError`]
4791
+ > If the revision to download from cannot be found.
4792
+ > - [`~utils.EntryNotFoundError`]
4793
+ > If the file to download cannot be found.
4891
4794
 
4892
4795
  """
4893
4796
  commit_message = (
@@ -5104,25 +5007,19 @@ class HfApi:
5104
5007
  print_report_every (`int`, *optional*):
5105
5008
  Frequency at which the report is printed. Defaults to 60 seconds.
5106
5009
 
5107
- <Tip>
5108
-
5109
- A few things to keep in mind:
5110
- - Repository limits still apply: https://huggingface.co/docs/hub/repositories-recommendations
5111
- - Do not start several processes in parallel.
5112
- - You can interrupt and resume the process at any time.
5113
- - Do not upload the same folder to several repositories. If you need to do so, you must delete the local `.cache/.huggingface/` folder first.
5010
+ > [!TIP]
5011
+ > A few things to keep in mind:
5012
+ > - Repository limits still apply: https://huggingface.co/docs/hub/repositories-recommendations
5013
+ > - Do not start several processes in parallel.
5014
+ > - You can interrupt and resume the process at any time.
5015
+ > - Do not upload the same folder to several repositories. If you need to do so, you must delete the local `.cache/.huggingface/` folder first.
5114
5016
 
5115
- </Tip>
5116
-
5117
- <Tip warning={true}>
5118
-
5119
- While being much more robust to upload large folders, `upload_large_folder` is more limited than [`upload_folder`] feature-wise. In practice:
5120
- - you cannot set a custom `path_in_repo`. If you want to upload to a subfolder, you need to set the proper structure locally.
5121
- - you cannot set a custom `commit_message` and `commit_description` since multiple commits are created.
5122
- - you cannot delete from the repo while uploading. Please make a separate commit first.
5123
- - you cannot create a PR directly. Please create a PR first (from the UI or using [`create_pull_request`]) and then commit to it by passing `revision`.
5124
-
5125
- </Tip>
5017
+ > [!WARNING]
5018
+ > While being much more robust to upload large folders, `upload_large_folder` is more limited than [`upload_folder`] feature-wise. In practice:
5019
+ > - you cannot set a custom `path_in_repo`. If you want to upload to a subfolder, you need to set the proper structure locally.
5020
+ > - you cannot set a custom `commit_message` and `commit_description` since multiple commits are created.
5021
+ > - you cannot delete from the repo while uploading. Please make a separate commit first.
5022
+ > - you cannot create a PR directly. Please create a PR first (from the UI or using [`create_pull_request`]) and then commit to it by passing `revision`.
5126
5023
 
5127
5024
  **Technical details:**
5128
5025
 
@@ -6129,19 +6026,16 @@ class HfApi:
6129
6026
 
6130
6027
  Returns: [`DiscussionWithDetails`]
6131
6028
 
6132
- <Tip>
6133
-
6134
- Raises the following errors:
6135
-
6136
- - [`HfHubHTTPError`]
6137
- if the HuggingFace API returned an error
6138
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6139
- if some parameter value is invalid
6140
- - [`~utils.RepositoryNotFoundError`]
6141
- If the repository to download from cannot be found. This may be because it doesn't exist,
6142
- or because it is set to `private` and you do not have access.
6143
-
6144
- </Tip>
6029
+ > [!TIP]
6030
+ > Raises the following errors:
6031
+ >
6032
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6033
+ > if the HuggingFace API returned an error
6034
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6035
+ > if some parameter value is invalid
6036
+ > - [`~utils.RepositoryNotFoundError`]
6037
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
6038
+ > or because it is set to `private` and you do not have access.
6145
6039
  """
6146
6040
  if not isinstance(discussion_num, int) or discussion_num <= 0:
6147
6041
  raise ValueError("Invalid discussion_num, must be a positive integer")
@@ -6222,19 +6116,16 @@ class HfApi:
6222
6116
 
6223
6117
  Returns: [`DiscussionWithDetails`]
6224
6118
 
6225
- <Tip>
6226
-
6227
- Raises the following errors:
6228
-
6229
- - [`HfHubHTTPError`]
6230
- if the HuggingFace API returned an error
6231
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6232
- if some parameter value is invalid
6233
- - [`~utils.RepositoryNotFoundError`]
6234
- If the repository to download from cannot be found. This may be because it doesn't exist,
6235
- or because it is set to `private` and you do not have access.
6236
-
6237
- </Tip>"""
6119
+ > [!TIP]
6120
+ > Raises the following errors:
6121
+ >
6122
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6123
+ > if the HuggingFace API returned an error
6124
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6125
+ > if some parameter value is invalid
6126
+ > - [`~utils.RepositoryNotFoundError`]
6127
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
6128
+ > or because it is set to `private` and you do not have access."""
6238
6129
  if repo_type not in constants.REPO_TYPES:
6239
6130
  raise ValueError(f"Invalid repo type, must be one of {constants.REPO_TYPES}")
6240
6131
  if repo_type is None:
@@ -6310,19 +6201,16 @@ class HfApi:
6310
6201
 
6311
6202
  Returns: [`DiscussionWithDetails`]
6312
6203
 
6313
- <Tip>
6314
-
6315
- Raises the following errors:
6316
-
6317
- - [`HfHubHTTPError`]
6318
- if the HuggingFace API returned an error
6319
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6320
- if some parameter value is invalid
6321
- - [`~utils.RepositoryNotFoundError`]
6322
- If the repository to download from cannot be found. This may be because it doesn't exist,
6323
- or because it is set to `private` and you do not have access.
6324
-
6325
- </Tip>"""
6204
+ > [!TIP]
6205
+ > Raises the following errors:
6206
+ >
6207
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6208
+ > if the HuggingFace API returned an error
6209
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6210
+ > if some parameter value is invalid
6211
+ > - [`~utils.RepositoryNotFoundError`]
6212
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
6213
+ > or because it is set to `private` and you do not have access."""
6326
6214
  return self.create_discussion(
6327
6215
  repo_id=repo_id,
6328
6216
  title=title,
@@ -6413,19 +6301,16 @@ class HfApi:
6413
6301
 
6414
6302
  ```
6415
6303
 
6416
- <Tip>
6417
-
6418
- Raises the following errors:
6419
-
6420
- - [`HfHubHTTPError`]
6421
- if the HuggingFace API returned an error
6422
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6423
- if some parameter value is invalid
6424
- - [`~utils.RepositoryNotFoundError`]
6425
- If the repository to download from cannot be found. This may be because it doesn't exist,
6426
- or because it is set to `private` and you do not have access.
6427
-
6428
- </Tip>
6304
+ > [!TIP]
6305
+ > Raises the following errors:
6306
+ >
6307
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6308
+ > if the HuggingFace API returned an error
6309
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6310
+ > if some parameter value is invalid
6311
+ > - [`~utils.RepositoryNotFoundError`]
6312
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
6313
+ > or because it is set to `private` and you do not have access.
6429
6314
  """
6430
6315
  resp = self._post_discussion_changes(
6431
6316
  repo_id=repo_id,
@@ -6483,19 +6368,16 @@ class HfApi:
6483
6368
 
6484
6369
  ```
6485
6370
 
6486
- <Tip>
6487
-
6488
- Raises the following errors:
6489
-
6490
- - [`HfHubHTTPError`]
6491
- if the HuggingFace API returned an error
6492
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6493
- if some parameter value is invalid
6494
- - [`~utils.RepositoryNotFoundError`]
6495
- If the repository to download from cannot be found. This may be because it doesn't exist,
6496
- or because it is set to `private` and you do not have access.
6497
-
6498
- </Tip>
6371
+ > [!TIP]
6372
+ > Raises the following errors:
6373
+ >
6374
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6375
+ > if the HuggingFace API returned an error
6376
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6377
+ > if some parameter value is invalid
6378
+ > - [`~utils.RepositoryNotFoundError`]
6379
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
6380
+ > or because it is set to `private` and you do not have access.
6499
6381
  """
6500
6382
  resp = self._post_discussion_changes(
6501
6383
  repo_id=repo_id,
@@ -6556,19 +6438,16 @@ class HfApi:
6556
6438
 
6557
6439
  ```
6558
6440
 
6559
- <Tip>
6560
-
6561
- Raises the following errors:
6562
-
6563
- - [`HfHubHTTPError`]
6564
- if the HuggingFace API returned an error
6565
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6566
- if some parameter value is invalid
6567
- - [`~utils.RepositoryNotFoundError`]
6568
- If the repository to download from cannot be found. This may be because it doesn't exist,
6569
- or because it is set to `private` and you do not have access.
6570
-
6571
- </Tip>
6441
+ > [!TIP]
6442
+ > Raises the following errors:
6443
+ >
6444
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6445
+ > if the HuggingFace API returned an error
6446
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6447
+ > if some parameter value is invalid
6448
+ > - [`~utils.RepositoryNotFoundError`]
6449
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
6450
+ > or because it is set to `private` and you do not have access.
6572
6451
  """
6573
6452
  if new_status not in ["open", "closed"]:
6574
6453
  raise ValueError("Invalid status, valid statuses are: 'open' and 'closed'")
@@ -6618,19 +6497,16 @@ class HfApi:
6618
6497
  Returns:
6619
6498
  [`DiscussionStatusChange`]: the status change event
6620
6499
 
6621
- <Tip>
6622
-
6623
- Raises the following errors:
6624
-
6625
- - [`HfHubHTTPError`]
6626
- if the HuggingFace API returned an error
6627
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6628
- if some parameter value is invalid
6629
- - [`~utils.RepositoryNotFoundError`]
6630
- If the repository to download from cannot be found. This may be because it doesn't exist,
6631
- or because it is set to `private` and you do not have access.
6632
-
6633
- </Tip>
6500
+ > [!TIP]
6501
+ > Raises the following errors:
6502
+ >
6503
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6504
+ > if the HuggingFace API returned an error
6505
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6506
+ > if some parameter value is invalid
6507
+ > - [`~utils.RepositoryNotFoundError`]
6508
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
6509
+ > or because it is set to `private` and you do not have access.
6634
6510
  """
6635
6511
  self._post_discussion_changes(
6636
6512
  repo_id=repo_id,
@@ -6677,19 +6553,16 @@ class HfApi:
6677
6553
  Returns:
6678
6554
  [`DiscussionComment`]: the edited comment
6679
6555
 
6680
- <Tip>
6681
-
6682
- Raises the following errors:
6683
-
6684
- - [`HfHubHTTPError`]
6685
- if the HuggingFace API returned an error
6686
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6687
- if some parameter value is invalid
6688
- - [`~utils.RepositoryNotFoundError`]
6689
- If the repository to download from cannot be found. This may be because it doesn't exist,
6690
- or because it is set to `private` and you do not have access.
6691
-
6692
- </Tip>
6556
+ > [!TIP]
6557
+ > Raises the following errors:
6558
+ >
6559
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6560
+ > if the HuggingFace API returned an error
6561
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6562
+ > if some parameter value is invalid
6563
+ > - [`~utils.RepositoryNotFoundError`]
6564
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
6565
+ > or because it is set to `private` and you do not have access.
6693
6566
  """
6694
6567
  resp = self._post_discussion_changes(
6695
6568
  repo_id=repo_id,
@@ -6713,9 +6586,8 @@ class HfApi:
6713
6586
  ) -> DiscussionComment:
6714
6587
  """Hides a comment on a Discussion / Pull Request.
6715
6588
 
6716
- <Tip warning={true}>
6717
- Hidden comments' content cannot be retrieved anymore. Hiding a comment is irreversible.
6718
- </Tip>
6589
+ > [!WARNING]
6590
+ > Hidden comments' content cannot be retrieved anymore. Hiding a comment is irreversible.
6719
6591
 
6720
6592
  Args:
6721
6593
  repo_id (`str`):
@@ -6738,19 +6610,16 @@ class HfApi:
6738
6610
  Returns:
6739
6611
  [`DiscussionComment`]: the hidden comment
6740
6612
 
6741
- <Tip>
6742
-
6743
- Raises the following errors:
6744
-
6745
- - [`HfHubHTTPError`]
6746
- if the HuggingFace API returned an error
6747
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6748
- if some parameter value is invalid
6749
- - [`~utils.RepositoryNotFoundError`]
6750
- If the repository to download from cannot be found. This may be because it doesn't exist,
6751
- or because it is set to `private` and you do not have access.
6752
-
6753
- </Tip>
6613
+ > [!TIP]
6614
+ > Raises the following errors:
6615
+ >
6616
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6617
+ > if the HuggingFace API returned an error
6618
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6619
+ > if some parameter value is invalid
6620
+ > - [`~utils.RepositoryNotFoundError`]
6621
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
6622
+ > or because it is set to `private` and you do not have access.
6754
6623
  """
6755
6624
  warnings.warn(
6756
6625
  "Hidden comments' content cannot be retrieved anymore. Hiding a comment is irreversible.",
@@ -6974,11 +6843,8 @@ class HfApi:
6974
6843
  Returns:
6975
6844
  [`SpaceRuntime`]: Runtime information about a Space including Space stage and hardware.
6976
6845
 
6977
- <Tip>
6978
-
6979
- It is also possible to request hardware directly when creating the Space repo! See [`create_repo`] for details.
6980
-
6981
- </Tip>
6846
+ > [!TIP]
6847
+ > It is also possible to request hardware directly when creating the Space repo! See [`create_repo`] for details.
6982
6848
  """
6983
6849
  if sleep_time is not None and hardware == SpaceHardware.CPU_BASIC:
6984
6850
  warnings.warn(
@@ -7025,11 +6891,8 @@ class HfApi:
7025
6891
  Returns:
7026
6892
  [`SpaceRuntime`]: Runtime information about a Space including Space stage and hardware.
7027
6893
 
7028
- <Tip>
7029
-
7030
- It is also possible to set a custom sleep time when requesting hardware with [`request_space_hardware`].
7031
-
7032
- </Tip>
6894
+ > [!TIP]
6895
+ > It is also possible to set a custom sleep time when requesting hardware with [`request_space_hardware`].
7033
6896
  """
7034
6897
  r = get_session().post(
7035
6898
  f"{self.endpoint}/api/spaces/{repo_id}/sleeptime",
@@ -7275,12 +7138,9 @@ class HfApi:
7275
7138
  Returns:
7276
7139
  [`SpaceRuntime`]: Runtime information about a Space including Space stage and hardware.
7277
7140
 
7278
- <Tip>
7279
-
7280
- It is not possible to decrease persistent storage after its granted. To do so, you must delete it
7281
- via [`delete_space_storage`].
7282
-
7283
- </Tip>
7141
+ > [!TIP]
7142
+ > It is not possible to decrease persistent storage after its granted. To do so, you must delete it
7143
+ > via [`delete_space_storage`].
7284
7144
  """
7285
7145
  payload: dict[str, SpaceStorage] = {"tier": storage}
7286
7146
  r = get_session().post(
@@ -7644,12 +7504,9 @@ class HfApi:
7644
7504
  Returns:
7645
7505
  [`InferenceEndpoint`]: information about the new Inference Endpoint.
7646
7506
 
7647
- <Tip warning={true}>
7648
-
7649
- `create_inference_endpoint_from_catalog` is experimental. Its API is subject to change in the future. Please provide feedback
7650
- if you have any suggestions or requests.
7651
-
7652
- </Tip>
7507
+ > [!WARNING]
7508
+ > `create_inference_endpoint_from_catalog` is experimental. Its API is subject to change in the future. Please provide feedback
7509
+ > if you have any suggestions or requests.
7653
7510
  """
7654
7511
  token = token or self.token or get_token()
7655
7512
  payload: dict = {
@@ -7686,13 +7543,10 @@ class HfApi:
7686
7543
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
7687
7544
 
7688
7545
  Returns:
7689
- list[`str`]: A list of model IDs available in the catalog.
7690
- <Tip warning={true}>
7691
-
7692
- `list_inference_catalog` is experimental. Its API is subject to change in the future. Please provide feedback
7693
- if you have any suggestions or requests.
7694
-
7695
- </Tip>
7546
+ List[`str`]: A list of model IDs available in the catalog.
7547
+ > [!WARNING]
7548
+ > `list_inference_catalog` is experimental. Its API is subject to change in the future. Please provide feedback
7549
+ > if you have any suggestions or requests.
7696
7550
  """
7697
7551
  response = get_session().get(
7698
7552
  f"{constants.INFERENCE_CATALOG_ENDPOINT}/repo-list",
@@ -8055,12 +7909,9 @@ class HfApi:
8055
7909
  ) -> Iterable[Collection]:
8056
7910
  """List collections on the Huggingface Hub, given some filters.
8057
7911
 
8058
- <Tip warning={true}>
8059
-
8060
- When listing collections, the item list per collection is truncated to 4 items maximum. To retrieve all items
8061
- from a collection, you must use [`get_collection`].
8062
-
8063
- </Tip>
7912
+ > [!WARNING]
7913
+ > When listing collections, the item list per collection is truncated to 4 items maximum. To retrieve all items
7914
+ > from a collection, you must use [`get_collection`].
8064
7915
 
8065
7916
  Args:
8066
7917
  owner (`list[str]` or `str`, *optional*):
@@ -8300,11 +8151,8 @@ class HfApi:
8300
8151
  >>> collection = delete_collection("username/useless-collection-64f9a55bb3115b4f513ec026", missing_ok=True)
8301
8152
  ```
8302
8153
 
8303
- <Tip warning={true}>
8304
-
8305
- This is a non-revertible action. A deleted collection cannot be restored.
8306
-
8307
- </Tip>
8154
+ > [!WARNING]
8155
+ > This is a non-revertible action. A deleted collection cannot be restored.
8308
8156
  """
8309
8157
  r = get_session().delete(
8310
8158
  f"{self.endpoint}/api/collections/{collection_slug}", headers=self._build_hf_headers(token=token)