huggingface-hub 0.29.0rc2__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.
Files changed (153) hide show
  1. huggingface_hub/__init__.py +160 -46
  2. huggingface_hub/_commit_api.py +277 -71
  3. huggingface_hub/_commit_scheduler.py +15 -15
  4. huggingface_hub/_inference_endpoints.py +33 -22
  5. huggingface_hub/_jobs_api.py +301 -0
  6. huggingface_hub/_local_folder.py +18 -3
  7. huggingface_hub/_login.py +31 -63
  8. huggingface_hub/_oauth.py +460 -0
  9. huggingface_hub/_snapshot_download.py +241 -81
  10. huggingface_hub/_space_api.py +18 -10
  11. huggingface_hub/_tensorboard_logger.py +15 -19
  12. huggingface_hub/_upload_large_folder.py +196 -76
  13. huggingface_hub/_webhooks_payload.py +3 -3
  14. huggingface_hub/_webhooks_server.py +15 -25
  15. huggingface_hub/{commands → cli}/__init__.py +1 -15
  16. huggingface_hub/cli/_cli_utils.py +173 -0
  17. huggingface_hub/cli/auth.py +147 -0
  18. huggingface_hub/cli/cache.py +841 -0
  19. huggingface_hub/cli/download.py +189 -0
  20. huggingface_hub/cli/hf.py +60 -0
  21. huggingface_hub/cli/inference_endpoints.py +377 -0
  22. huggingface_hub/cli/jobs.py +772 -0
  23. huggingface_hub/cli/lfs.py +175 -0
  24. huggingface_hub/cli/repo.py +315 -0
  25. huggingface_hub/cli/repo_files.py +94 -0
  26. huggingface_hub/{commands/env.py → cli/system.py} +10 -13
  27. huggingface_hub/cli/upload.py +294 -0
  28. huggingface_hub/cli/upload_large_folder.py +117 -0
  29. huggingface_hub/community.py +20 -12
  30. huggingface_hub/constants.py +83 -59
  31. huggingface_hub/dataclasses.py +609 -0
  32. huggingface_hub/errors.py +99 -30
  33. huggingface_hub/fastai_utils.py +30 -41
  34. huggingface_hub/file_download.py +606 -346
  35. huggingface_hub/hf_api.py +2445 -1132
  36. huggingface_hub/hf_file_system.py +269 -152
  37. huggingface_hub/hub_mixin.py +61 -66
  38. huggingface_hub/inference/_client.py +501 -630
  39. huggingface_hub/inference/_common.py +133 -121
  40. huggingface_hub/inference/_generated/_async_client.py +536 -722
  41. huggingface_hub/inference/_generated/types/__init__.py +6 -1
  42. huggingface_hub/inference/_generated/types/automatic_speech_recognition.py +5 -6
  43. huggingface_hub/inference/_generated/types/base.py +10 -7
  44. huggingface_hub/inference/_generated/types/chat_completion.py +77 -31
  45. huggingface_hub/inference/_generated/types/depth_estimation.py +2 -2
  46. huggingface_hub/inference/_generated/types/document_question_answering.py +2 -2
  47. huggingface_hub/inference/_generated/types/feature_extraction.py +2 -2
  48. huggingface_hub/inference/_generated/types/fill_mask.py +2 -2
  49. huggingface_hub/inference/_generated/types/image_to_image.py +8 -2
  50. huggingface_hub/inference/_generated/types/image_to_text.py +2 -3
  51. huggingface_hub/inference/_generated/types/image_to_video.py +60 -0
  52. huggingface_hub/inference/_generated/types/sentence_similarity.py +3 -3
  53. huggingface_hub/inference/_generated/types/summarization.py +2 -2
  54. huggingface_hub/inference/_generated/types/table_question_answering.py +5 -5
  55. huggingface_hub/inference/_generated/types/text2text_generation.py +2 -2
  56. huggingface_hub/inference/_generated/types/text_generation.py +11 -11
  57. huggingface_hub/inference/_generated/types/text_to_audio.py +1 -2
  58. huggingface_hub/inference/_generated/types/text_to_speech.py +1 -2
  59. huggingface_hub/inference/_generated/types/text_to_video.py +2 -2
  60. huggingface_hub/inference/_generated/types/token_classification.py +2 -2
  61. huggingface_hub/inference/_generated/types/translation.py +2 -2
  62. huggingface_hub/inference/_generated/types/zero_shot_classification.py +2 -2
  63. huggingface_hub/inference/_generated/types/zero_shot_image_classification.py +2 -2
  64. huggingface_hub/inference/_generated/types/zero_shot_object_detection.py +1 -3
  65. huggingface_hub/inference/_mcp/__init__.py +0 -0
  66. huggingface_hub/inference/_mcp/_cli_hacks.py +88 -0
  67. huggingface_hub/inference/_mcp/agent.py +100 -0
  68. huggingface_hub/inference/_mcp/cli.py +247 -0
  69. huggingface_hub/inference/_mcp/constants.py +81 -0
  70. huggingface_hub/inference/_mcp/mcp_client.py +395 -0
  71. huggingface_hub/inference/_mcp/types.py +45 -0
  72. huggingface_hub/inference/_mcp/utils.py +128 -0
  73. huggingface_hub/inference/_providers/__init__.py +149 -20
  74. huggingface_hub/inference/_providers/_common.py +160 -37
  75. huggingface_hub/inference/_providers/black_forest_labs.py +12 -9
  76. huggingface_hub/inference/_providers/cerebras.py +6 -0
  77. huggingface_hub/inference/_providers/clarifai.py +13 -0
  78. huggingface_hub/inference/_providers/cohere.py +32 -0
  79. huggingface_hub/inference/_providers/fal_ai.py +231 -22
  80. huggingface_hub/inference/_providers/featherless_ai.py +38 -0
  81. huggingface_hub/inference/_providers/fireworks_ai.py +22 -1
  82. huggingface_hub/inference/_providers/groq.py +9 -0
  83. huggingface_hub/inference/_providers/hf_inference.py +143 -33
  84. huggingface_hub/inference/_providers/hyperbolic.py +9 -5
  85. huggingface_hub/inference/_providers/nebius.py +47 -5
  86. huggingface_hub/inference/_providers/novita.py +48 -5
  87. huggingface_hub/inference/_providers/nscale.py +44 -0
  88. huggingface_hub/inference/_providers/openai.py +25 -0
  89. huggingface_hub/inference/_providers/publicai.py +6 -0
  90. huggingface_hub/inference/_providers/replicate.py +46 -9
  91. huggingface_hub/inference/_providers/sambanova.py +37 -1
  92. huggingface_hub/inference/_providers/scaleway.py +28 -0
  93. huggingface_hub/inference/_providers/together.py +34 -5
  94. huggingface_hub/inference/_providers/wavespeed.py +138 -0
  95. huggingface_hub/inference/_providers/zai_org.py +17 -0
  96. huggingface_hub/lfs.py +33 -100
  97. huggingface_hub/repocard.py +34 -38
  98. huggingface_hub/repocard_data.py +79 -59
  99. huggingface_hub/serialization/__init__.py +0 -1
  100. huggingface_hub/serialization/_base.py +12 -15
  101. huggingface_hub/serialization/_dduf.py +8 -8
  102. huggingface_hub/serialization/_torch.py +69 -69
  103. huggingface_hub/utils/__init__.py +27 -8
  104. huggingface_hub/utils/_auth.py +7 -7
  105. huggingface_hub/utils/_cache_manager.py +92 -147
  106. huggingface_hub/utils/_chunk_utils.py +2 -3
  107. huggingface_hub/utils/_deprecation.py +1 -1
  108. huggingface_hub/utils/_dotenv.py +55 -0
  109. huggingface_hub/utils/_experimental.py +7 -5
  110. huggingface_hub/utils/_fixes.py +0 -10
  111. huggingface_hub/utils/_git_credential.py +5 -5
  112. huggingface_hub/utils/_headers.py +8 -30
  113. huggingface_hub/utils/_http.py +399 -237
  114. huggingface_hub/utils/_pagination.py +6 -6
  115. huggingface_hub/utils/_parsing.py +98 -0
  116. huggingface_hub/utils/_paths.py +5 -5
  117. huggingface_hub/utils/_runtime.py +74 -22
  118. huggingface_hub/utils/_safetensors.py +21 -21
  119. huggingface_hub/utils/_subprocess.py +13 -11
  120. huggingface_hub/utils/_telemetry.py +4 -4
  121. huggingface_hub/{commands/_cli_utils.py → utils/_terminal.py} +4 -4
  122. huggingface_hub/utils/_typing.py +25 -5
  123. huggingface_hub/utils/_validators.py +55 -74
  124. huggingface_hub/utils/_verification.py +167 -0
  125. huggingface_hub/utils/_xet.py +235 -0
  126. huggingface_hub/utils/_xet_progress_reporting.py +162 -0
  127. huggingface_hub/utils/insecure_hashlib.py +3 -5
  128. huggingface_hub/utils/logging.py +8 -11
  129. huggingface_hub/utils/tqdm.py +33 -4
  130. {huggingface_hub-0.29.0rc2.dist-info → huggingface_hub-1.1.3.dist-info}/METADATA +94 -82
  131. huggingface_hub-1.1.3.dist-info/RECORD +155 -0
  132. {huggingface_hub-0.29.0rc2.dist-info → huggingface_hub-1.1.3.dist-info}/WHEEL +1 -1
  133. huggingface_hub-1.1.3.dist-info/entry_points.txt +6 -0
  134. huggingface_hub/commands/delete_cache.py +0 -428
  135. huggingface_hub/commands/download.py +0 -200
  136. huggingface_hub/commands/huggingface_cli.py +0 -61
  137. huggingface_hub/commands/lfs.py +0 -200
  138. huggingface_hub/commands/repo_files.py +0 -128
  139. huggingface_hub/commands/scan_cache.py +0 -181
  140. huggingface_hub/commands/tag.py +0 -159
  141. huggingface_hub/commands/upload.py +0 -299
  142. huggingface_hub/commands/upload_large_folder.py +0 -129
  143. huggingface_hub/commands/user.py +0 -304
  144. huggingface_hub/commands/version.py +0 -37
  145. huggingface_hub/inference_api.py +0 -217
  146. huggingface_hub/keras_mixin.py +0 -500
  147. huggingface_hub/repository.py +0 -1477
  148. huggingface_hub/serialization/_tensorflow.py +0 -95
  149. huggingface_hub/utils/_hf_folder.py +0 -68
  150. huggingface_hub-0.29.0rc2.dist-info/RECORD +0 -131
  151. huggingface_hub-0.29.0rc2.dist-info/entry_points.txt +0 -6
  152. {huggingface_hub-0.29.0rc2.dist-info → huggingface_hub-1.1.3.dist-info/licenses}/LICENSE +0 -0
  153. {huggingface_hub-0.29.0rc2.dist-info → huggingface_hub-1.1.3.dist-info}/top_level.txt +0 -0
