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.

Files changed (125) hide show
  1. huggingface_hub/__init__.py +46 -45
  2. huggingface_hub/_commit_api.py +28 -28
  3. huggingface_hub/_commit_scheduler.py +11 -8
  4. huggingface_hub/_inference_endpoints.py +8 -8
  5. huggingface_hub/_jobs_api.py +167 -10
  6. huggingface_hub/_login.py +13 -39
  7. huggingface_hub/_oauth.py +8 -8
  8. huggingface_hub/_snapshot_download.py +14 -28
  9. huggingface_hub/_space_api.py +4 -4
  10. huggingface_hub/_tensorboard_logger.py +13 -14
  11. huggingface_hub/_upload_large_folder.py +15 -15
  12. huggingface_hub/_webhooks_payload.py +3 -3
  13. huggingface_hub/_webhooks_server.py +2 -2
  14. huggingface_hub/cli/_cli_utils.py +2 -2
  15. huggingface_hub/cli/auth.py +5 -6
  16. huggingface_hub/cli/cache.py +14 -20
  17. huggingface_hub/cli/download.py +4 -4
  18. huggingface_hub/cli/jobs.py +560 -11
  19. huggingface_hub/cli/lfs.py +4 -4
  20. huggingface_hub/cli/repo.py +7 -7
  21. huggingface_hub/cli/repo_files.py +2 -2
  22. huggingface_hub/cli/upload.py +4 -4
  23. huggingface_hub/cli/upload_large_folder.py +3 -3
  24. huggingface_hub/commands/_cli_utils.py +2 -2
  25. huggingface_hub/commands/delete_cache.py +13 -13
  26. huggingface_hub/commands/download.py +4 -13
  27. huggingface_hub/commands/lfs.py +4 -4
  28. huggingface_hub/commands/repo_files.py +2 -2
  29. huggingface_hub/commands/scan_cache.py +1 -1
  30. huggingface_hub/commands/tag.py +1 -3
  31. huggingface_hub/commands/upload.py +4 -4
  32. huggingface_hub/commands/upload_large_folder.py +3 -3
  33. huggingface_hub/commands/user.py +5 -6
  34. huggingface_hub/community.py +5 -5
  35. huggingface_hub/constants.py +3 -41
  36. huggingface_hub/dataclasses.py +16 -19
  37. huggingface_hub/errors.py +42 -29
  38. huggingface_hub/fastai_utils.py +8 -9
  39. huggingface_hub/file_download.py +153 -252
  40. huggingface_hub/hf_api.py +815 -600
  41. huggingface_hub/hf_file_system.py +98 -62
  42. huggingface_hub/hub_mixin.py +37 -57
  43. huggingface_hub/inference/_client.py +177 -325
  44. huggingface_hub/inference/_common.py +110 -124
  45. huggingface_hub/inference/_generated/_async_client.py +226 -432
  46. huggingface_hub/inference/_generated/types/automatic_speech_recognition.py +3 -3
  47. huggingface_hub/inference/_generated/types/base.py +10 -7
  48. huggingface_hub/inference/_generated/types/chat_completion.py +18 -16
  49. huggingface_hub/inference/_generated/types/depth_estimation.py +2 -2
  50. huggingface_hub/inference/_generated/types/document_question_answering.py +2 -2
  51. huggingface_hub/inference/_generated/types/feature_extraction.py +2 -2
  52. huggingface_hub/inference/_generated/types/fill_mask.py +2 -2
  53. huggingface_hub/inference/_generated/types/sentence_similarity.py +3 -3
  54. huggingface_hub/inference/_generated/types/summarization.py +2 -2
  55. huggingface_hub/inference/_generated/types/table_question_answering.py +4 -4
  56. huggingface_hub/inference/_generated/types/text2text_generation.py +2 -2
  57. huggingface_hub/inference/_generated/types/text_generation.py +10 -10
  58. huggingface_hub/inference/_generated/types/text_to_video.py +2 -2
  59. huggingface_hub/inference/_generated/types/token_classification.py +2 -2
  60. huggingface_hub/inference/_generated/types/translation.py +2 -2
  61. huggingface_hub/inference/_generated/types/zero_shot_classification.py +2 -2
  62. huggingface_hub/inference/_generated/types/zero_shot_image_classification.py +2 -2
  63. huggingface_hub/inference/_generated/types/zero_shot_object_detection.py +1 -3
  64. huggingface_hub/inference/_mcp/_cli_hacks.py +3 -3
  65. huggingface_hub/inference/_mcp/agent.py +3 -3
  66. huggingface_hub/inference/_mcp/cli.py +1 -1
  67. huggingface_hub/inference/_mcp/constants.py +2 -3
  68. huggingface_hub/inference/_mcp/mcp_client.py +58 -30
  69. huggingface_hub/inference/_mcp/types.py +10 -7
  70. huggingface_hub/inference/_mcp/utils.py +11 -7
  71. huggingface_hub/inference/_providers/__init__.py +2 -2
  72. huggingface_hub/inference/_providers/_common.py +49 -25
  73. huggingface_hub/inference/_providers/black_forest_labs.py +6 -6
  74. huggingface_hub/inference/_providers/cohere.py +3 -3
  75. huggingface_hub/inference/_providers/fal_ai.py +25 -25
  76. huggingface_hub/inference/_providers/featherless_ai.py +4 -4
  77. huggingface_hub/inference/_providers/fireworks_ai.py +3 -3
  78. huggingface_hub/inference/_providers/hf_inference.py +28 -20
  79. huggingface_hub/inference/_providers/hyperbolic.py +4 -4
  80. huggingface_hub/inference/_providers/nebius.py +10 -10
  81. huggingface_hub/inference/_providers/novita.py +5 -5
  82. huggingface_hub/inference/_providers/nscale.py +4 -4
  83. huggingface_hub/inference/_providers/replicate.py +15 -15
  84. huggingface_hub/inference/_providers/sambanova.py +6 -6
  85. huggingface_hub/inference/_providers/together.py +7 -7
  86. huggingface_hub/lfs.py +20 -31
  87. huggingface_hub/repocard.py +18 -18
  88. huggingface_hub/repocard_data.py +56 -56
  89. huggingface_hub/serialization/__init__.py +0 -1
  90. huggingface_hub/serialization/_base.py +9 -9
  91. huggingface_hub/serialization/_dduf.py +7 -7
  92. huggingface_hub/serialization/_torch.py +28 -28
  93. huggingface_hub/utils/__init__.py +10 -4
  94. huggingface_hub/utils/_auth.py +5 -5
  95. huggingface_hub/utils/_cache_manager.py +31 -31
  96. huggingface_hub/utils/_deprecation.py +1 -1
  97. huggingface_hub/utils/_dotenv.py +3 -3
  98. huggingface_hub/utils/_fixes.py +0 -10
  99. huggingface_hub/utils/_git_credential.py +4 -4
  100. huggingface_hub/utils/_headers.py +7 -29
  101. huggingface_hub/utils/_http.py +366 -208
  102. huggingface_hub/utils/_pagination.py +4 -4
  103. huggingface_hub/utils/_paths.py +5 -5
  104. huggingface_hub/utils/_runtime.py +15 -13
  105. huggingface_hub/utils/_safetensors.py +21 -21
  106. huggingface_hub/utils/_subprocess.py +9 -9
  107. huggingface_hub/utils/_telemetry.py +3 -3
  108. huggingface_hub/utils/_typing.py +25 -5
  109. huggingface_hub/utils/_validators.py +53 -72
  110. huggingface_hub/utils/_xet.py +16 -16
  111. huggingface_hub/utils/_xet_progress_reporting.py +32 -11
  112. huggingface_hub/utils/insecure_hashlib.py +3 -9
  113. huggingface_hub/utils/tqdm.py +3 -3
  114. {huggingface_hub-0.34.4.dist-info → huggingface_hub-1.0.0rc0.dist-info}/METADATA +18 -29
  115. huggingface_hub-1.0.0rc0.dist-info/RECORD +161 -0
  116. huggingface_hub/inference_api.py +0 -217
  117. huggingface_hub/keras_mixin.py +0 -500
  118. huggingface_hub/repository.py +0 -1477
  119. huggingface_hub/serialization/_tensorflow.py +0 -95
  120. huggingface_hub/utils/_hf_folder.py +0 -68
  121. huggingface_hub-0.34.4.dist-info/RECORD +0 -166
  122. {huggingface_hub-0.34.4.dist-info → huggingface_hub-1.0.0rc0.dist-info}/LICENSE +0 -0
  123. {huggingface_hub-0.34.4.dist-info → huggingface_hub-1.0.0rc0.dist-info}/WHEEL +0 -0
  124. {huggingface_hub-0.34.4.dist-info → huggingface_hub-1.0.0rc0.dist-info}/entry_points.txt +0 -0
  125. {huggingface_hub-0.34.4.dist-info → huggingface_hub-1.0.0rc0.dist-info}/top_level.txt +0 -0
