code: 
  
  
  
  
  
  '''simple docstring'''
  
  
  import unittest
  
  import numpy as np
  
  from transformers.testing_utils import require_torch, require_vision
  from transformers.utils import is_torch_available, is_vision_available
  
  from ...test_image_processing_common import ImageProcessingSavingTestMixin
  
  
  if is_torch_available():
  				import torch
  
  if is_vision_available():
  				from PIL import Image
  
  				from transformers import TvltImageProcessor
  
  
  
  
  def    __a (     UpperCAmelCase       ,			UpperCAmelCase=10       ,			UpperCAmelCase=10       ,			UpperCAmelCase=False       ,			UpperCAmelCase=False    )      ->Optional[int]:
  
  
  
  	"""simple docstring"""
  
  
  
  
  
  
  
  	A							  =      []
  	for i in range(image_processor_tester.num_frames    ):
  		video.append(np.random.randint(255       ,			size=(image_processor_tester.num_channels, width, height)       ,			dtype=np.uinta    )    )
  
  	if not numpify and not torchify:
  		# PIL expects the channel dimension as last dimension
  		A							  =      [Image.fromarray(np.moveaxis(UpperCAmelCase       ,			0       ,			-1    )    ) for frame in video]
  
  	if torchify:
  		A							  =      [torch.from_numpy(UpperCAmelCase    ) for frame in video]
  
  	return video
  
  
  
  
  def    __a (     UpperCAmelCase       ,			UpperCAmelCase=False       ,			UpperCAmelCase=False       ,			UpperCAmelCase=False    )      ->Tuple:
  
  
  
  	"""simple docstring"""
  
  
  
  
  
  
  
  	assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"
  
  	A							  =      []
  	for i in range(image_processor_tester.batch_size    ):
  		if equal_resolution:
  			A							  =      A							  =      image_processor_tester.max_resolution
  		else:
  			A  ,    A							  =      np.random.choice(
  			    np.arange(image_processor_tester.min_resolution       ,			image_processor_tester.max_resolution    )       ,			2    )
  			A							  =      prepare_video(
  			    image_processor_tester=UpperCAmelCase       ,			width=UpperCAmelCase       ,			height=UpperCAmelCase       ,			numpify=UpperCAmelCase       ,			torchify=UpperCAmelCase       ,			)
  		video_inputs.append(UpperCAmelCase    )
  
  	return video_inputs
  
  
  
  class 							__UpperCAmelCase  (       unittest.TestCase						):
  
  
  
  
  
  
  
  		'''simple docstring'''
  
  
  
  
  
  
  
  		def __init__(self						:      str      ,      _lowerCAmelCase						:      List[Any]      ,      _lowerCAmelCase						:      Dict=7      ,      _lowerCAmelCase						:      Tuple=3      ,      _lowerCAmelCase						:      Optional[Any]=4      ,      _lowerCAmelCase						:      Union[str, Any]=18      ,      _lowerCAmelCase						:      List[Any]=30      ,      _lowerCAmelCase						:      List[Any]=400      ,      _lowerCAmelCase						:      Dict=True      ,      _lowerCAmelCase						:      List[str]=None      ,      _lowerCAmelCase						:      Dict=True      ,      _lowerCAmelCase						:      Dict=[0.5, 0.5, 0.5]      ,      _lowerCAmelCase						:      Optional[int]=[0.5, 0.5, 0.5]      ,      _lowerCAmelCase						:      List[str]=True      ,      _lowerCAmelCase						:      int=None      ,      ):
  			A							  =      size if size is not None else {"""shortest_edge""": 18}
  			A							  =      crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
  
  			A							  =      parent
  			A							  =      batch_size
  			A							  =      num_channels
  			A							  =      num_frames
  			A							  =      image_size
  			A							  =      min_resolution
  			A							  =      max_resolution
  			A							  =      do_resize
  			A							  =      size
  			A							  =      do_normalize
  			A							  =      image_mean
  			A							  =      image_std
  			A							  =      do_center_crop
  			A							  =      crop_size
  
  
  
  
  
  
  
  		def        A     (self						:      Tuple      ):
  			return {
  			    "image_mean": self.image_mean,
  			    "image_std": self.image_std,
  			    "do_normalize": self.do_normalize,
  			    "do_resize": self.do_resize,
  			    "size": self.size,
  			    "do_center_crop": self.do_center_crop,
  			    "crop_size": self.crop_size,
  			}
  
  
  
  
  
  
  @require_torch
  @require_vision
  class 							__UpperCAmelCase  (       A__		,					unittest.TestCase						):
  
  
  
  
  
  
  
  		'''simple docstring'''
  
  
  
  
  
  
  
  		__lowerCAmelCase 				=    TvltImageProcessor if is_vision_available() else None
  
  
  
  
  
  
  
  		def        A     (self						:      Tuple      ):
  			A							  =      TvltImageProcessorTester(self      )
  
  
  
  
  
  
  
  		@property
  		def        A     (self						:      Optional[int]      ):
  			return self.image_processor_tester.prepare_image_processor_dict()
  
  
  
  
  
  
  
  		def        A     (self						:      Any      ):
  			A							  =      self.image_processing_class(**self.image_processor_dict      )
  			self.assertTrue(hasattr(_lowerCAmelCase      ,      """image_mean"""      )      )
  			self.assertTrue(hasattr(_lowerCAmelCase      ,      """image_std"""      )      )
  			self.assertTrue(hasattr(_lowerCAmelCase      ,      """do_normalize"""      )      )
  			self.assertTrue(hasattr(_lowerCAmelCase      ,      """do_resize"""      )      )
  			self.assertTrue(hasattr(_lowerCAmelCase      ,      """do_center_crop"""      )      )
  			self.assertTrue(hasattr(_lowerCAmelCase      ,      """size"""      )      )
  
  
  
  
  
  
  
  		def        A     (self						:      str      ):
  			# Initialize image_processor
  			A							  =      self.image_processing_class(**self.image_processor_dict      )
  			# create random PIL videos
  			A							  =      prepare_video_inputs(self.image_processor_tester      ,      equal_resolution=_lowerCAmelCase      )
  			for video in video_inputs:
  				self.assertIsInstance(_lowerCAmelCase      ,      _lowerCAmelCase      )
  				self.assertIsInstance(video[0]      ,      Image.Image      )
  
  			# Test not batched input
  			A							  =      image_processor(video_inputs[0]      ,      return_tensors="""pt"""      ).pixel_values
  			self.assertEqual(
  			    encoded_videos.shape      ,      (
  			        1,
  			        self.image_processor_tester.num_frames,
  			        self.image_processor_tester.num_channels,
  			        self.image_processor_tester.crop_size["""height"""],
  			        self.image_processor_tester.crop_size["""width"""],
  			    )      ,      )
  
  			# Test batched
  			A							  =      image_processor(_lowerCAmelCase      ,      return_tensors="""pt"""      ).pixel_values
  			self.assertEqual(
  			    encoded_videos.shape      ,      (
  			        self.image_processor_tester.batch_size,
  			        self.image_processor_tester.num_frames,
  			        self.image_processor_tester.num_channels,
  			        self.image_processor_tester.crop_size["""height"""],
  			        self.image_processor_tester.crop_size["""width"""],
  			    )      ,      )
  
  
  
  
  
  
  
  		def        A     (self						:      Optional[int]      ):
  			# Initialize image_processor
  			A							  =      self.image_processing_class(**self.image_processor_dict      )
  			# create random numpy tensors
  			A							  =      prepare_video_inputs(self.image_processor_tester      ,      equal_resolution=_lowerCAmelCase      ,      numpify=_lowerCAmelCase      )
  			for video in video_inputs:
  				self.assertIsInstance(_lowerCAmelCase      ,      _lowerCAmelCase      )
  				self.assertIsInstance(video[0]      ,      np.ndarray      )
  
  			# Test not batched input
  			A							  =      image_processor(video_inputs[0]      ,      return_tensors="""pt"""      ).pixel_values
  			self.assertEqual(
  			    encoded_videos.shape      ,      (
  			        1,
  			        self.image_processor_tester.num_frames,
  			        self.image_processor_tester.num_channels,
  			        self.image_processor_tester.crop_size["""height"""],
  			        self.image_processor_tester.crop_size["""width"""],
  			    )      ,      )
  
  			# Test batched
  			A							  =      image_processor(_lowerCAmelCase      ,      return_tensors="""pt"""      ).pixel_values
  			self.assertEqual(
  			    encoded_videos.shape      ,      (
  			        self.image_processor_tester.batch_size,
  			        self.image_processor_tester.num_frames,
  			        self.image_processor_tester.num_channels,
  			        self.image_processor_tester.crop_size["""height"""],
  			        self.image_processor_tester.crop_size["""width"""],
  			    )      ,      )
  
  
  
  
  
  
  
  		def        A     (self						:      Dict      ):
  			# Initialize image_processor
  			A							  =      self.image_processing_class(**self.image_processor_dict      )
  			# create random PyTorch tensors
  			A							  =      prepare_video_inputs(self.image_processor_tester      ,      equal_resolution=_lowerCAmelCase      ,      torchify=_lowerCAmelCase      )
  			for video in video_inputs:
  				self.assertIsInstance(_lowerCAmelCase      ,      _lowerCAmelCase      )
  				self.assertIsInstance(video[0]      ,      torch.Tensor      )
  
  			# Test not batched input
  			A							  =      image_processor(video_inputs[0]      ,      return_tensors="""pt"""      ).pixel_values
  			self.assertEqual(
  			    encoded_videos.shape      ,      (
  			        1,
  			        self.image_processor_tester.num_frames,
  			        self.image_processor_tester.num_channels,
  			        self.image_processor_tester.crop_size["""height"""],
  			        self.image_processor_tester.crop_size["""width"""],
  			    )      ,      )
  
  			# Test batched
  			A							  =      image_processor(_lowerCAmelCase      ,      return_tensors="""pt"""      ).pixel_values
  			self.assertEqual(
  			    encoded_videos.shape      ,      (
  			        self.image_processor_tester.batch_size,
  			        self.image_processor_tester.num_frames,
  			        self.image_processor_tester.num_channels,
  			        self.image_processor_tester.crop_size["""height"""],
  			        self.image_processor_tester.crop_size["""width"""],
  			    )      ,      )
  
  
