




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


SCREAMING_SNAKE_CASE_    :       int       =							5_03_58
SCREAMING_SNAKE_CASE_    :       List[str]       =							5_03_62







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





     """simple docstring"""



     def 					__SCREAMING_SNAKE_CASE		(   self			:							str     )      ->      Union[str, Any]:






         """simple docstring"""
         a__  			=							"""openai/whisper-small.en"""
         a__  			=							tempfile.mkdtemp()

     def 					__SCREAMING_SNAKE_CASE		(   self			:							str    ,					**A			:							Optional[Any]     )      ->      Union[str, Any]:






         """simple docstring"""
         return WhisperTokenizer.from_pretrained(self.checkpoint    ,					**A     )

     def 					__SCREAMING_SNAKE_CASE		(   self			:							Tuple    ,					**A			:							Dict     )      ->      str:






         """simple docstring"""
         return WhisperFeatureExtractor.from_pretrained(self.checkpoint    ,					**A     )

     def 					__SCREAMING_SNAKE_CASE		(   self			:							Union[str, Any]     )      ->      int:






         """simple docstring"""
         shutil.rmtree(self.tmpdirname     )

     def 					__SCREAMING_SNAKE_CASE		(   self			:							List[Any]     )      ->      Tuple:






         """simple docstring"""
         a__  			=							self.get_tokenizer()
         a__  			=							self.get_feature_extractor()

         a__  			=							WhisperProcessor(tokenizer=A    ,					feature_extractor=A     )

         processor.save_pretrained(self.tmpdirname     )
         a__  			=							WhisperProcessor.from_pretrained(self.tmpdirname     )

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

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

     def 					__SCREAMING_SNAKE_CASE		(   self			:							Tuple     )      ->      List[str]:






         """simple docstring"""
         a__  			=							WhisperProcessor(tokenizer=self.get_tokenizer()    ,					feature_extractor=self.get_feature_extractor()     )
         processor.save_pretrained(self.tmpdirname     )

         a__  			=							self.get_tokenizer(bos_token="""(BOS)"""    ,					eos_token="""(EOS)"""     )
         a__  			=							self.get_feature_extractor(do_normalize=A    ,					padding_value=1.0     )

         a__  			=							WhisperProcessor.from_pretrained(
             self.tmpdirname    ,					bos_token="""(BOS)"""    ,					eos_token="""(EOS)"""    ,					do_normalize=A    ,					padding_value=1.0     )

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

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

     def 					__SCREAMING_SNAKE_CASE		(   self			:							str     )      ->      List[Any]:






         """simple docstring"""
         a__  			=							self.get_feature_extractor()
         a__  			=							self.get_tokenizer()

         a__  			=							WhisperProcessor(tokenizer=A    ,					feature_extractor=A     )

         a__  			=							floats_list((3, 10_00)     )

         a__  			=							feature_extractor(A    ,					return_tensors="""np"""     )
         a__  			=							processor(A    ,					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 					__SCREAMING_SNAKE_CASE		(   self			:							List[str]     )      ->      Dict:






         """simple docstring"""
         a__  			=							self.get_feature_extractor()
         a__  			=							self.get_tokenizer()

         a__  			=							WhisperProcessor(tokenizer=A    ,					feature_extractor=A     )

         a__  			=							"""This is a test string"""

         a__  			=							processor(text=A     )

         a__  			=							tokenizer(A     )

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

     def 					__SCREAMING_SNAKE_CASE		(   self			:							List[Any]     )      ->      Tuple:






         """simple docstring"""
         a__  			=							self.get_feature_extractor()
         a__  			=							self.get_tokenizer()

         a__  			=							WhisperProcessor(tokenizer=A    ,					feature_extractor=A     )

         a__  			=							[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

         a__  			=							processor.batch_decode(A     )
         a__  			=							tokenizer.batch_decode(A     )

         self.assertListEqual(A    ,					A     )

     def 					__SCREAMING_SNAKE_CASE		(   self			:							List[Any]     )      ->      Dict:






         """simple docstring"""
         a__  			=							self.get_feature_extractor()
         a__  			=							self.get_tokenizer()

         a__  			=							WhisperProcessor(tokenizer=A    ,					feature_extractor=A     )

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

     def 					__SCREAMING_SNAKE_CASE		(   self			:							List[str]     )      ->      List[str]:






         """simple docstring"""
         a__  			=							self.get_feature_extractor()
         a__  			=							self.get_tokenizer()

         a__  			=							WhisperProcessor(tokenizer=A    ,					feature_extractor=A     )
         a__  			=							processor.get_decoder_prompt_ids(task="""transcribe"""    ,					no_timestamps=A     )

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

         a__  			=							[TRANSCRIBE, NOTIMESTAMPS]
         self.assertListEqual([ids[-1] for ids in forced_decoder_ids]    ,					A     )

     def 					__SCREAMING_SNAKE_CASE		(   self			:							Union[str, Any]     )      ->      Union[str, Any]:






         """simple docstring"""
         a__  			=							WhisperProcessor(tokenizer=self.get_tokenizer()    ,					feature_extractor=self.get_feature_extractor()     )
         a__  			=							processor.get_prompt_ids("""Mr. Quilter"""     )
         a__  			=							processor.tokenizer.decode(A     )

         self.assertListEqual(prompt_ids.tolist()    ,					[5_03_60, 17_70, 13, 22_64, 3_46, 3_53]     )
         self.assertEqual(A    ,					"""<|startofprev|> Mr. Quilter"""     )

     def 					__SCREAMING_SNAKE_CASE		(   self			:							Dict     )      ->      Any:






         """simple docstring"""
         a__  			=							WhisperProcessor(tokenizer=self.get_tokenizer()    ,					feature_extractor=self.get_feature_extractor()     )
         a__  			=							processor.get_prompt_ids(""""""     )
         a__  			=							processor.tokenizer.decode(A     )

         self.assertListEqual(prompt_ids.tolist()    ,					[5_03_60, 2_20]     )
         self.assertEqual(A    ,					"""<|startofprev|> """     )






     def 					__SCREAMING_SNAKE_CASE		(   self			:							Tuple     )      ->      List[str]:






         """simple docstring"""
         a__  			=							WhisperProcessor(tokenizer=self.get_tokenizer()    ,					feature_extractor=self.get_feature_extractor()     )

         def _test_prompt_error_raised_helper(A			:							Optional[int]    ,					A			:							int     ):
             with pytest.raises(A     ) as excinfo:
                 processor.get_prompt_ids(A     )
             a__  			=							f"""Encountered text in the prompt corresponding to disallowed special token: {special_token}."""
             self.assertEqual(A    ,					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|>"""     )












def 							__lowerCAmelCase			(UpperCAmelCase_		):
    return n * (2 * n - 1)
def 							__lowerCAmelCase			(UpperCAmelCase_		):
    a__  			=							(1 + 24 * n) ** 0.5
    return ((1 + root) / 6) % 1 == 0
def 							__lowerCAmelCase			(UpperCAmelCase_ = 144		):
    a__  			=							start
    a__  			=							hexagonal_num(UpperCAmelCase_		)
    while not is_pentagonal(UpperCAmelCase_		):
        n += 1
        a__  			=							hexagonal_num(UpperCAmelCase_		)
    return num


if __name__ == "__main__":
 print(F"{solution()} = ")