@@ -1,217 +0,0 @@
1
- import io
2
- from typing import Any, Dict, List, Optional, Union
3
-
4
- from . import constants
5
- from .hf_api import HfApi
6
- from .utils import build_hf_headers, get_session, is_pillow_available, logging, validate_hf_hub_args
7
- from .utils._deprecation import _deprecate_method
8
-
9
-
10
- logger = logging.get_logger(__name__)
11
-
12
-
13
- ALL_TASKS = [
14
- # NLP
15
- "text-classification",
16
- "token-classification",
17
- "table-question-answering",
18
- "question-answering",
19
- "zero-shot-classification",
20
- "translation",
21
- "summarization",
22
- "conversational",
23
- "feature-extraction",
24
- "text-generation",
25
- "text2text-generation",
26
- "fill-mask",
27
- "sentence-similarity",
28
- # Audio
29
- "text-to-speech",
30
- "automatic-speech-recognition",
31
- "audio-to-audio",
32
- "audio-classification",
33
- "voice-activity-detection",
34
- # Computer vision
35
- "image-classification",
36
- "object-detection",
37
- "image-segmentation",
38
- "text-to-image",
39
- "image-to-image",
40
- # Others
41
- "tabular-classification",
42
- "tabular-regression",
43
- ]
44
-
45
-
46
- class InferenceApi:
47
- """Client to configure requests and make calls to the HuggingFace Inference API.
48
-
49
- Example:
50
-
51
- ```python
52
- >>> from huggingface_hub.inference_api import InferenceApi
53
-
54
- >>> # Mask-fill example
55
- >>> inference = InferenceApi("bert-base-uncased")
56
- >>> inference(inputs="The goal of life is [MASK].")
57
- [{'sequence': 'the goal of life is life.', 'score': 0.10933292657136917, 'token': 2166, 'token_str': 'life'}]
58
-
59
- >>> # Question Answering example
60
- >>> inference = InferenceApi("deepset/roberta-base-squad2")
61
- >>> inputs = {
62
- ... "question": "What's my name?",
63
- ... "context": "My name is Clara and I live in Berkeley.",
64
- ... }
65
- >>> inference(inputs)
66
- {'score': 0.9326569437980652, 'start': 11, 'end': 16, 'answer': 'Clara'}
67
-
68
- >>> # Zero-shot example
69
- >>> inference = InferenceApi("typeform/distilbert-base-uncased-mnli")
70
- >>> inputs = "Hi, I recently bought a device from your company but it is not working as advertised and I would like to get reimbursed!"
71
- >>> params = {"candidate_labels": ["refund", "legal", "faq"]}
72
- >>> inference(inputs, params)
73
- {'sequence': 'Hi, I recently bought a device from your company but it is not working as advertised and I would like to get reimbursed!', 'labels': ['refund', 'faq', 'legal'], 'scores': [0.9378499388694763, 0.04914155602455139, 0.013008488342165947]}
74
-
75
- >>> # Overriding configured task
76
- >>> inference = InferenceApi("bert-base-uncased", task="feature-extraction")
77
-
78
- >>> # Text-to-image
79
- >>> inference = InferenceApi("stabilityai/stable-diffusion-2-1")
80
- >>> inference("cat")
81
- <PIL.PngImagePlugin.PngImageFile image (...)>
82
-
83
- >>> # Return as raw response to parse the output yourself
84
- >>> inference = InferenceApi("mio/amadeus")
85
- >>> response = inference("hello world", raw_response=True)
86
- >>> response.headers
87
- {"Content-Type": "audio/flac", ...}
88
- >>> response.content # raw bytes from server
89
- b'(...)'
90
- ```
91
- """
92
-
93
- @validate_hf_hub_args
94
- @_deprecate_method(
95
- version="1.0",
96
- message=(
97
- "`InferenceApi` client is deprecated in favor of the more feature-complete `InferenceClient`. Check out"
98
- " this guide to learn how to convert your script to use it:"
99
- " https://huggingface.co/docs/huggingface_hub/guides/inference#legacy-inferenceapi-client."
100
- ),
101
- )
102
- def __init__(
103
- self,
104
- repo_id: str,
105
- task: Optional[str] = None,
106
- token: Optional[str] = None,
107
- gpu: bool = False,
108
- ):
109
- """Inits headers and API call information.
110
-
111
- Args:
112
- repo_id (``str``):
113
- Id of repository (e.g. `user/bert-base-uncased`).
114
- task (``str``, `optional`, defaults ``None``):
115
- Whether to force a task instead of using task specified in the
116
- repository.
117
- token (`str`, `optional`):
118
- The API token to use as HTTP bearer authorization. This is not
119
- the authentication token. You can find the token in
120
- https://huggingface.co/settings/token. Alternatively, you can
121
- find both your organizations and personal API tokens using
122
- `HfApi().whoami(token)`.
123
- gpu (`bool`, `optional`, defaults `False`):
124
- Whether to use GPU instead of CPU for inference(requires Startup
125
- plan at least).
126
- """
127
- self.options = {"wait_for_model": True, "use_gpu": gpu}
128
- self.headers = build_hf_headers(token=token)
129
-
130
- # Configure task
131
- model_info = HfApi(token=token).model_info(repo_id=repo_id)
132
- if not model_info.pipeline_tag and not task:
133
- raise ValueError(
134
- "Task not specified in the repository. Please add it to the model card"
135
- " using pipeline_tag"
136
- " (https://huggingface.co/docs#how-is-a-models-type-of-inference-api-and-widget-determined)"
137
- )
138
-
139
- if task and task != model_info.pipeline_tag:
140
- if task not in ALL_TASKS:
141
- raise ValueError(f"Invalid task {task}. Make sure it's valid.")
142
-
143
- logger.warning(
144
- "You're using a different task than the one specified in the"
145
- " repository. Be sure to know what you're doing :)"
146
- )
147
- self.task = task
148
- else:
149
- assert model_info.pipeline_tag is not None, "Pipeline tag cannot be None"
150
- self.task = model_info.pipeline_tag
151
-
152
- self.api_url = f"{constants.INFERENCE_ENDPOINT}/pipeline/{self.task}/{repo_id}"
153
-
154
- def __repr__(self):
155
- # Do not add headers to repr to avoid leaking token.
156
- return f"InferenceAPI(api_url='{self.api_url}', task='{self.task}', options={self.options})"
157
-
158
- def __call__(
159
- self,
160
- inputs: Optional[Union[str, Dict, List[str], List[List[str]]]] = None,
161
- params: Optional[Dict] = None,
162
- data: Optional[bytes] = None,
163
- raw_response: bool = False,
164
- ) -> Any:
165
- """Make a call to the Inference API.
166
-
167
- Args:
168
- inputs (`str` or `Dict` or `List[str]` or `List[List[str]]`, *optional*):
169
- Inputs for the prediction.
170
- params (`Dict`, *optional*):
171
- Additional parameters for the models. Will be sent as `parameters` in the
172
- payload.
173
- data (`bytes`, *optional*):
174
- Bytes content of the request. In this case, leave `inputs` and `params` empty.
175
- raw_response (`bool`, defaults to `False`):
176
- If `True`, the raw `Response` object is returned. You can parse its content
177
- as preferred. By default, the content is parsed into a more practical format
178
- (json dictionary or PIL Image for example).
179
- """
180
- # Build payload
181
- payload: Dict[str, Any] = {
182
- "options": self.options,
183
- }
184
- if inputs:
185
- payload["inputs"] = inputs
186
- if params:
187
- payload["parameters"] = params
188
-
189
- # Make API call
190
- response = get_session().post(self.api_url, headers=self.headers, json=payload, data=data)
191
-
192
- # Let the user handle the response
193
- if raw_response:
194
- return response
195
-
196
- # By default, parse the response for the user.
197
- content_type = response.headers.get("Content-Type") or ""
198
- if content_type.startswith("image"):
199
- if not is_pillow_available():
200
- raise ImportError(
201
- f"Task '{self.task}' returned as image but Pillow is not installed."
202
- " Please install it (`pip install Pillow`) or pass"
203
- " `raw_response=True` to get the raw `Response` object and parse"
204
- " the image by yourself."
205
- )
206
-
207
- from PIL import Image
208
-
209
- return Image.open(io.BytesIO(response.content))
210
- elif content_type == "application/json":
211
- return response.json()
212
- else:
213
- raise NotImplementedError(
214
- f"{content_type} output type is not implemented yet. You can pass"
215
- " `raw_response=True` to get the raw `Response` object and parse the"
216
- " output by yourself."
217
- )