@@ -1,7 +1,7 @@
1
1
  import os
2
2
  import re
3
3
  import typing
4
- from typing import Literal, Optional, Tuple
4
+ from typing import Literal, Optional
5
5
 
6
6
 
7
7
  # Possible values for env variables
@@ -35,7 +35,7 @@ DEFAULT_ETAG_TIMEOUT = 10
35
35
  DEFAULT_DOWNLOAD_TIMEOUT = 10
36
36
  DEFAULT_REQUEST_TIMEOUT = 10
37
37
  DOWNLOAD_CHUNK_SIZE = 10 * 1024 * 1024
38
- HF_TRANSFER_CONCURRENCY = 100
38
+ MAX_HTTP_DOWNLOAD_SIZE = 50 * 1000 * 1000 * 1000 # 50 GB
39
39
 
40
40
  # Constants for serialization
41
41
 
@@ -73,11 +73,24 @@ if _staging_mode:
73
73
  HUGGINGFACE_HEADER_X_REPO_COMMIT = "X-Repo-Commit"
74
74
  HUGGINGFACE_HEADER_X_LINKED_ETAG = "X-Linked-Etag"
75
75
  HUGGINGFACE_HEADER_X_LINKED_SIZE = "X-Linked-Size"
76
+ HUGGINGFACE_HEADER_X_BILL_TO = "X-HF-Bill-To"
76
77
 
