





'''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


_SCREAMING_SNAKE_CASE									=				logging.get_logger(__name__)

@add_end_docstrings(__magic_name__		)
class  lowerCAmelCase_		(		__magic_name__		):




 def __init__(						self      ,  **_lowerCAmelCase		)     ->				List[Any]:
     super().__init__(**_lowerCAmelCase		)

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




 def __call__(						self      ,  _lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Optional[Any]:
     return super().__call__(_lowerCAmelCase      ,  **_lowerCAmelCase		)




 def 				_snake_case (						self      ,  **_lowerCAmelCase		)     ->				Any:
     _lowerCAmelCase						      =   {}
     if "candidate_labels" in kwargs:
         _lowerCAmelCase						      =   kwargs["candidate_labels"]
     if "hypothesis_template" in kwargs:
         _lowerCAmelCase						      =   kwargs["hypothesis_template"]

     return preprocess_params, {}, {}




 def 				_snake_case (						self      ,  _lowerCAmelCase      ,  _lowerCAmelCase=None      ,  _lowerCAmelCase="This is a sound of {}."		)     ->				List[str]:
     if isinstance(_lowerCAmelCase      ,  _lowerCAmelCase		):
         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(_lowerCAmelCase		).content
         else:
             with open(_lowerCAmelCase      ,  "rb"		) as f:
                 _lowerCAmelCase						      =   f.read()

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

     if not isinstance(_lowerCAmelCase      ,  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(_lowerCAmelCase		) for x in candidate_labels]
     _lowerCAmelCase						      =   self.tokenizer(_lowerCAmelCase      ,  return_tensors=self.framework      ,  padding=_lowerCAmelCase		)
     _lowerCAmelCase						      =   [text_inputs]
     return inputs




 def 				_snake_case (						self      ,  _lowerCAmelCase		)     ->				List[Any]:
     _lowerCAmelCase						      =   model_inputs.pop("candidate_labels"		)
     _lowerCAmelCase						      =   model_inputs.pop("text_inputs"		)
     if isinstance(text_inputs[0]      ,  _lowerCAmelCase		):
         _lowerCAmelCase						      =   text_inputs[0]
     else:
         # Batching case.
         _lowerCAmelCase						      =   text_inputs[0][0]

     _lowerCAmelCase						      =   self.model(**_lowerCAmelCase      ,  **_lowerCAmelCase		)

     _lowerCAmelCase						      =   {
         "candidate_labels": candidate_labels,
         "logits": outputs.logits_per_audio,
     }
     return model_outputs





 def 				_snake_case (						self      ,  _lowerCAmelCase		)     ->				str:
     _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(_lowerCAmelCase      ,  _lowerCAmelCase		)      ,  key=lambda _lowerCAmelCase		: -x[0]		)
     ]
     return result








from __future__ import annotations

from collections.abc import Generator

def    UpperCAmelCase_				( )   ->					Generator[int, None, None]:
      SCREAMING_SNAKE_CASE_      		=     {}
      SCREAMING_SNAKE_CASE_      		=     2
      while True:
            SCREAMING_SNAKE_CASE_      		=     factor_map.pop(__UpperCAmelCase     ,     __UpperCAmelCase				)
            if factor:
                  SCREAMING_SNAKE_CASE_      		=     factor + prime
                  while x in factor_map:
                        x += factor
                  SCREAMING_SNAKE_CASE_      		=     factor
            else:
                  SCREAMING_SNAKE_CASE_      		=     prime
                  yield prime
            prime += 1

def    UpperCAmelCase_				( __UpperCAmelCase		:      float = 1E10				)   ->					int:
      SCREAMING_SNAKE_CASE_      		=     sieve()

      SCREAMING_SNAKE_CASE_      		=     1
      while True:
            SCREAMING_SNAKE_CASE_      		=     next(__UpperCAmelCase				)
            if (2 * prime * n) > limit:
                  return n
            # Ignore the next prime as the reminder will be 2.
            next(__UpperCAmelCase				)
            n += 2


if __name__ == "__main__":
   print(solution())