

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__						=		logging.get_logger(__name__)

@add_end_docstrings(snake_case__			)
class 				__UpperCamelCase				(					snake_case__			):







	def __init__(   self: Optional[int]  , **__UpperCamelCase: Any      ):

						'''simple docstring'''





						super().__init__(**UpperCAmelCase_      )

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







	def __call__(   self: str  , __UpperCamelCase: Union[np.ndarray, bytes, str]  , **__UpperCamelCase: List[Any]      ):

						'''simple docstring'''





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







	def 	_SCREAMING_SNAKE_CASE							(   self: Tuple  , **__UpperCamelCase: Optional[int]      ):

						'''simple docstring'''





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

						return preprocess_params, {}, {}







	def 	_SCREAMING_SNAKE_CASE							(   self: List[str]  , __UpperCamelCase: int  , __UpperCamelCase: List[Any]=None  , __UpperCamelCase: Optional[int]="This is a sound of {}."      ):

						'''simple docstring'''





						if isinstance(UpperCAmelCase_  , UpperCAmelCase_      ):
											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
																__magic_name__							=    requests.get(UpperCAmelCase_      ).content
											else:
																with open(UpperCAmelCase_  , 'rb'      ) as f:
																					__magic_name__							=    f.read()

						if isinstance(UpperCAmelCase_  , UpperCAmelCase_      ):
											__magic_name__							=    ffmpeg_read(UpperCAmelCase_  , self.feature_extractor.sampling_rate      )

						if not isinstance(UpperCAmelCase_  , 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'      )

						__magic_name__							=    self.feature_extractor(
						    [audio]  , sampling_rate=self.feature_extractor.sampling_rate  , return_tensors='pt'      )
						__magic_name__							=    candidate_labels
						__magic_name__							=    [hypothesis_template.format(UpperCAmelCase_      ) for x in candidate_labels]
						__magic_name__							=    self.tokenizer(UpperCAmelCase_  , return_tensors=self.framework  , padding=UpperCAmelCase_      )
						__magic_name__							=    [text_inputs]
						return inputs







	def 	_SCREAMING_SNAKE_CASE							(   self: Any  , __UpperCamelCase: Tuple      ):

						'''simple docstring'''





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

						__magic_name__							=    self.model(**UpperCAmelCase_  , **UpperCAmelCase_      )

						__magic_name__							=    {
						    'candidate_labels': candidate_labels,
						    'logits': outputs.logits_per_audio,
						}
						return model_outputs







	def 	_SCREAMING_SNAKE_CASE							(   self: Optional[int]  , __UpperCamelCase: Union[str, Any]      ):

						'''simple docstring'''





						__magic_name__							=    model_outputs.pop('candidate_labels'      )
						__magic_name__							=    model_outputs['logits'][0]

						if self.framework == "pt":
											__magic_name__							=    logits.softmax(dim=0      )
											__magic_name__							=    probs.tolist()
						else:
											raise ValueError('`tf` framework not supported.'      )

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







from __future__ import annotations




def 					_lowercase     (				a_				:					int				)				->	bool:




					'''simple docstring'''







					__magic_name__							=    str(a_				)
					return len(a_				) == 9 and set(a_				) == set('123456789'				)




def 					_lowercase     (				)				->	int | None:




					'''simple docstring'''







					for base_num in range(9_9_9_9					,4_9_9_9					,-1				):
										__magic_name__							=    1_0_0_0_0_2 * base_num
										if is_9_pandigital(a_				):
															return candidate

					for base_num in range(3_3_3					,9_9					,-1				):
										__magic_name__							=    1_0_0_2_0_0_3 * base_num
										if is_9_pandigital(a_				):
															return candidate

					return None


if __name__ == "__main__":
						print(f'''{solution() = }''')




