


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

__magic_name__          =							logging.get_logger(__name__)





def 			a_   (  lowercase__   :bytes, lowercase__   :int    ):
			__lowerCamelCase        =			f'{sampling_rate}'
			__lowerCamelCase        =			"""1"""
			__lowerCamelCase        =			"""f32le"""
			__lowerCamelCase        =			[
			    """ffmpeg""",
			    """-i""",
			    """pipe:0""",
			    """-ac""",
			    ac,
			    """-ar""",
			    ar,
			    """-f""",
			    format_for_conversion,
			    """-hide_banner""",
			    """-loglevel""",
			    """quiet""",
			    """pipe:1""",
			]

			try:
						__lowerCamelCase        =			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"""    )
			__lowerCamelCase        =			ffmpeg_process.communicate(lowercase__    )
			__lowerCamelCase        =			output_stream[0]

			__lowerCamelCase        =			np.frombuffer(lowercase__, np.floataa    )
			if audio.shape[0] == 0:
						raise ValueError("""Malformed soundfile"""    )
			return audio




@add_end_docstrings(lowerCamelCase     )
class  __snake_case      (lowerCamelCase     ):




							def __init__(    self:						Union[str, Any]    ,       *A_:						int    ,       **A_:						List[str]      ):
										# Default, might be overriden by the model.config.
										__lowerCamelCase        =			5
										super().__init__(*A_    ,       **A_      )

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

										self.check_model_type(A_      )




							def __call__(    self:						Optional[int]    ,       A_:						Union[np.ndarray, bytes, str]    ,       **A_:						Optional[int]    ,       ):
										return super().__call__(A_    ,       **A_      )




							def      __a      (    self:						Union[str, Any]    ,       A_:						Optional[Any]=None    ,       **A_:						Union[str, Any]      ):
										# No parameters on this pipeline right now
										__lowerCamelCase        =			{}
										if top_k is not None:
													if top_k > self.model.config.num_labels:
																__lowerCamelCase        =			self.model.config.num_labels
													__lowerCamelCase        =			top_k
										return {}, {}, postprocess_params




							def      __a      (    self:						Optional[Any]    ,       A_:						Optional[int]      ):
										if isinstance(A_    ,       A_      ):
													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
																__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 isinstance(A_    ,       A_      ):
													# 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"""      )

													__lowerCamelCase        =			inputs.pop("""raw"""    ,       A_      )
													if _inputs is None:
																# Remove path which will not be used from `datasets`.
																inputs.pop("""path"""    ,       A_      )
																__lowerCamelCase        =			inputs.pop("""array"""    ,       A_      )
													__lowerCamelCase        =			inputs.pop("""sampling_rate"""      )
													__lowerCamelCase        =			_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`."""      )

																__lowerCamelCase        =			F.resample(
																    torch.from_numpy(A_      )    ,       A_    ,       self.feature_extractor.sampling_rate      ).numpy()

										if not isinstance(A_    ,       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"""      )

										__lowerCamelCase        =			self.feature_extractor(
										    A_    ,       sampling_rate=self.feature_extractor.sampling_rate    ,       return_tensors="""pt"""      )
										return processed




							def      __a      (    self:						List[str]    ,       A_:						Union[str, Any]      ):
										__lowerCamelCase        =			self.model(**A_      )
										return model_outputs




							def      __a      (    self:						str    ,       A_:						Any    ,       A_:						Dict=5      ):
										__lowerCamelCase        =			model_outputs.logits[0].softmax(-1      )
										__lowerCamelCase    ,__lowerCamelCase        =			probs.topk(A_      )

										__lowerCamelCase        =			scores.tolist()
										__lowerCamelCase        =			ids.tolist()

										__lowerCamelCase        =			[{"""score""": score, """label""": self.model.config.idalabel[_id]} for score, _id in zip(A_    ,       A_      )]

										return labels








"""simple docstring"""




def 			a_   (  lowercase__   :str, lowercase__   :int = 13    ):
			__lowerCamelCase        =			""""""
			for c in s:
						if "A" <= c <= "Z":
									out += chr(ord("""A"""    ) + (ord(lowercase__    ) - ord("""A"""    ) + n) % 26    )
						elif "a" <= c <= "z":
									out += chr(ord("""a"""    ) + (ord(lowercase__    ) - ord("""a"""    ) + n) % 26    )
						else:
									out += c
			return out





def 			a_   (  ):
			__lowerCamelCase        =			input("""Enter message: """    )

			__lowerCamelCase        =			dencrypt(lowercase__, 13    )
			print("""Encryption:""", lowercase__    )

			__lowerCamelCase        =			dencrypt(lowercase__, 13    )
			print("""Decryption: """, lowercase__    )


if __name__ == "__main__":
					import doctest

					doctest.testmod()
					main()




