





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


UpperCAmelCase						:   int			  =     logging.get_logger(__name__)





@add_end_docstrings(snake_case__   )
class 						_A(					snake_case__   ):


				"""simple docstring"""


				def __init__(			self     ,					**_A     ):
									super().__init__(**_A     )

									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__(_A     ,					**_A     )



				def 					UpperCAmelCase_		(			self     ,					**_A     ):
									__A	:						Tuple       =				{}
									if "candidate_labels" in kwargs:
														__A	:						int       =				kwargs['candidate_labels']
									if "hypothesis_template" in kwargs:
														__A	:						Any       =				kwargs['hypothesis_template']

									return preprocess_params, {}, {}



				def 					UpperCAmelCase_		(			self     ,					_A     ,					_A=None     ,					_A="This is a sound of {}."     ):
									if isinstance(_A     ,					_A     ):
														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
																			__A	:						int       =				requests.get(_A     ).content
														else:
																			with open(_A     ,					'rb'     ) as f:
																								__A	:						Optional[Any]       =				f.read()

									if isinstance(_A     ,					_A     ):
														__A	:						Optional[int]       =				ffmpeg_read(_A     ,					self.feature_extractor.sampling_rate     )

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

									__A	:						Any       =				self.feature_extractor(
									    [audio]     ,					sampling_rate=self.feature_extractor.sampling_rate     ,					return_tensors='pt'     )
									__A	:						Optional[Any]       =				candidate_labels
									__A	:						Tuple       =				[hypothesis_template.format(_A     ) for x in candidate_labels]
									__A	:						Optional[Any]       =				self.tokenizer(_A     ,					return_tensors=self.framework     ,					padding=_A     )
									__A	:						Tuple       =				[text_inputs]
									return inputs



				def 					UpperCAmelCase_		(			self     ,					_A     ):
									__A	:						Optional[Any]       =				model_inputs.pop('candidate_labels'     )
									__A	:						int       =				model_inputs.pop('text_inputs'     )
									if isinstance(text_inputs[0]     ,					_A     ):
														__A	:						Union[str, Any]       =				text_inputs[0]
									else:
														# Batching case.
														__A	:						str       =				text_inputs[0][0]

									__A	:						Optional[int]       =				self.model(**_A     ,					**_A     )

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





				def 					UpperCAmelCase_		(			self     ,					_A     ):
									__A	:						str       =				model_outputs.pop('candidate_labels'     )
									__A	:						Any       =				model_outputs['logits'][0]

									if self.framework == "pt":
														__A	:						Union[str, Any]       =				logits.softmax(dim=0     )
														__A	:						List[Any]       =				probs.tolist()
									else:
														raise ValueError('`tf` framework not supported.'     )

									__A	:						Union[str, Any]       =				[
									    {'score': score, 'label': candidate_label}
									    for score, candidate_label in sorted(zip(_A     ,					_A     )     ,					key=lambda _A     : -x[0]     )
									]
									return result











def  _SCREAMING_SNAKE_CASE				(   a  )      ->      bool:
					return str(a  ) == str(a  )[::-1]







def  _SCREAMING_SNAKE_CASE				(   a  )      ->      int:
					return int(a  ) + int(str(a  )[::-1]  )







def  _SCREAMING_SNAKE_CASE				(   a = 1_00_00  )      ->      int:
					__A	:						int       =				[]
					for num in range(1					,						a  ):
										__A	:						List[str]       =				0
										__A	:						List[Any]       =				num
										while iterations < 50:
															__A	:						str       =				sum_reverse(a  )
															iterations += 1
															if is_palindrome(a  ):
																				break
										else:
															lychrel_nums.append(a  )
					return len(a  )


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




