






"""simple docstring"""
import shutil
import tempfile
import unittest

import pytest

from transformers import WhisperTokenizer, is_speech_available
from transformers.testing_utils import require_sentencepiece, require_torch, require_torchaudio

from .test_feature_extraction_whisper import floats_list


if is_speech_available():
      from transformers import WhisperFeatureExtractor, WhisperProcessor


A_			: List[str]				=			5_03_58
A_			: Dict				=			5_03_62



@require_torch
@require_torchaudio
@require_sentencepiece
class 		a_      (	unittest.TestCase ):







      '''simple docstring'''

      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			Any     				=						'openai/whisper-small.en'
       lowerCamelCase__     :			List[str]     				=						tempfile.mkdtemp()




      def 			a__							(self,     **lowerCamelCase_					):

       '''simple docstring'''



       return WhisperTokenizer.from_pretrained(self.checkpoint,     **lowerCamelCase_					)




      def 			a__							(self,     **lowerCamelCase_					):

       '''simple docstring'''



       return WhisperFeatureExtractor.from_pretrained(self.checkpoint,     **lowerCamelCase_					)




      def 			a__							(self					):

       '''simple docstring'''



       shutil.rmtree(self.tmpdirname					)




      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			int     				=						self.get_tokenizer()
       lowerCamelCase__     :			Dict     				=						self.get_feature_extractor()

       lowerCamelCase__     :			str     				=						WhisperProcessor(tokenizer=lowerCamelCase_,     feature_extractor=lowerCamelCase_					)

       processor.save_pretrained(self.tmpdirname					)
       lowerCamelCase__     :			int     				=						WhisperProcessor.from_pretrained(self.tmpdirname					)

       self.assertEqual(processor.tokenizer.get_vocab(),     tokenizer.get_vocab()					)
       self.assertIsInstance(processor.tokenizer,     lowerCamelCase_					)

       self.assertEqual(processor.feature_extractor.to_json_string(),     feature_extractor.to_json_string()					)
       self.assertIsInstance(processor.feature_extractor,     lowerCamelCase_					)




      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			Tuple     				=						WhisperProcessor(tokenizer=self.get_tokenizer(),     feature_extractor=self.get_feature_extractor()					)
       processor.save_pretrained(self.tmpdirname					)

       lowerCamelCase__     :			int     				=						self.get_tokenizer(bos_token='(BOS)',     eos_token='(EOS)'					)
       lowerCamelCase__     :			List[str]     				=						self.get_feature_extractor(do_normalize=lowerCamelCase_,     padding_value=1.0					)

       lowerCamelCase__     :			str     				=						WhisperProcessor.from_pretrained(
           self.tmpdirname,     bos_token='(BOS)',     eos_token='(EOS)',     do_normalize=lowerCamelCase_,     padding_value=1.0					)

       self.assertEqual(processor.tokenizer.get_vocab(),     tokenizer_add_kwargs.get_vocab()					)
       self.assertIsInstance(processor.tokenizer,     lowerCamelCase_					)

       self.assertEqual(processor.feature_extractor.to_json_string(),     feature_extractor_add_kwargs.to_json_string()					)
       self.assertIsInstance(processor.feature_extractor,     lowerCamelCase_					)




      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			str     				=						self.get_feature_extractor()
       lowerCamelCase__     :			Union[str, Any]     				=						self.get_tokenizer()

       lowerCamelCase__     :			List[str]     				=						WhisperProcessor(tokenizer=lowerCamelCase_,     feature_extractor=lowerCamelCase_					)

       lowerCamelCase__     :			int     				=						floats_list((3, 1_0_0_0)					)

       lowerCamelCase__     :			Any     				=						feature_extractor(lowerCamelCase_,     return_tensors='np'					)
       lowerCamelCase__     :			Optional[Any]     				=						processor(lowerCamelCase_,     return_tensors='np'					)

       for key in input_feat_extract.keys():
        self.assertAlmostEqual(input_feat_extract[key].sum(),     input_processor[key].sum(),     delta=1e-2					)




      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			Dict     				=						self.get_feature_extractor()
       lowerCamelCase__     :			Dict     				=						self.get_tokenizer()

       lowerCamelCase__     :			int     				=						WhisperProcessor(tokenizer=lowerCamelCase_,     feature_extractor=lowerCamelCase_					)

       lowerCamelCase__     :			Any     				=						'This is a test string'

       lowerCamelCase__     :			List[str]     				=						processor(text=lowerCamelCase_					)

       lowerCamelCase__     :			Optional[Any]     				=						tokenizer(lowerCamelCase_					)

       for key in encoded_tok.keys():
        self.assertListEqual(encoded_tok[key],     encoded_processor[key]					)




      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			Dict     				=						self.get_feature_extractor()
       lowerCamelCase__     :			List[str]     				=						self.get_tokenizer()

       lowerCamelCase__     :			Any     				=						WhisperProcessor(tokenizer=lowerCamelCase_,     feature_extractor=lowerCamelCase_					)

       lowerCamelCase__     :			str     				=						[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

       lowerCamelCase__     :			int     				=						processor.batch_decode(lowerCamelCase_					)
       lowerCamelCase__     :			Optional[Any]     				=						tokenizer.batch_decode(lowerCamelCase_					)

       self.assertListEqual(lowerCamelCase_,     lowerCamelCase_					)




      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			Optional[int]     				=						self.get_feature_extractor()
       lowerCamelCase__     :			Tuple     				=						self.get_tokenizer()

       lowerCamelCase__     :			Dict     				=						WhisperProcessor(tokenizer=lowerCamelCase_,     feature_extractor=lowerCamelCase_					)

       self.assertListEqual(
           processor.model_input_names,     feature_extractor.model_input_names,     msg='`processor` and `feature_extractor` model input names do not match',     )




      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			Optional[Any]     				=						self.get_feature_extractor()
       lowerCamelCase__     :			Tuple     				=						self.get_tokenizer()

       lowerCamelCase__     :			Optional[int]     				=						WhisperProcessor(tokenizer=lowerCamelCase_,     feature_extractor=lowerCamelCase_					)
       lowerCamelCase__     :			int     				=						processor.get_decoder_prompt_ids(task='transcribe',     no_timestamps=lowerCamelCase_					)

       self.assertIsInstance(lowerCamelCase_,     lowerCamelCase_					)
       for ids in forced_decoder_ids:
        self.assertIsInstance(lowerCamelCase_,     (list, tuple)					)

       lowerCamelCase__     :			Tuple     				=						[TRANSCRIBE, NOTIMESTAMPS]
       self.assertListEqual([ids[-1] for ids in forced_decoder_ids],     lowerCamelCase_					)




      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			Tuple     				=						WhisperProcessor(tokenizer=self.get_tokenizer(),     feature_extractor=self.get_feature_extractor()					)
       lowerCamelCase__     :			Tuple     				=						processor.get_prompt_ids('Mr. Quilter'					)
       lowerCamelCase__     :			str     				=						processor.tokenizer.decode(lowerCamelCase_					)

       self.assertListEqual(prompt_ids.tolist(),     [5_0_3_6_0, 1_7_7_0, 1_3, 2_2_6_4, 3_4_6, 3_5_3]					)
       self.assertEqual(lowerCamelCase_,     '<|startofprev|> Mr. Quilter'					)




      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			Dict     				=						WhisperProcessor(tokenizer=self.get_tokenizer(),     feature_extractor=self.get_feature_extractor()					)
       lowerCamelCase__     :			List[str]     				=						processor.get_prompt_ids(''					)
       lowerCamelCase__     :			Tuple     				=						processor.tokenizer.decode(lowerCamelCase_					)

       self.assertListEqual(prompt_ids.tolist(),     [5_0_3_6_0, 2_2_0]					)
       self.assertEqual(lowerCamelCase_,     '<|startofprev|> '					)





      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			Any     				=						WhisperProcessor(tokenizer=self.get_tokenizer(),     feature_extractor=self.get_feature_extractor()					)

       def _test_prompt_error_raised_helper(lowerCamelCase_,     lowerCamelCase_					):
        with pytest.raises(lowerCamelCase_					) as excinfo:
         processor.get_prompt_ids(lowerCamelCase_					)
        lowerCamelCase__     :			List[Any]     				=						f'''Encountered text in the prompt corresponding to disallowed special token: {special_token}.'''
        self.assertEqual(lowerCamelCase_,     str(excinfo.value					)					)

       _test_prompt_error_raised_helper('<|startofprev|> test',     '<|startofprev|>'					)
       _test_prompt_error_raised_helper('test <|notimestamps|>',     '<|notimestamps|>'					)
       _test_prompt_error_raised_helper('test <|zh|> test <|transcribe|>',     '<|zh|>'					)









"""simple docstring"""
def        lowerCamelCase_  (						_lowerCamelCase				):
 return 1 if input_a == 0 else 0






def        lowerCamelCase_  (						):
 assert not_gate(0				) == 1
 assert not_gate(1				) == 0


if __name__ == "__main__":
      print(not_gate(0))
      print(not_gate(1))

