
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


__magic_name__  :  List[Any]     			=   5_0_3_5_8
__magic_name__  :  Tuple     			=   5_0_3_6_2


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



  """simple docstring"""





  def 					lowercase_						(					self					):
      A_								=					'openai/whisper-small.en'
      A_								=					tempfile.mkdtemp()

  def 					lowercase_						(					self						,    **__UpperCamelCase					):
      return WhisperTokenizer.from_pretrained(self.checkpoint						,    **_snake_case					)

  def 					lowercase_						(					self						,    **__UpperCamelCase					):
      return WhisperFeatureExtractor.from_pretrained(self.checkpoint						,    **_snake_case					)

  def 					lowercase_						(					self					):
      shutil.rmtree(self.tmpdirname					)

  def 					lowercase_						(					self					):
      A_								=					self.get_tokenizer()
      A_								=					self.get_feature_extractor()

      A_								=					WhisperProcessor(tokenizer=_snake_case						,    feature_extractor=_snake_case					)

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

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

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

  def 					lowercase_						(					self					):
      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=_snake_case						,    padding_value=1.0					)

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

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

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

  def 					lowercase_						(					self					):
      A_								=					self.get_feature_extractor()
      A_								=					self.get_tokenizer()

      A_								=					WhisperProcessor(tokenizer=_snake_case						,    feature_extractor=_snake_case					)

      A_								=					floats_list((3, 1000)					)

      A_								=					feature_extractor(_snake_case						,    return_tensors="np"					)
      A_								=					processor(_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 					lowercase_						(					self					):
      A_								=					self.get_feature_extractor()
      A_								=					self.get_tokenizer()

      A_								=					WhisperProcessor(tokenizer=_snake_case						,    feature_extractor=_snake_case					)

      A_								=					'This is a test string'

      A_								=					processor(text=_snake_case					)

      A_								=					tokenizer(_snake_case					)

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

  def 					lowercase_						(					self					):
      A_								=					self.get_feature_extractor()
      A_								=					self.get_tokenizer()

      A_								=					WhisperProcessor(tokenizer=_snake_case						,    feature_extractor=_snake_case					)

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

      A_								=					processor.batch_decode(_snake_case					)
      A_								=					tokenizer.batch_decode(_snake_case					)

      self.assertListEqual(_snake_case						,    _snake_case					)

  def 					lowercase_						(					self					):
      A_								=					self.get_feature_extractor()
      A_								=					self.get_tokenizer()

      A_								=					WhisperProcessor(tokenizer=_snake_case						,    feature_extractor=_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 					lowercase_						(					self					):
      A_								=					self.get_feature_extractor()
      A_								=					self.get_tokenizer()

      A_								=					WhisperProcessor(tokenizer=_snake_case						,    feature_extractor=_snake_case					)
      A_								=					processor.get_decoder_prompt_ids(task="transcribe"						,    no_timestamps=_snake_case					)

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

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

  def 					lowercase_						(					self					):
      A_								=					WhisperProcessor(tokenizer=self.get_tokenizer()						,    feature_extractor=self.get_feature_extractor()					)
      A_								=					processor.get_prompt_ids("Mr. Quilter"					)
      A_								=					processor.tokenizer.decode(_snake_case					)

      self.assertListEqual(prompt_ids.tolist()						,    [50360, 1770, 13, 2264, 346, 353]					)
      self.assertEqual(_snake_case						,    "<|startofprev|> Mr. Quilter"					)

  def 					lowercase_						(					self					):
      A_								=					WhisperProcessor(tokenizer=self.get_tokenizer()						,    feature_extractor=self.get_feature_extractor()					)
      A_								=					processor.get_prompt_ids(""					)
      A_								=					processor.tokenizer.decode(_snake_case					)

      self.assertListEqual(prompt_ids.tolist()						,    [50360, 220]					)
      self.assertEqual(_snake_case						,    "<|startofprev|> "					)

  def 					lowercase_						(					self					):
      A_								=					WhisperProcessor(tokenizer=self.get_tokenizer()						,    feature_extractor=self.get_feature_extractor()					)

      def _test_prompt_error_raised_helper(__UpperCamelCase						,    __UpperCamelCase					):
          with pytest.raises(_snake_case					) as excinfo:
              processor.get_prompt_ids(_snake_case					)
          A_								=					f'Encountered text in the prompt corresponding to disallowed special token: {special_token}.'
          self.assertEqual(_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     SCREAMING_SNAKE_CASE(	UpperCamelCase	)     ->     int:
	if not isinstance(UpperCamelCase ,UpperCamelCase	):
		raise TypeError('recursive_lucas_number accepts only integer arguments.'	)
	if n_th_number == 0:
		return 2
	if n_th_number == 1:
		return 1

	return recursive_lucas_number(n_th_number - 1	) + recursive_lucas_number(
	    n_th_number - 2	)







def     SCREAMING_SNAKE_CASE(	UpperCamelCase	)     ->     int:
	if not isinstance(UpperCamelCase ,UpperCamelCase	):
		raise TypeError('dynamic_lucas_number accepts only integer arguments.'	)
	UpperCAmelCase_						,     UpperCAmelCase_		:   List[str]													=       2, 1
	for _ in range(UpperCamelCase	):
		UpperCAmelCase_						,     UpperCAmelCase_		:   Dict													=       b, a + b
	return a


if __name__ == "__main__":
						from doctest import testmod

						testmod()
						lowerCAmelCase__      				=			int(input("Enter the number of terms in lucas series:\n").strip())
						print("Using recursive function to calculate lucas series:")
						print(" ".join(str(recursive_lucas_number(i)) for i in range(n)))
						print("\nUsing dynamic function to calculate lucas series:")
						print(" ".join(str(dynamic_lucas_number(i)) for i in range(n)))






