From 7d83b2879b47d485c2239f3b6bcdfe50446c86f9 Mon Sep 17 00:00:00 2001 From: Lucain Pouget Date: Wed, 19 Feb 2025 13:08:13 +0100 Subject: [PATCH] Prepare for 0.30 --- src/huggingface_hub/__init__.py | 2 +- src/huggingface_hub/_webhooks_server.py | 2 + src/huggingface_hub/inference/_client.py | 39 ++----------------- .../inference/_generated/_async_client.py | 39 ++----------------- 4 files changed, 9 insertions(+), 73 deletions(-) diff --git a/src/huggingface_hub/__init__.py b/src/huggingface_hub/__init__.py index 38b153ac79..dc935329a2 100644 --- a/src/huggingface_hub/__init__.py +++ b/src/huggingface_hub/__init__.py @@ -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 diff --git a/src/huggingface_hub/_webhooks_server.py b/src/huggingface_hub/_webhooks_server.py index c0c08e0092..a7bd6c8626 100644 --- a/src/huggingface_hub/_webhooks_server.py +++ b/src/huggingface_hub/_webhooks_server.py @@ -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) diff --git a/src/huggingface_hub/inference/_client.py b/src/huggingface_hub/inference/_client.py index c59ebb5169..a2d3bdafb4 100644 --- a/src/huggingface_hub/inference/_client.py +++ b/src/huggingface_hub/inference/_client.py @@ -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: @@ -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. @@ -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, @@ -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, @@ -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.") diff --git a/src/huggingface_hub/inference/_generated/_async_client.py b/src/huggingface_hub/inference/_generated/_async_client.py index 1f350b19e5..547a51dedd 100644 --- a/src/huggingface_hub/inference/_generated/_async_client.py +++ b/src/huggingface_hub/inference/_generated/_async_client.py @@ -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 @@ -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. @@ -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, @@ -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, @@ -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.")