Skip to content

Commit

Permalink
Prepare for 0.30 (#2878)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wauplin authored Feb 20, 2025
1 parent 6456491 commit 290aa26
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 73 deletions.
2 changes: 1 addition & 1 deletion src/huggingface_hub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from typing import TYPE_CHECKING


__version__ = "0.29.0.dev0"
__version__ = "0.30.0.dev0"

# Alphabetical order of definitions is ensured in tests
# WARNING: any comment added in this dictionary definition will be lost when
Expand Down
2 changes: 2 additions & 0 deletions src/huggingface_hub/_webhooks_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ def launch(self, prevent_thread_lock: bool = False, **launch_kwargs: Any) -> Non
# Print instructions and block main thread
space_host = os.environ.get("SPACE_HOST")
url = "https://" + space_host if space_host is not None else (ui.share_url or ui.local_url)
if url is None:
raise ValueError("Cannot find the URL of the app. Please provide a valid `ui` or update `gradio` version.")
url = url.strip("/")
message = "\nWebhooks are correctly setup and ready to use:"
message += "\n" + "\n".join(f" - POST {url}{webhook}" for webhook in self.registered_webhooks)
Expand Down
39 changes: 3 additions & 36 deletions src/huggingface_hub/inference/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
)
from huggingface_hub.inference._providers import PROVIDER_T, HFInferenceTask, get_provider_helper
from huggingface_hub.utils import build_hf_headers, get_session, hf_raise_for_status
from huggingface_hub.utils._deprecation import _deprecate_arguments, _deprecate_method
from huggingface_hub.utils._deprecation import _deprecate_method


if TYPE_CHECKING:
Expand Down Expand Up @@ -3033,22 +3033,14 @@ def visual_question_answering(
response = self._inner_post(request_parameters)
return VisualQuestionAnsweringOutputElement.parse_obj_as_list(response)

@_deprecate_arguments(
version="0.30.0",
deprecated_args=["labels"],
custom_message="`labels`has been renamed to `candidate_labels` and will be removed in huggingface_hub>=0.30.0.",
)
def zero_shot_classification(
self,
text: str,
# temporarily keeping it optional for backward compatibility.
candidate_labels: List[str] = None, # type: ignore
candidate_labels: List[str],
*,
multi_label: Optional[bool] = False,
hypothesis_template: Optional[str] = None,
model: Optional[str] = None,
# deprecated argument
labels: List[str] = None, # type: ignore
) -> List[ZeroShotClassificationOutputElement]:
"""
Provide as input a text and a set of candidate labels to classify the input text.
Expand Down Expand Up @@ -3127,16 +3119,6 @@ def zero_shot_classification(
]
```
"""
# handle deprecation
if labels is not None:
if candidate_labels is not None:
raise ValueError(
"Cannot specify both `labels` and `candidate_labels`. Use `candidate_labels` instead."
)
candidate_labels = labels
elif candidate_labels is None:
raise ValueError("Must specify `candidate_labels`")

provider_helper = get_provider_helper(self.provider, task="zero-shot-classification")
request_parameters = provider_helper.prepare_request(
inputs=text,
Expand All @@ -3156,16 +3138,10 @@ def zero_shot_classification(
for label, score in zip(output["labels"], output["scores"])
]

@_deprecate_arguments(
version="0.30.0",
deprecated_args=["labels"],
custom_message="`labels`has been renamed to `candidate_labels` and will be removed in huggingface_hub>=0.30.0.",
)
def zero_shot_image_classification(
self,
image: ContentT,
# temporarily keeping it optional for backward compatibility.
candidate_labels: List[str] = None, # type: ignore
candidate_labels: List[str],
*,
model: Optional[str] = None,
hypothesis_template: Optional[str] = None,
Expand Down Expand Up @@ -3210,15 +3186,6 @@ def zero_shot_image_classification(
[ZeroShotImageClassificationOutputElement(label='dog', score=0.956),...]
```
"""
# handle deprecation
if labels is not None:
if candidate_labels is not None:
raise ValueError(
"Cannot specify both `labels` and `candidate_labels`. Use `candidate_labels` instead."
)
candidate_labels = labels
elif candidate_labels is None:
raise ValueError("Must specify `candidate_labels`")
# Raise ValueError if input is less than 2 labels
if len(candidate_labels) < 2:
raise ValueError("You must specify at least 2 classes to compare.")
Expand Down
39 changes: 3 additions & 36 deletions src/huggingface_hub/inference/_generated/_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
)
from huggingface_hub.inference._providers import PROVIDER_T, HFInferenceTask, get_provider_helper
from huggingface_hub.utils import build_hf_headers, get_session, hf_raise_for_status
from huggingface_hub.utils._deprecation import _deprecate_arguments, _deprecate_method
from huggingface_hub.utils._deprecation import _deprecate_method

from .._common import _async_yield_from, _import_aiohttp

Expand Down Expand Up @@ -3094,22 +3094,14 @@ async def visual_question_answering(
response = await self._inner_post(request_parameters)
return VisualQuestionAnsweringOutputElement.parse_obj_as_list(response)

@_deprecate_arguments(
version="0.30.0",
deprecated_args=["labels"],
custom_message="`labels`has been renamed to `candidate_labels` and will be removed in huggingface_hub>=0.30.0.",
)
async def zero_shot_classification(
self,
text: str,
# temporarily keeping it optional for backward compatibility.
candidate_labels: List[str] = None, # type: ignore
candidate_labels: List[str],
*,
multi_label: Optional[bool] = False,
hypothesis_template: Optional[str] = None,
model: Optional[str] = None,
# deprecated argument
labels: List[str] = None, # type: ignore
) -> List[ZeroShotClassificationOutputElement]:
"""
Provide as input a text and a set of candidate labels to classify the input text.
Expand Down Expand Up @@ -3190,16 +3182,6 @@ async def zero_shot_classification(
]
```
"""
# handle deprecation
if labels is not None:
if candidate_labels is not None:
raise ValueError(
"Cannot specify both `labels` and `candidate_labels`. Use `candidate_labels` instead."
)
candidate_labels = labels
elif candidate_labels is None:
raise ValueError("Must specify `candidate_labels`")

provider_helper = get_provider_helper(self.provider, task="zero-shot-classification")
request_parameters = provider_helper.prepare_request(
inputs=text,
Expand All @@ -3219,16 +3201,10 @@ async def zero_shot_classification(
for label, score in zip(output["labels"], output["scores"])
]

@_deprecate_arguments(
version="0.30.0",
deprecated_args=["labels"],
custom_message="`labels`has been renamed to `candidate_labels` and will be removed in huggingface_hub>=0.30.0.",
)
async def zero_shot_image_classification(
self,
image: ContentT,
# temporarily keeping it optional for backward compatibility.
candidate_labels: List[str] = None, # type: ignore
candidate_labels: List[str],
*,
model: Optional[str] = None,
hypothesis_template: Optional[str] = None,
Expand Down Expand Up @@ -3274,15 +3250,6 @@ async def zero_shot_image_classification(
[ZeroShotImageClassificationOutputElement(label='dog', score=0.956),...]
```
"""
# handle deprecation
if labels is not None:
if candidate_labels is not None:
raise ValueError(
"Cannot specify both `labels` and `candidate_labels`. Use `candidate_labels` instead."
)
candidate_labels = labels
elif candidate_labels is None:
raise ValueError("Must specify `candidate_labels`")
# Raise ValueError if input is less than 2 labels
if len(candidate_labels) < 2:
raise ValueError("You must specify at least 2 classes to compare.")
Expand Down

0 comments on commit 290aa26

Please sign in to comment.