code: 
  
  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
  
  
  UpperCAmelCase_       :				Dict		   =      50_358
  UpperCAmelCase_       :				int		   =      50_362
  
  
  
  
  
  
  @require_torch
  @require_torchaudio
  @require_sentencepiece
  class     lowerCamelCase_			(  unittest.TestCase  ):
  
  
  
  
  	def 					lowerCAmelCase_					(    self	:    str       ):
  		__A   : Optional[int]								= """openai/whisper-small.en"""
  		__A   : Optional[int]								= tempfile.mkdtemp()
  
  
  
  
  	def 					lowerCAmelCase_					(    self	:    str				,			**__A	:    int       ):
  		return WhisperTokenizer.from_pretrained(self.checkpoint				,			**__A       )
  
  
  
  
  	def 					lowerCAmelCase_					(    self	:    List[str]				,			**__A	:    Any       ):
  		return WhisperFeatureExtractor.from_pretrained(self.checkpoint				,			**__A       )
  
  
  
  
  	def 					lowerCAmelCase_					(    self	:    Optional[int]       ):
  		shutil.rmtree(self.tmpdirname       )
  
  
  
  
  	def 					lowerCAmelCase_					(    self	:    Optional[int]       ):
  		__A   : Optional[Any]								= self.get_tokenizer()
  		__A   : List[str]								= self.get_feature_extractor()
  
  		__A   : Union[str, Any]								= WhisperProcessor(tokenizer=__A				,			feature_extractor=__A       )
  
  		processor.save_pretrained(self.tmpdirname       )
  		__A   : Optional[Any]								= 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 					lowerCAmelCase_					(    self	:    str       ):
  		__A   : List[str]								= WhisperProcessor(tokenizer=self.get_tokenizer()				,			feature_extractor=self.get_feature_extractor()       )
  		processor.save_pretrained(self.tmpdirname       )
  
  		__A   : Dict								= self.get_tokenizer(bos_token="""(BOS)"""				,			eos_token="""(EOS)"""       )
  		__A   : str								= self.get_feature_extractor(do_normalize=__A				,			padding_value=1.0       )
  
  		__A   : List[Any]								= 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 					lowerCAmelCase_					(    self	:    Union[str, Any]       ):
  		__A   : Optional[int]								= self.get_feature_extractor()
  		__A   : List[str]								= self.get_tokenizer()
  
  		__A   : str								= WhisperProcessor(tokenizer=__A				,			feature_extractor=__A       )
  
  		__A   : Optional[Any]								= floats_list((3, 1000)       )
  
  		__A   : List[str]								= feature_extractor(__A				,			return_tensors="""np"""       )
  		__A   : int								= 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 					lowerCAmelCase_					(    self	:    List[str]       ):
  		__A   : int								= self.get_feature_extractor()
  		__A   : List[str]								= self.get_tokenizer()
  
  		__A   : Dict								= WhisperProcessor(tokenizer=__A				,			feature_extractor=__A       )
  
  		__A   : int								= """This is a test string"""
  
  		__A   : Optional[Any]								= processor(text=__A       )
  
  		__A   : Any								= tokenizer(__A       )
  
  		for key in encoded_tok.keys():
  			self.assertListEqual(encoded_tok[key]				,			encoded_processor[key]       )
  
  
  
  
  	def 					lowerCAmelCase_					(    self	:    Union[str, Any]       ):
  		__A   : Any								= self.get_feature_extractor()
  		__A   : List[str]								= self.get_tokenizer()
  
  		__A   : Union[str, Any]								= WhisperProcessor(tokenizer=__A				,			feature_extractor=__A       )
  
  		__A   : Tuple								= [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]
  
  		__A   : Dict								= processor.batch_decode(__A       )
  		__A   : List[Any]								= tokenizer.batch_decode(__A       )
  
  		self.assertListEqual(__A				,			__A       )
  
  
  
  
  	def 					lowerCAmelCase_					(    self	:    Optional[Any]       ):
  		__A   : str								= self.get_feature_extractor()
  		__A   : Dict								= self.get_tokenizer()
  
  		__A   : List[str]								= 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 					lowerCAmelCase_					(    self	:    Any       ):
  		__A   : List[str]								= self.get_feature_extractor()
  		__A   : Optional[Any]								= self.get_tokenizer()
  
  		__A   : Optional[Any]								= WhisperProcessor(tokenizer=__A				,			feature_extractor=__A       )
  		__A   : Dict								= 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   : List[Any]								= [TRANSCRIBE, NOTIMESTAMPS]
  		self.assertListEqual([ids[-1] for ids in forced_decoder_ids]				,			__A       )
  
  
  
  
  	def 					lowerCAmelCase_					(    self	:    str       ):
  		__A   : str								= WhisperProcessor(tokenizer=self.get_tokenizer()				,			feature_extractor=self.get_feature_extractor()       )
  		__A   : Optional[Any]								= processor.get_prompt_ids("""Mr. Quilter"""       )
  		__A   : List[str]								= processor.tokenizer.decode(__A       )
  
  		self.assertListEqual(prompt_ids.tolist()				,			[5_0360, 1770, 13, 2264, 346, 353]       )
  		self.assertEqual(__A				,			"""<|startofprev|> Mr. Quilter"""       )
  
  
  
  
  	def 					lowerCAmelCase_					(    self	:    Optional[Any]       ):
  		__A   : Optional[int]								= WhisperProcessor(tokenizer=self.get_tokenizer()				,			feature_extractor=self.get_feature_extractor()       )
  		__A   : Union[str, Any]								= processor.get_prompt_ids(""""""       )
  		__A   : Optional[Any]								= processor.tokenizer.decode(__A       )
  
  		self.assertListEqual(prompt_ids.tolist()				,			[5_0360, 220]       )
  		self.assertEqual(__A				,			"""<|startofprev|> """       )
  
  
  
  
  	def 					lowerCAmelCase_					(    self	:    Dict       ):
  		__A   : Union[str, Any]								= WhisperProcessor(tokenizer=self.get_tokenizer()				,			feature_extractor=self.get_feature_extractor()       )
  
  		def _test_prompt_error_raised_helper(__A	:    Dict				,			__A	:    List[Any]       ):
  			with pytest.raises(__A       ) as excinfo:
  				processor.get_prompt_ids(__A       )
  			__A   : int								= 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|>"""       )
  
  
  
  
  
  
style_context: 
  
  import unittest
  from pathlib import Path
  
  from transformers import is_vision_available, load_tool
  from transformers.testing_utils import get_tests_dir
  
  from .test_tools_common import ToolTesterMixin
  
  
  if is_vision_available():
  			from PIL import Image
  
  
  
  
  
  
  class     lowerCamelCase_			(  unittest.TestCase	,			_lowercase  ):
  
  
  
  
  	def 					lowerCAmelCase_					(    self	:    Dict       ):
  		__A   : str								= load_tool("""image-captioning"""       )
  		self.tool.setup()
  		__A   : Dict								= load_tool("""image-captioning"""				,			remote=__A       )
  
  
  
  
  	def 					lowerCAmelCase_					(    self	:    Optional[int]       ):
  		__A   : List[Any]								= Image.open(Path(get_tests_dir("""fixtures/tests_samples/COCO"""       )       ) / """000000039769.png"""       )
  		__A   : Optional[Any]								= self.tool(__A       )
  		self.assertEqual(__A				,			"""two cats sleeping on a couch"""       )
  
  
  
  
  	def 					lowerCAmelCase_					(    self	:    Dict       ):
  		__A   : Any								= Image.open(Path(get_tests_dir("""fixtures/tests_samples/COCO"""       )       ) / """000000039769.png"""       )
  		__A   : List[str]								= self.remote_tool(__A       )
  		self.assertEqual(__A				,			"""two cats sleeping on a couch"""       )
  
  
  
  
  	def 					lowerCAmelCase_					(    self	:    Union[str, Any]       ):
  		__A   : Optional[Any]								= Image.open(Path(get_tests_dir("""fixtures/tests_samples/COCO"""       )       ) / """000000039769.png"""       )
  		__A   : str								= self.tool(image=__A       )
  		self.assertEqual(__A				,			"""two cats sleeping on a couch"""       )
  
  
  
  
  	def 					lowerCAmelCase_					(    self	:    str       ):
  		__A   : Dict								= Image.open(Path(get_tests_dir("""fixtures/tests_samples/COCO"""       )       ) / """000000039769.png"""       )
  		__A   : List[Any]								= self.remote_tool(image=__A       )
  		self.assertEqual(__A				,			"""two cats sleeping on a couch"""       )
  
  
  
  
  
  