code: 
  
  
  
  
  """simple docstring"""
  
  
  
  import subprocess
  from typing import Union
  
  import numpy as np
  import requests
  
  from ..utils import add_end_docstrings, is_torch_available, is_torchaudio_available, logging
  from .base import PIPELINE_INIT_ARGS, Pipeline
  
  
  if is_torch_available():
         from ..models.auto.modeling_auto import MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
  
  SCREAMING_SNAKE_CASE       = logging.get_logger(__name__)
  
  
  
  
  
  
  
  def 						_SCREAMING_SNAKE_CASE     (							lowercase_    ,				lowercase_		)		->	np.array:
   A__ =       f"""{sampling_rate}"""
   A__ =       "1"
   A__ =       "f32le"
   A__ =       [
       "ffmpeg",
       "-i",
       "pipe:0",
       "-ac",
       ac,
       "-ar",
       ar,
       "-f",
       format_for_conversion,
       "-hide_banner",
       "-loglevel",
       "quiet",
       "pipe:1",
   ]
  
   try:
    A__ =       subprocess.Popen(lowercase_    ,				stdin=subprocess.PIPE    ,				stdout=subprocess.PIPE		)
   except FileNotFoundError:
    raise ValueError("ffmpeg was not found but is required to load audio files from filename"		)
   A__ =       ffmpeg_process.communicate(lowercase_		)
   A__ =       output_stream[0]
  
   A__ =       np.frombuffer(lowercase_    ,				np.floataa		)
   if audio.shape[0] == 0:
    raise ValueError("Malformed soundfile"		)
   return audio
  
  
  
  
  
  
  @add_end_docstrings(A_							)
  class 			UpperCAmelCase_						(		A_							):
  
  
  
  
      def __init__(					self		: List[Any]			,				*snake_case_		: int			,				**snake_case_		: Optional[Any]   )   ->							int:
  
  
  
  
       '''simple docstring'''
  
       A__ =       5
       super().__init__(*snake_case_			,				**snake_case_   )
  
       if self.framework != "pt":
        raise ValueError(F"""The {self.__class__} is only available in PyTorch."""   )
  
       self.check_model_type(snake_case_   )
  
  
  
  
      def __call__(					self		: Any			,				snake_case_		: Union[np.ndarray, bytes, str]			,				**snake_case_		: List[Any]			,				)   ->							Tuple:
  
  
  
  
       '''simple docstring'''
  
       return super().__call__(snake_case_			,				**snake_case_   )
  
  
  
  
      def 							__magic_name__							(					self		: List[Any]			,				snake_case_		: Dict=None			,				**snake_case_		: List[str]   )   ->							Optional[int]:
  
  
  
  
       '''simple docstring'''
  
       A__ =       {}
       if top_k is not None:
        if top_k > self.model.config.num_labels:
         A__ =       self.model.config.num_labels
        A__ =       top_k
       return {}, {}, postprocess_params
  
  
  
  
      def 							__magic_name__							(					self		: List[Any]			,				snake_case_		: List[Any]   )   ->							Dict:
  
  
  
  
       '''simple docstring'''
  
       if isinstance(snake_case_			,				snake_case_   ):
        if inputs.startswith("http://"   ) or inputs.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__ =       requests.get(snake_case_   ).content
        else:
         with open(snake_case_			,				"rb"   ) as f:
          A__ =       f.read()
  
       if isinstance(snake_case_			,				snake_case_   ):
        A__ =       ffmpeg_read(snake_case_			,				self.feature_extractor.sampling_rate   )
  
       if isinstance(snake_case_			,				snake_case_   ):
        # Accepting `"array"` which is the key defined in `datasets` for
        # better integration
        if not ("sampling_rate" in inputs and ("raw" in inputs or "array" in inputs)):
         raise ValueError(
             "When passing a dictionary to AudioClassificationPipeline, the dict needs to contain a "
             "\"raw\" key containing the numpy array representing the audio and a \"sampling_rate\" key, "
             "containing the sampling_rate associated with that array"   )
  
        A__ =       inputs.pop("raw"			,				snake_case_   )
        if _inputs is None:
         # Remove path which will not be used from `datasets`.
         inputs.pop("path"			,				snake_case_   )
         A__ =       inputs.pop("array"			,				snake_case_   )
        A__ =       inputs.pop("sampling_rate"   )
        A__ =       _inputs
        if in_sampling_rate != self.feature_extractor.sampling_rate:
         import torch
  
         if is_torchaudio_available():
          from torchaudio import functional as F
         else:
          raise ImportError(
              "torchaudio is required to resample audio samples in AudioClassificationPipeline. "
              "The torchaudio package can be installed through: `pip install torchaudio`."   )
  
         A__ =       F.resample(
             torch.from_numpy(snake_case_   )			,				snake_case_			,				self.feature_extractor.sampling_rate   ).numpy()
  
       if not isinstance(snake_case_			,				np.ndarray   ):
        raise ValueError("We expect a numpy ndarray as input"   )
       if len(inputs.shape   ) != 1:
        raise ValueError("We expect a single channel audio input for AudioClassificationPipeline"   )
  
       A__ =       self.feature_extractor(
           snake_case_			,				sampling_rate=self.feature_extractor.sampling_rate			,				return_tensors="pt"   )
       return processed
  
  
  
  
      def 							__magic_name__							(					self		: str			,				snake_case_		: List[str]   )   ->							Dict:
  
  
  
  
       '''simple docstring'''
  
       A__ =       self.model(**snake_case_   )
       return model_outputs
  
  
  
  
      def 							__magic_name__							(					self		: List[Any]			,				snake_case_		: Any			,				snake_case_		: Union[str, Any]=5   )   ->							List[Any]:
  
  
  
  
       '''simple docstring'''
  
       A__ =       model_outputs.logits[0].softmax(-1   )
       A__,   A__ =       probs.topk(snake_case_   )
  
       A__ =       scores.tolist()
       A__ =       ids.tolist()
  
       A__ =       [{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(snake_case_			,				snake_case_   )]
  
       return labels
  
  
  
  
  
  
style_context: 
  
  
  
  
  """simple docstring"""
  
  
  
  from transformers import PretrainedConfig
  
  
  
  
  class 			UpperCAmelCase_						(		A_							):
      lowercase__		      =   '''custom'''
  
  
  
  
      def __init__(					self		: Any			,				snake_case_		: List[Any]=1			,				**snake_case_		: Any   )   ->							str:
  
  
  
  
       '''simple docstring'''
  
       A__ =       attribute
       super().__init__(**snake_case_   )
  
  
  
  
  
  
  class 			UpperCAmelCase_						(		A_							):
      lowercase__		      =   '''custom'''
  
  
  
  
      def __init__(					self		: Any			,				snake_case_		: Tuple=1			,				**snake_case_		: Dict   )   ->							Any:
  
  
  
  
       '''simple docstring'''
  
       A__ =       attribute
  
  
  
  
  
  