77
78
  INFERENCE_ENDPOINT = os.environ.get("HF_INFERENCE_ENDPOINT", "https://api-inference.huggingface.co")
78
79
 
79
80
  # See https://huggingface.co/docs/inference-endpoints/index
80
81
  INFERENCE_ENDPOINTS_ENDPOINT = "https://api.endpoints.huggingface.cloud/v2"
82
+ INFERENCE_CATALOG_ENDPOINT = "https://endpoints.huggingface.co/api/catalog"
83
+
84
+ # See https://api.endpoints.huggingface.cloud/#post-/v2/endpoint/-namespace-
85
+ INFERENCE_ENDPOINT_IMAGE_KEYS = [
86
+ "custom",
87
+ "huggingface",
88
+ "huggingfaceNeuron",
89
+ "llamacpp",
90
+ "tei",
91
+ "tgi",
92
+ "tgiNeuron",
93
+ ]
81
94
 
82
95
  # Proxy for third-party providers
83
96
  INFERENCE_PROXY_TEMPLATE = "https://router.huggingface.co/{provider}"
@@ -104,22 +117,23 @@ REPO_TYPES_MAPPING = {
104
117
  }
105
118
 
106
119
  DiscussionTypeFilter = Literal["all", "discussion", "pull_request"]
107
- DISCUSSION_TYPES: Tuple[DiscussionTypeFilter, ...] = typing.get_args(DiscussionTypeFilter)
120
+ DISCUSSION_TYPES: tuple[DiscussionTypeFilter, ...] = typing.get_args(DiscussionTypeFilter)
108
121
  DiscussionStatusFilter = Literal["all", "open", "closed"]
