






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


snake_case   :   Optional[int]    		=		5_0_3_5_8
snake_case   :   List[str]    		=		5_0_3_6_2



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







				"""simple docstring"""







				def 							a__ (		self   :  Tuple   ):





											'''simple docstring'''

											__magic_name__										=						'openai/whisper-small.en'
											__magic_name__										=						tempfile.mkdtemp()







				def 							a__ (		self   :  List[str]							,						**UpperCamelCase_   :  Optional[Any]   ):





											'''simple docstring'''

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







				def 							a__ (		self   :  Optional[Any]							,						**UpperCamelCase_   :  Any   ):





											'''simple docstring'''

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







				def 							a__ (		self   :  List[Any]   ):





											'''simple docstring'''

											shutil.rmtree(self.tmpdirname   )







				def 							a__ (		self   :  Tuple   ):





											'''simple docstring'''

											__magic_name__										=						self.get_tokenizer()
											__magic_name__										=						self.get_feature_extractor()

											__magic_name__										=						WhisperProcessor(tokenizer=__SCREAMING_SNAKE_CASE							,						feature_extractor=__SCREAMING_SNAKE_CASE   )

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

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

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







				def 							a__ (		self   :  Optional[int]   ):





											'''simple docstring'''

											__magic_name__										=						WhisperProcessor(tokenizer=self.get_tokenizer()							,						feature_extractor=self.get_feature_extractor()   )
											processor.save_pretrained(self.tmpdirname   )

											__magic_name__										=						self.get_tokenizer(bos_token='(BOS)'							,						eos_token='(EOS)'   )
											__magic_name__										=						self.get_feature_extractor(do_normalize=__SCREAMING_SNAKE_CASE							,						padding_value=1.0   )

											__magic_name__										=						WhisperProcessor.from_pretrained(
											    self.tmpdirname							,						bos_token='(BOS)'							,						eos_token='(EOS)'							,						do_normalize=__SCREAMING_SNAKE_CASE							,						padding_value=1.0   )

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

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







				def 							a__ (		self   :  int   ):





											'''simple docstring'''

											__magic_name__										=						self.get_feature_extractor()
											__magic_name__										=						self.get_tokenizer()

											__magic_name__										=						WhisperProcessor(tokenizer=__SCREAMING_SNAKE_CASE							,						feature_extractor=__SCREAMING_SNAKE_CASE   )

											__magic_name__										=						floats_list((3, 1_0_0_0)   )

											__magic_name__										=						feature_extractor(__SCREAMING_SNAKE_CASE							,						return_tensors='np'   )
											__magic_name__										=						processor(__SCREAMING_SNAKE_CASE							,						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   :  List[Any]   ):





											'''simple docstring'''

											__magic_name__										=						self.get_feature_extractor()
											__magic_name__										=						self.get_tokenizer()

											__magic_name__										=						WhisperProcessor(tokenizer=__SCREAMING_SNAKE_CASE							,						feature_extractor=__SCREAMING_SNAKE_CASE   )

											__magic_name__										=						'This is a test string'

											__magic_name__										=						processor(text=__SCREAMING_SNAKE_CASE   )

											__magic_name__										=						tokenizer(__SCREAMING_SNAKE_CASE   )

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







				def 							a__ (		self   :  Optional[int]   ):





											'''simple docstring'''

											__magic_name__										=						self.get_feature_extractor()
											__magic_name__										=						self.get_tokenizer()

											__magic_name__										=						WhisperProcessor(tokenizer=__SCREAMING_SNAKE_CASE							,						feature_extractor=__SCREAMING_SNAKE_CASE   )

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

											__magic_name__										=						processor.batch_decode(__SCREAMING_SNAKE_CASE   )
											__magic_name__										=						tokenizer.batch_decode(__SCREAMING_SNAKE_CASE   )

											self.assertListEqual(__SCREAMING_SNAKE_CASE							,						__SCREAMING_SNAKE_CASE   )







				def 							a__ (		self   :  Any   ):





											'''simple docstring'''

											__magic_name__										=						self.get_feature_extractor()
											__magic_name__										=						self.get_tokenizer()

											__magic_name__										=						WhisperProcessor(tokenizer=__SCREAMING_SNAKE_CASE							,						feature_extractor=__SCREAMING_SNAKE_CASE   )

											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   :  Dict   ):





											'''simple docstring'''

											__magic_name__										=						self.get_feature_extractor()
											__magic_name__										=						self.get_tokenizer()

											__magic_name__										=						WhisperProcessor(tokenizer=__SCREAMING_SNAKE_CASE							,						feature_extractor=__SCREAMING_SNAKE_CASE   )
											__magic_name__										=						processor.get_decoder_prompt_ids(task='transcribe'							,						no_timestamps=__SCREAMING_SNAKE_CASE   )

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

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







				def 							a__ (		self   :  str   ):





											'''simple docstring'''

											__magic_name__										=						WhisperProcessor(tokenizer=self.get_tokenizer()							,						feature_extractor=self.get_feature_extractor()   )
											__magic_name__										=						processor.get_prompt_ids('Mr. Quilter'   )
											__magic_name__										=						processor.tokenizer.decode(__SCREAMING_SNAKE_CASE   )

											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(__SCREAMING_SNAKE_CASE							,						'<|startofprev|> Mr. Quilter'   )







				def 							a__ (		self   :  Tuple   ):





											'''simple docstring'''

											__magic_name__										=						WhisperProcessor(tokenizer=self.get_tokenizer()							,						feature_extractor=self.get_feature_extractor()   )
											__magic_name__										=						processor.get_prompt_ids(''   )
											__magic_name__										=						processor.tokenizer.decode(__SCREAMING_SNAKE_CASE   )

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







				def 							a__ (		self   :  Union[str, Any]   ):





											'''simple docstring'''

											__magic_name__										=						WhisperProcessor(tokenizer=self.get_tokenizer()							,						feature_extractor=self.get_feature_extractor()   )

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

       """simple docstring"""





       sequence.append(__snake_case     )

       __magic_name__										=						0
       while sequence[index] != target:
              index += 1

       sequence.pop()

       if index == len(__snake_case     ):
              return None

       return index


if __name__ == "__main__":
 snake_case   :   Dict    		=		input("""Enter numbers separated by comma:\n""").strip()
 snake_case   :   List[str]    		=		[int(item) for item in user_input.split(""",""")]

 snake_case   :   Union[str, Any]    		=		input("""Enter a single number to be found in the list:\n""")
 snake_case   :   str    		=		int(target_input)
 snake_case   :   Any    		=		sentinel_linear_search(sequence, target)
 if result is not None:
  print(f"""{target} found at positions: {result}""")
 else:
  print("""Not found""")