




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__    			=			logging.get_logger(__name__)
@add_end_docstrings(UpperCAmelCase__      )
class 			a__    (					UpperCAmelCase__      ):






						def __init__(   self		,			**_A			):




											"""simple docstring"""



											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			):




											"""simple docstring"""



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






						def 				__SCREAMING_SNAKE_CASE(   self		,			**_A			):




											"""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 				__SCREAMING_SNAKE_CASE(   self		,			_A		,			_A=None		,			_A="This is a sound of {}."			):




											"""simple docstring"""



											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
																					__lowerCAmelCase				   =       requests.get(_A			).content
																else:
																					with open(_A		,			"rb"			) as f:
																										__lowerCAmelCase				   =       f.read()

											if isinstance(_A		,			_A			):
																__lowerCAmelCase				   =       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"			)

											__lowerCAmelCase				   =       self.feature_extractor(
											    [audio]		,			sampling_rate=self.feature_extractor.sampling_rate		,			return_tensors="pt"			)
											__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 				__SCREAMING_SNAKE_CASE(   self		,			_A			):




											"""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_audio,
											}
											return model_outputs






						def 				__SCREAMING_SNAKE_CASE(   self		,			_A			):




											"""simple docstring"""



											__lowerCAmelCase				   =       model_outputs.pop("candidate_labels"			)
											__lowerCAmelCase				   =       model_outputs["""logits"""][0]

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

											__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 math import isqrt


def 	SCREAMING_SNAKE_CASE_					(  _UpperCAmelCase	:	int  )  ->			bool:
       return all(number % divisor != 0 for divisor in range(2    ,isqrt(_UpperCAmelCase  ) + 1  )  )


def 	SCREAMING_SNAKE_CASE_					(  _UpperCAmelCase	:	int = 10**6  )  ->			int:
       _a    : List[Any]     					=0
       _a    : str     					=1
       _a    : Optional[Any]     					=7
       while prime_candidate < max_prime:
              primes_count += is_prime(_UpperCAmelCase  )

              cube_index += 1
              prime_candidate += 6 * cube_index

       return primes_count


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