109
- DISCUSSION_STATUS: Tuple[DiscussionTypeFilter, ...] = typing.get_args(DiscussionStatusFilter)
122
+ DISCUSSION_STATUS: tuple[DiscussionTypeFilter, ...] = typing.get_args(DiscussionStatusFilter)
110
123
 
111
124
  # Webhook subscription types
112
125
  WEBHOOK_DOMAIN_T = Literal["repo", "discussions"]
113
126
 
114
127
  # default cache
115
128
  default_home = os.path.join(os.path.expanduser("~"), ".cache")
116
- HF_HOME = os.path.expanduser(
117
- os.getenv(
118
- "HF_HOME",
119
- os.path.join(os.getenv("XDG_CACHE_HOME", default_home), "huggingface"),
129
+ HF_HOME = os.path.expandvars(
130
+ os.path.expanduser(
131
+ os.getenv(
132
+ "HF_HOME",
133
+ os.path.join(os.getenv("XDG_CACHE_HOME", default_home), "huggingface"),
134
+ )
120
135
  )
121
136
  )
122
- hf_cache_home = HF_HOME # for backward compatibility. TODO: remove this in 1.0.0
123
137
 
124
138
  default_cache_path = os.path.join(HF_HOME, "hub")
125
139
  default_assets_cache_path = os.path.join(HF_HOME, "assets")
@@ -129,11 +143,29 @@ HUGGINGFACE_HUB_CACHE = os.getenv("HUGGINGFACE_HUB_CACHE", default_cache_path)
129
143
  HUGGINGFACE_ASSETS_CACHE = os.getenv("HUGGINGFACE_ASSETS_CACHE", default_assets_cache_path)
130
144
 
131
145
  # New env variables
132
- HF_HUB_CACHE = os.getenv("HF_HUB_CACHE", HUGGINGFACE_HUB_CACHE)
133
- HF_ASSETS_CACHE = os.getenv("HF_ASSETS_CACHE", HUGGINGFACE_ASSETS_CACHE)
146
+ HF_HUB_CACHE = os.path.expandvars(
147
+ os.path.expanduser(
148
+ os.getenv(
149
+ "HF_HUB_CACHE",
150
+ HUGGINGFACE_HUB_CACHE,
151
+ )
152
+ )
153
+ )
154
+ HF_ASSETS_CACHE = os.path.expandvars(
155
+ os.path.expanduser(
156
+ os.getenv(
157
+ "HF_ASSETS_CACHE",
158
+ HUGGINGFACE_ASSETS_CACHE,
159
+ )
160
+ )
161
+ )
134
162
 
135
163
  HF_HUB_OFFLINE = _is_true(os.environ.get("HF_HUB_OFFLINE") or os.environ.get("TRANSFORMERS_OFFLINE"))
136
164
 
165
+ # File created to mark that the version check has been done.
166
+ # Check is performed once per 24 hours at most.
167
+ CHECK_FOR_UPDATE_DONE_PATH = os.path.join(HF_HOME, ".check_for_update_done")
168
+
137
169
  # If set, log level will be set to DEBUG and all requests made to the Hub will be logged
138
170
  # as curl commands for reproducibility.
139
171
  HF_DEBUG = _is_true(os.environ.get("HF_DEBUG"))
@@ -145,7 +177,14 @@ HF_HUB_DISABLE_TELEMETRY = (
145
177
  or _is_true(os.environ.get("DO_NOT_TRACK")) # https://consoledonottrack.com/
146
178
  )
147
179
 
148
- HF_TOKEN_PATH = os.environ.get("HF_TOKEN_PATH", os.path.join(HF_HOME, "token"))
180
+ HF_TOKEN_PATH = os.path.expandvars(
181
+ os.path.expanduser(
182
+ os.getenv(
183
+ "HF_TOKEN_PATH",
184
+ os.path.join(HF_HOME, "token"),
185
+ )
186
+ )
187
+ )
149
188
  HF_STORED_TOKENS_PATH = os.path.join(os.path.dirname(HF_TOKEN_PATH), "stored_tokens")
150
189
 
151
190
  if _staging_mode:
@@ -175,18 +214,18 @@ HF_HUB_DISABLE_EXPERIMENTAL_WARNING: bool = _is_true(os.environ.get("HF_HUB_DISA
175
214
  # Disable sending the cached token by default is all HTTP requests to the Hub
176
215
  HF_HUB_DISABLE_IMPLICIT_TOKEN: bool = _is_true(os.environ.get("HF_HUB_DISABLE_IMPLICIT_TOKEN"))
177
216
 
178
- # Enable fast-download using external dependency "hf_transfer"
179
- # See:
180
- # - https://pypi.org/project/hf-transfer/
181
- # - https://github.com/huggingface/hf_transfer (private)
182
- HF_HUB_ENABLE_HF_TRANSFER: bool = _is_true(os.environ.get("HF_HUB_ENABLE_HF_TRANSFER"))
217
+ HF_XET_HIGH_PERFORMANCE: bool = _is_true(os.environ.get("HF_XET_HIGH_PERFORMANCE"))
183
218
 
219
+ # hf_transfer is not used anymore. Let's warn user is case they set the env variable
220
+ if _is_true(os.environ.get("HF_HUB_ENABLE_HF_TRANSFER")) and not HF_XET_HIGH_PERFORMANCE:
221
+ import warnings
184
222
 
185
- # UNUSED
186
- # We don't use symlinks in local dir anymore.
187
- HF_HUB_LOCAL_DIR_AUTO_SYMLINK_THRESHOLD: int = (
188
- _as_int(os.environ.get("HF_HUB_LOCAL_DIR_AUTO_SYMLINK_THRESHOLD")) or 5 * 1024 * 1024
189
- )
223
+ warnings.warn(
224
+ "The `HF_HUB_ENABLE_HF_TRANSFER` environment variable is deprecated as 'hf_transfer' is not used anymore. "
225
+ "Please use `HF_XET_HIGH_PERFORMANCE` instead to enable high performance transfer with Xet. "
226
+ "Visit https://huggingface.co/docs/huggingface_hub/package_reference/environment_variables#hfxethighperformance for more details.",
227
+ DeprecationWarning,
228
+ )
190
229
 
191
230
  # Used to override the etag timeout on a system level
192
231
  HF_HUB_ETAG_TIMEOUT: int = _as_int(os.environ.get("HF_HUB_ETAG_TIMEOUT")) or DEFAULT_ETAG_TIMEOUT
@@ -194,42 +233,27 @@ HF_HUB_ETAG_TIMEOUT: int = _as_int(os.environ.get("HF_HUB_ETAG_TIMEOUT")) or DEF
194
233
  # Used to override the get request timeout on a system level
195
234
  HF_HUB_DOWNLOAD_TIMEOUT: int = _as_int(os.environ.get("HF_HUB_DOWNLOAD_TIMEOUT")) or DEFAULT_DOWNLOAD_TIMEOUT
196
235
 
197
- # Allows to add information about the requester in the user-agent (eg. partner name)
236
+ # Allows to add information about the requester in the user-agent (e.g. partner name)
198
237
  HF_HUB_USER_AGENT_ORIGIN: Optional[str] = os.environ.get("HF_HUB_USER_AGENT_ORIGIN")
199
238
 
200
- # List frameworks that are handled by the InferenceAPI service. Useful to scan endpoints and check which models are
201
- # deployed and running. Since 95% of the models are using the top 4 frameworks listed below, we scan only those by
202
- # default. We still keep the full list of supported frameworks in case we want to scan all of them.
203
- MAIN_INFERENCE_API_FRAMEWORKS = [
204
- "diffusers",
205
- "sentence-transformers",
206
- "text-generation-inference",
207
- "transformers",
208
- ]
209
-
210
- ALL_INFERENCE_API_FRAMEWORKS = MAIN_INFERENCE_API_FRAMEWORKS + [
211
- "adapter-transformers",
212
- "allennlp",
213
- "asteroid",
214
- "bertopic",
215
- "doctr",
216
- "espnet",
217
- "fairseq",
218
- "fastai",
219
- "fasttext",
220
- "flair",
221
- "k2",
222
- "keras",
223
- "mindspore",
224
- "nemo",
225
- "open_clip",
226
- "paddlenlp",
227
- "peft",
228
- "pyannote-audio",
229
- "sklearn",
230
- "spacy",
231
- "span-marker",
232
- "speechbrain",
233
- "stanza",
234
- "timm",
235
- ]
239
+ # If OAuth didn't work after 2 redirects, there's likely a third-party cookie issue in the Space iframe view.
240
+ # In this case, we redirect the user to the non-iframe view.
241
+ OAUTH_MAX_REDIRECTS = 2
242
+
243
+ # OAuth-related environment variables injected by the Space
244
+ OAUTH_CLIENT_ID = os.environ.get("OAUTH_CLIENT_ID")
245
+ OAUTH_CLIENT_SECRET = os.environ.get("OAUTH_CLIENT_SECRET")
246
+ OAUTH_SCOPES = os.environ.get("OAUTH_SCOPES")
247
+ OPENID_PROVIDER_URL = os.environ.get("OPENID_PROVIDER_URL")
248
+
249
+ # Xet constants
250
+ HUGGINGFACE_HEADER_X_XET_ENDPOINT = "X-Xet-Cas-Url"
251
+ HUGGINGFACE_HEADER_X_XET_ACCESS_TOKEN = "X-Xet-Access-Token"
252
+ HUGGINGFACE_HEADER_X_XET_EXPIRATION = "X-Xet-Token-Expiration"
253
+ HUGGINGFACE_HEADER_X_XET_HASH = "X-Xet-Hash"
254
+ HUGGINGFACE_HEADER_X_XET_REFRESH_ROUTE = "X-Xet-Refresh-Route"
255
+ HUGGINGFACE_HEADER_LINK_XET_AUTH_KEY = "xet-auth"
256
+
257
+ default_xet_cache_path = os.path.join(HF_HOME, "xet")
258
+ HF_XET_CACHE = os.getenv("HF_XET_CACHE", default_xet_cache_path)
259
+ HF_HUB_DISABLE_XET: bool = _is_true(os.environ.get("HF_HUB_DISABLE_XET"))