"""simple docstring"""




from collections import UserDict
from typing import Union

import numpy as np
import requests

from ..utils import (
    add_end_docstrings,
    logging,
)
from .audio_classification import ffmpeg_read
from .base import PIPELINE_INIT_ARGS, Pipeline


_a				:		Optional[Any]	   =       logging.get_logger(__name__)
@add_end_docstrings(_lowerCAmelCase		)
class 						__A							(			_lowerCAmelCase		):






					def __init__(		self    ,					**a__  ):
							super().__init__(**_lowercase  )

							if self.framework != "pt":
									raise ValueError(F"The {self.__class__} is only available in PyTorch."  )
							# No specific FOR_XXX available yet






					def __call__(		self    ,					a__    ,					**a__  ):
							return super().__call__(_lowercase    ,					**_lowercase  )






					def    __A  (		self    ,					**a__  ):
							_lowerCAmelCase						:	Tuple        =					{}
							if "candidate_labels" in kwargs:
									_lowerCAmelCase						:	Any        =					kwargs["""candidate_labels"""]
							if "hypothesis_template" in kwargs:
									_lowerCAmelCase						:	List[Any]        =					kwargs["""hypothesis_template"""]

							return preprocess_params, {}, {}






					def    __A  (		self    ,					a__    ,					a__=None    ,					a__="This is a sound of {}."  ):
							if isinstance(_lowercase    ,					_lowercase  ):
									if audio.startswith("""http://"""  ) or audio.startswith("""https://"""  ):
											# We need to actually check for a real protocol, otherwise it's impossible to use a local file
											# like http_huggingface_co.png
											_lowerCAmelCase						:	Any        =					requests.get(_lowercase  ).content
									else:
											with open(_lowercase    ,					"""rb"""  ) as f:
													_lowerCAmelCase						:	List[Any]        =					f.read()

							if isinstance(_lowercase    ,					_lowercase  ):
									_lowerCAmelCase						:	int        =					ffmpeg_read(_lowercase    ,					self.feature_extractor.sampling_rate  )

							if not isinstance(_lowercase    ,					np.ndarray  ):
									raise ValueError("""We expect a numpy ndarray as input"""  )
							if len(audio.shape  ) != 1:
									raise ValueError("""We expect a single channel audio input for ZeroShotAudioClassificationPipeline"""  )

							_lowerCAmelCase						:	Dict        =					self.feature_extractor(
							    [audio]    ,					sampling_rate=self.feature_extractor.sampling_rate    ,					return_tensors="""pt"""  )
							_lowerCAmelCase						:	int        =					candidate_labels
							_lowerCAmelCase						:	List[str]        =					[hypothesis_template.format(_lowercase  ) for x in candidate_labels]
							_lowerCAmelCase						:	List[Any]        =					self.tokenizer(_lowercase    ,					return_tensors=self.framework    ,					padding=_lowercase  )
							_lowerCAmelCase						:	List[Any]        =					[text_inputs]
							return inputs






					def    __A  (		self    ,					a__  ):
							_lowerCAmelCase						:	str        =					model_inputs.pop("""candidate_labels"""  )
							_lowerCAmelCase						:	Optional[Any]        =					model_inputs.pop("""text_inputs"""  )
							if isinstance(text_inputs[0]    ,					_lowercase  ):
									_lowerCAmelCase						:	Tuple        =					text_inputs[0]
							else:
									# Batching case.
									_lowerCAmelCase						:	Optional[Any]        =					text_inputs[0][0]

							_lowerCAmelCase						:	int        =					self.model(**_lowercase    ,					**_lowercase  )

							_lowerCAmelCase						:	Union[str, Any]        =					{
							    """candidate_labels""": candidate_labels,
							    """logits""": outputs.logits_per_audio,
							}
							return model_outputs






					def    __A  (		self    ,					a__  ):
							_lowerCAmelCase						:	Optional[int]        =					model_outputs.pop("""candidate_labels"""  )
							_lowerCAmelCase						:	int        =					model_outputs["""logits"""][0]

							if self.framework == "pt":
									_lowerCAmelCase						:	List[Any]        =					logits.softmax(dim=0  )
									_lowerCAmelCase						:	Optional[int]        =					probs.tolist()
							else:
									raise ValueError("""`tf` framework not supported."""  )

							_lowerCAmelCase						:	int        =					[
							    {"""score""": score, """label""": candidate_label}
							    for score, candidate_label in sorted(zip(_lowercase    ,					_lowercase  )    ,					key=lambda a__  : -x[0]  )
							]
							return result





"""simple docstring"""




from ..utils import DummyObject, requires_backends
class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Optional[Any]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      List[Any]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      int		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      str		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Optional[int]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      List[Any]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      str		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Union[str, Any]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Optional[int]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      List[str]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Any		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      str		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Tuple		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      str		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Tuple		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      str		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Tuple		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      str		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Dict		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Dict		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Union[str, Any]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Tuple		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      List[Any]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Optional[int]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Optional[Any]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Optional[Any]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      List[Any]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      int		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Dict		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      List[str]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      int		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )




