






'''simple docstring'''





import unittest

import numpy as np

from transformers import MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING, TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
from transformers.pipelines import AudioClassificationPipeline, pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_torchaudio,
    slow,
)

from .test_pipelines_common import ANY
@is_pipeline_test
class      UpperCamelCase (				unittest.TestCase ):







		"""simple docstring"""



		snake_case    =   MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
		snake_case    =   TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
		def       A(  self		:       int						,_SCREAMING_SNAKE_CASE		:       Any						,_SCREAMING_SNAKE_CASE		:       List[Any]						,_SCREAMING_SNAKE_CASE		:       Tuple		)    ->   Dict:


						'''simple docstring'''
						A	 =      AudioClassificationPipeline(model=_SCREAMING_SNAKE_CASE						,feature_extractor=_SCREAMING_SNAKE_CASE		)

						# test with a raw waveform
						A	 =      np.zeros((3_4_0_0_0,)		)
						A	 =      np.zeros((1_4_0_0_0,)		)
						return audio_classifier, [audioa, audio]
		def       A(  self		:       int						,_SCREAMING_SNAKE_CASE		:       Tuple						,_SCREAMING_SNAKE_CASE		:       List[Any]		)    ->   Union[str, Any]:


						'''simple docstring'''
						A ,		A	 =      examples
						A	 =      audio_classifier(_SCREAMING_SNAKE_CASE		)
						# by default a model is initialized with num_labels=2
						self.assertEqual(
						    _SCREAMING_SNAKE_CASE						,[
						        {'score': ANY(_SCREAMING_SNAKE_CASE		), 'label': ANY(_SCREAMING_SNAKE_CASE		)},
						        {'score': ANY(_SCREAMING_SNAKE_CASE		), 'label': ANY(_SCREAMING_SNAKE_CASE		)},
						    ]						,)
						A	 =      audio_classifier(_SCREAMING_SNAKE_CASE						,top_k=1		)
						self.assertEqual(
						    _SCREAMING_SNAKE_CASE						,[
						        {'score': ANY(_SCREAMING_SNAKE_CASE		), 'label': ANY(_SCREAMING_SNAKE_CASE		)},
						    ]						,)

						self.run_torchaudio(_SCREAMING_SNAKE_CASE		)
		@require_torchaudio
		def       A(  self		:       Optional[int]						,_SCREAMING_SNAKE_CASE		:       int		)    ->   Optional[Any]:


						'''simple docstring'''
						import datasets

						# test with a local file
						A	 =      datasets.load_dataset('hf-internal-testing/librispeech_asr_dummy'						,'clean'						,split='validation'		)
						A	 =      dataset[0]['audio']['array']
						A	 =      audio_classifier(_SCREAMING_SNAKE_CASE		)
						self.assertEqual(
						    _SCREAMING_SNAKE_CASE						,[
						        {'score': ANY(_SCREAMING_SNAKE_CASE		), 'label': ANY(_SCREAMING_SNAKE_CASE		)},
						        {'score': ANY(_SCREAMING_SNAKE_CASE		), 'label': ANY(_SCREAMING_SNAKE_CASE		)},
						    ]						,)
		@require_torch
		def       A(  self		:       int		)    ->   str:


						'''simple docstring'''
						A	 =      'anton-l/wav2vec2-random-tiny-classifier'

						A	 =      pipeline('audio-classification'						,model=_SCREAMING_SNAKE_CASE		)

						A	 =      np.ones((8_0_0_0,)		)
						A	 =      audio_classifier(_SCREAMING_SNAKE_CASE						,top_k=4		)

						A	 =      [
						    {'score': 0.0842, 'label': 'no'},
						    {'score': 0.0838, 'label': 'up'},
						    {'score': 0.0837, 'label': 'go'},
						    {'score': 0.0834, 'label': 'right'},
						]
						A	 =      [
						    {'score': 0.0845, 'label': 'stop'},
						    {'score': 0.0844, 'label': 'on'},
						    {'score': 0.0841, 'label': 'right'},
						    {'score': 0.0834, 'label': 'left'},
						]
						self.assertIn(nested_simplify(_SCREAMING_SNAKE_CASE						,decimals=4		)						,[EXPECTED_OUTPUT, EXPECTED_OUTPUT_PT_2]		)

						A	 =      {'array': np.ones((8_0_0_0,)		), 'sampling_rate': audio_classifier.feature_extractor.sampling_rate}
						A	 =      audio_classifier(_SCREAMING_SNAKE_CASE						,top_k=4		)
						self.assertIn(nested_simplify(_SCREAMING_SNAKE_CASE						,decimals=4		)						,[EXPECTED_OUTPUT, EXPECTED_OUTPUT_PT_2]		)
		@require_torch
		@slow
		def       A(  self		:       Optional[int]		)    ->   Union[str, Any]:


						'''simple docstring'''
						import datasets

						A	 =      'superb/wav2vec2-base-superb-ks'

						A	 =      pipeline('audio-classification'						,model=_SCREAMING_SNAKE_CASE		)
						A	 =      datasets.load_dataset('anton-l/superb_dummy'						,'ks'						,split='test'		)

						A	 =      np.array(dataset[3]['speech']						,dtype=np.floataa		)
						A	 =      audio_classifier(_SCREAMING_SNAKE_CASE						,top_k=4		)
						self.assertEqual(
						    nested_simplify(_SCREAMING_SNAKE_CASE						,decimals=3		)						,[
						        {'score': 0.981, 'label': 'go'},
						        {'score': 0.007, 'label': 'up'},
						        {'score': 0.006, 'label': '_unknown_'},
						        {'score': 0.001, 'label': 'down'},
						    ]						,)







		@require_tf
		@unittest.skip('Audio classification is not implemented for TF'		)
		def       A(  self		:       Any		)    ->   int:


						'''simple docstring'''
						pass













def      snake_case		(							UpperCAmelCase	:       Optional[int],						UpperCAmelCase	:       Union[str, Any]   ):
				A	 =      ''
				for i in table:
								res += inp[i - 1]
				return res







def      snake_case		(							UpperCAmelCase	:       Union[str, Any]   ):
				return data[1:] + data[0]







def      snake_case		(							UpperCAmelCase	:       Union[str, Any],						UpperCAmelCase	:       Dict   ):
				A	 =      ''
				for i in range(len(UpperCAmelCase   )   ):
								if a[i] == b[i]:
												res += "0"
								else:
												res += "1"
				return res







def      snake_case		(							UpperCAmelCase	:       int,						UpperCAmelCase	:       Optional[Any]   ):
				A	 =      int('0b' + data[0] + data[-1],						2   )
				A	 =      int('0b' + data[1:3],						2   )
				return bin(s[row][col]   )[2:]







def      snake_case		(							UpperCAmelCase	:       Optional[Any],						UpperCAmelCase	:       Any,						UpperCAmelCase	:       Union[str, Any],						UpperCAmelCase	:       Optional[Any],						UpperCAmelCase	:       Optional[int]   ):
				A	 =      message[:4]
				A	 =      message[4:]
				A	 =      apply_table(UpperCAmelCase,						UpperCAmelCase   )
				A	 =      xor(UpperCAmelCase,						UpperCAmelCase   )
				A	 =      apply_sbox(UpperCAmelCase,						temp[:4]   )  # noqa: E741
				A	 =      apply_sbox(UpperCAmelCase,						temp[4:]   )
				A	 =      '0' * (2 - len(UpperCAmelCase   )) + l  # noqa: E741
				A	 =      '0' * (2 - len(UpperCAmelCase   )) + r
				A	 =      apply_table(l + r,						UpperCAmelCase   )
				A	 =      xor(UpperCAmelCase,						UpperCAmelCase   )
				return temp + right


if __name__ == "__main__":
					lowerCAmelCase_           = input('Enter 10 bit key: ')
					lowerCAmelCase_           = input('Enter 8 bit message: ')

					lowerCAmelCase_           = [6, 3, 7, 4, 8, 5, 10, 9]
					lowerCAmelCase_           = [3, 5, 2, 7, 4, 10, 1, 9, 8, 6]
					lowerCAmelCase_           = [2, 4, 3, 1]
					lowerCAmelCase_           = [2, 6, 3, 1, 4, 8, 5, 7]
					lowerCAmelCase_           = [4, 1, 3, 5, 7, 2, 8, 6]
					lowerCAmelCase_           = [4, 1, 2, 3, 2, 3, 4, 1]
					lowerCAmelCase_           = [[1, 0, 3, 2], [3, 2, 1, 0], [0, 2, 1, 3], [3, 1, 3, 2]]
					lowerCAmelCase_           = [[0, 1, 2, 3], [2, 0, 1, 3], [3, 0, 1, 0], [2, 1, 0, 3]]

					# key generation
					lowerCAmelCase_           = apply_table(key, paa_table)
					lowerCAmelCase_           = temp[:5]
					lowerCAmelCase_           = temp[5:]
					lowerCAmelCase_           = left_shift(left)
					lowerCAmelCase_           = left_shift(right)
					lowerCAmelCase_           = apply_table(left + right, pa_table)
					lowerCAmelCase_           = left_shift(left)
					lowerCAmelCase_           = left_shift(right)
					lowerCAmelCase_           = left_shift(left)
					lowerCAmelCase_           = left_shift(right)
					lowerCAmelCase_           = apply_table(left + right, pa_table)

					# encryption
					lowerCAmelCase_           = apply_table(message, IP)
					lowerCAmelCase_           = function(expansion, sa, sa, keya, temp)
					lowerCAmelCase_           = temp[4:] + temp[:4]
					lowerCAmelCase_           = function(expansion, sa, sa, keya, temp)
					lowerCAmelCase_           = apply_table(temp, IP_inv)
					print('Cipher text is:', CT)

					# decryption
					lowerCAmelCase_           = apply_table(CT, IP)
					lowerCAmelCase_           = function(expansion, sa, sa, keya, temp)
					lowerCAmelCase_           = temp[4:] + temp[:4]
					lowerCAmelCase_           = function(expansion, sa, sa, keya, temp)
					lowerCAmelCase_           = apply_table(temp, IP_inv)
					print('Plain text after decypting is:', PT)





