huggingface-hub 0.35.0rc0__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 +176 -20
- huggingface_hub/_local_folder.py +1 -1
- huggingface_hub/_login.py +13 -39
- huggingface_hub/_oauth.py +10 -14
- 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 +120 -13
- 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 +8 -6
- huggingface_hub/cli/cache.py +18 -20
- huggingface_hub/cli/download.py +4 -4
- huggingface_hub/cli/hf.py +2 -5
- huggingface_hub/cli/jobs.py +599 -22
- huggingface_hub/cli/lfs.py +4 -4
- huggingface_hub/cli/repo.py +11 -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 +4 -5
- 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 +162 -259
- huggingface_hub/hf_api.py +841 -616
- huggingface_hub/hf_file_system.py +98 -62
- huggingface_hub/hub_mixin.py +37 -57
- huggingface_hub/inference/_client.py +257 -325
- huggingface_hub/inference/_common.py +110 -124
- huggingface_hub/inference/_generated/_async_client.py +307 -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 +4 -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 +52 -21
- 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 +25 -21
- 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 +16 -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.35.0rc0.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.35.0rc0.dist-info/RECORD +0 -166
- {huggingface_hub-0.35.0rc0.dist-info → huggingface_hub-1.0.0rc0.dist-info}/LICENSE +0 -0
- {huggingface_hub-0.35.0rc0.dist-info → huggingface_hub-1.0.0rc0.dist-info}/WHEEL +0 -0
- {huggingface_hub-0.35.0rc0.dist-info → huggingface_hub-1.0.0rc0.dist-info}/entry_points.txt +0 -0
- {huggingface_hub-0.35.0rc0.dist-info → huggingface_hub-1.0.0rc0.dist-info}/top_level.txt +0 -0
huggingface_hub/inference_api.py
DELETED
|
@@ -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
|
-
)
|