style_context: 
  
  
  
  
  
  '''simple docstring'''
  
  
  from typing import Dict, List, Optional, Tuple
  
  from ...tokenization_utils import AddedToken, PreTrainedTokenizer
  from ...utils import logging
  
  
  _lowerCamelCase				:	int				    =       logging.get_logger(__name__)
  
  
  
  class 							__UpperCAmelCase  (       A__						):
  
  
  
  
  
  
  
  		'''simple docstring'''
  
  
  
  
  
  
  
  		__lowerCAmelCase 				=    ['''input_ids''', '''attention_mask''']
  
  
  
  
  
  
  
  		def __init__(self						:      Tuple      ,      _lowerCAmelCase						:      str="[PAD]"      ,      _lowerCAmelCase						:      Dict="[BOS]"      ,      _lowerCAmelCase						:      Any="[EOS]"      ,      _lowerCAmelCase						:      List[Any]="[MASK]"      ,      _lowerCAmelCase						:      int="[CLS]"      ,      _lowerCAmelCase						:      Optional[Any]="[SEP]"      ,      _lowerCAmelCase						:      List[str]=2048      ,      **_lowerCAmelCase						:      Dict      ,      ):
  			A							  =      AddedToken(_lowerCAmelCase      ,      lstrip=_lowerCAmelCase      ,      rstrip=_lowerCAmelCase      ) if isinstance(_lowerCAmelCase      ,      _lowerCAmelCase      ) else pad_token
  			A							  =      AddedToken(_lowerCAmelCase      ,      lstrip=_lowerCAmelCase      ,      rstrip=_lowerCAmelCase      ) if isinstance(_lowerCAmelCase      ,      _lowerCAmelCase      ) else bos_token
  			A							  =      AddedToken(_lowerCAmelCase      ,      lstrip=_lowerCAmelCase      ,      rstrip=_lowerCAmelCase      ) if isinstance(_lowerCAmelCase      ,      _lowerCAmelCase      ) else eos_token
  			A							  =      AddedToken(_lowerCAmelCase      ,      lstrip=_lowerCAmelCase      ,      rstrip=_lowerCAmelCase      ) if isinstance(_lowerCAmelCase      ,      _lowerCAmelCase      ) else mask_token
  			A							  =      AddedToken(_lowerCAmelCase      ,      lstrip=_lowerCAmelCase      ,      rstrip=_lowerCAmelCase      ) if isinstance(_lowerCAmelCase      ,      _lowerCAmelCase      ) else cls_token
  			A							  =      AddedToken(_lowerCAmelCase      ,      lstrip=_lowerCAmelCase      ,      rstrip=_lowerCAmelCase      ) if isinstance(_lowerCAmelCase      ,      _lowerCAmelCase      ) else sep_token
  
  			super().__init__(
  			    pad_token=_lowerCAmelCase      ,      bos_token=_lowerCAmelCase      ,      eos_token=_lowerCAmelCase      ,      mask_token=_lowerCAmelCase      ,      cls_token=_lowerCAmelCase      ,      sep_token=_lowerCAmelCase      ,      model_max_length=_lowerCAmelCase      ,      **_lowerCAmelCase      ,      )
  
  			A							  =      2**8  # utf is 8 bits
  
  			# define special tokens dict
  			A							  =      {
  			    self.pad_token: 0,
  			    self.bos_token: 1,
  			    self.eos_token: 2,
  			    self.mask_token: 3,
  			    self.cls_token: 4,
  			    self.sep_token: 5,
  			}
  			A							  =      len(self.special_tokens_encoder      )
  			A							  =      {v: k for k, v in self.special_tokens_encoder.items()}
  
  
  
  
  
  
  
  		def        A     (self						:      Tuple      ):
  			A							  =      self.special_tokens_encoder.copy()
  			vocab.update(self.added_tokens_encoder      )
  			for i in range(self._utf_vocab_size      ):
  				A							  =      chr(_lowerCAmelCase      )
  				A							  =      i + len(self.special_tokens_encoder      )
  			return vocab
  
  
  
  
  
  
  
  		@property
  		def        A     (self						:      Tuple      ):
  			return self._utf_vocab_size + self._num_special_tokens
  
  
  
  
  
  
  
  		def        A     (self						:      Union[str, Any]      ,      _lowerCAmelCase						:      List[int]      ,      _lowerCAmelCase						:      Optional[List[int]] = None      ,      _lowerCAmelCase						:      bool = False      ):
  			if already_has_special_tokens:
  				return super().get_special_tokens_mask(
  				    token_ids_a=_lowerCAmelCase      ,      token_ids_a=_lowerCAmelCase      ,      already_has_special_tokens=_lowerCAmelCase      )
  
  			# normal case: some special tokens
  			if token_ids_a is None:
  				return [1] + [0] * len(_lowerCAmelCase      ) + [1]
  			return [1] + ([0] * len(_lowerCAmelCase      )) + [1] + ([0] * len(_lowerCAmelCase      )) + [1]
  
  
  
  
  
  
  
  		def        A     (self						:      List[Any]      ,      _lowerCAmelCase						:      List[int]      ,      _lowerCAmelCase						:      Optional[List[int]] = None      ):
  			if token_ids_a is None:
  				return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
  			else:
  				return [self.cls_token_id] + token_ids_a + [self.sep_token_id] + token_ids_a + [self.sep_token_id]
  
  
  
  
  
  
  
  		def        A     (self						:      str      ,      _lowerCAmelCase						:      str      ):
  			A							  =      [chr(_lowerCAmelCase      ) for i in text.encode("""utf-8"""      )]
  			return tokens
  
  
  
  
  
  
  
  		def        A     (self						:      int      ,      _lowerCAmelCase						:      List[str]      ):
  			if token in self.special_tokens_encoder:
  				A							  =      self.special_tokens_encoder[token]
  			elif token in self.added_tokens_encoder:
  				A							  =      self.added_tokens_encoder[token]
  			elif len(_lowerCAmelCase      ) != 1:
  				A							  =      self.unk_token_id
  			else:
  				A							  =      ord(_lowerCAmelCase      ) + self._num_special_tokens
  			return token_id
  
  
  
  
  
  
  
  		def        A     (self						:      Optional[int]      ,      _lowerCAmelCase						:      Any      ):
  			if index in self.special_tokens_decoder:
  				A							  =      self.special_tokens_decoder[index]
  			elif index in self.added_tokens_decoder:
  				A							  =      self.added_tokens_decoder[index]
  			else:
  				A							  =      chr(index - self._num_special_tokens      )
  			return token
  
  
  
  
  
  
  
  		def        A     (self						:      Dict      ,      _lowerCAmelCase						:      List[str]      ):
  			A							  =      b""""""
  			for token in tokens:
  				if token in self.special_tokens_decoder:
  					A							  =      self.special_tokens_decoder[token].encode("""utf-8"""      )
  				elif token in self.added_tokens_decoder:
  					A							  =      self.special_tokens_decoder[token].encode("""utf-8"""      )
  				elif token in self.special_tokens_encoder:
  					A							  =      token.encode("""utf-8"""      )
  				elif token in self.added_tokens_encoder:
  					A							  =      token.encode("""utf-8"""      )
  				else:
  					A							  =      bytes([ord(_lowerCAmelCase      )]      )
  				bstring += tok_string
  			A							  =      bstring.decode("""utf-8"""      ,      errors="""replace"""      )
  			return string
  
  
  
  
  
  
  
  		def        A     (self						:      Tuple      ,      _lowerCAmelCase						:      str      ,      _lowerCAmelCase						:      Optional[str] = None      ):
  			return ()
  
  