




from collections import UserDict
from typing import List, Union

from ..utils import (
    add_end_docstrings,
    is_tf_available,
    is_torch_available,
    is_vision_available,
    logging,
    requires_backends,
)
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_vision_available():
 from PIL import Image

 from ..image_utils import load_image

if is_torch_available():
 from ..models.auto.modeling_auto import MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING

if is_tf_available():
 from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING
 from ..tf_utils import stable_softmax

lowerCamelCase							:						str					       =  logging.get_logger(__name__)







@add_end_docstrings(UpperCamelCase  )
class     A(		UpperCamelCase  ):



 '''simple docstring'''


 def __init__(							self   :    Optional[Any]		,				**A_   :    str    )  ->      Dict:

       """simple docstring"""






       super().__init__(**A_    )

       requires_backends(self		,				'vision'    )
       self.check_model_type(
           TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING
           if self.framework == 'tf'
           else MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING    )

 def __call__(							self   :    Optional[Any]		,				A_   :    Union[str, List[str], "Image", List["Image"]]		,				**A_   :    Union[str, Any]    )  ->      List[str]:

       """simple docstring"""






       return super().__call__(A_		,				**A_    )

 def 							a__					(							self   :    Optional[int]		,				**A_   :    Tuple    )  ->      int:

       """simple docstring"""






       lowerCamelCase_							=       {}
       if "candidate_labels" in kwargs:
             lowerCamelCase_							=       kwargs['candidate_labels']
       if "hypothesis_template" in kwargs:
             lowerCamelCase_							=       kwargs['hypothesis_template']

       return preprocess_params, {}, {}

 def 							a__					(							self   :    Optional[Any]		,				A_   :    List[Any]		,				A_   :    str=None		,				A_   :    Tuple="This is a photo of {}."    )  ->      Tuple:

       """simple docstring"""






       lowerCamelCase_							=       load_image(A_    )
       lowerCamelCase_							=       self.image_processor(images=[image]		,				return_tensors=self.framework    )
       lowerCamelCase_							=       candidate_labels
       lowerCamelCase_							=       [hypothesis_template.format(A_    ) for x in candidate_labels]
       lowerCamelCase_							=       self.tokenizer(A_		,				return_tensors=self.framework		,				padding=A_    )
       lowerCamelCase_							=       [text_inputs]
       return inputs

 def 							a__					(							self   :    Any		,				A_   :    Optional[Any]    )  ->      List[str]:

       """simple docstring"""






       lowerCamelCase_							=       model_inputs.pop('candidate_labels'    )
       lowerCamelCase_							=       model_inputs.pop('text_inputs'    )
       if isinstance(text_inputs[0]		,				A_    ):
             lowerCamelCase_							=       text_inputs[0]
       else:
             # Batching case.
             lowerCamelCase_							=       text_inputs[0][0]

       lowerCamelCase_							=       self.model(**A_		,				**A_    )

       lowerCamelCase_							=       {
           'candidate_labels': candidate_labels,
           'logits': outputs.logits_per_image,
       }
       return model_outputs





 def 							a__					(							self   :    int		,				A_   :    Union[str, Any]    )  ->      str:

       """simple docstring"""






       lowerCamelCase_							=       model_outputs.pop('candidate_labels'    )
       lowerCamelCase_							=       model_outputs['logits'][0]
       if self.framework == "pt":
             lowerCamelCase_							=       logits.softmax(dim=-1    ).squeeze(-1    )
             lowerCamelCase_							=       probs.tolist()
             if not isinstance(A_		,				A_    ):
                   lowerCamelCase_							=       [scores]
       elif self.framework == "tf":
             lowerCamelCase_							=       stable_softmax(A_		,				axis=-1    )
             lowerCamelCase_							=       probs.numpy().tolist()
       else:
             raise ValueError(f"""Unsupported framework: {self.framework}"""    )

       lowerCamelCase_							=       [
           {'score': score, 'label': candidate_label}
           for score, candidate_label in sorted(zip(A_		,				A_    )		,				key=lambda A_    : -x[0]    )
       ]
       return result








"""simple docstring"""







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


UpperCamelCase     =							{"""configuration_wavlm""": ["""WAVLM_PRETRAINED_CONFIG_ARCHIVE_MAP""", """WavLMConfig"""]}

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			UpperCamelCase     =							[
			    """WAVLM_PRETRAINED_MODEL_ARCHIVE_LIST""",
			    """WavLMForAudioFrameClassification""",
			    """WavLMForCTC""",
			    """WavLMForSequenceClassification""",
			    """WavLMForXVector""",
			    """WavLMModel""",
			    """WavLMPreTrainedModel""",
			]

if TYPE_CHECKING:
			from .configuration_wavlm import WAVLM_PRETRAINED_CONFIG_ARCHIVE_MAP, WavLMConfig

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_wavlm import (
						    WAVLM_PRETRAINED_MODEL_ARCHIVE_LIST,
						    WavLMForAudioFrameClassification,
						    WavLMForCTC,
						    WavLMForSequenceClassification,
						    WavLMForXVector,
						    WavLMModel,
						    WavLMPreTrainedModel,
						)

else:
			import sys

			UpperCamelCase     =							_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)




