from typing import List, Optional, Union

from ...image_utils import ImageInput
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType



class  SCREAMING_SNAKE_CASE_ (					lowerCAmelCase_			):
  '''simple docstring'''


  lowercase		:     Tuple            =				["image_processor", "tokenizer"]
  lowercase		:     Optional[Any]            =				"BlipImageProcessor"
  lowercase		:     int            =				("BertTokenizer", "BertTokenizerFast")







  def __init__(				self    :					Optional[Any]      ,	SCREAMING_SNAKE_CASE__    :					Dict      ,	SCREAMING_SNAKE_CASE__    :					Optional[Any]     )    ->				Tuple:
         A						:     Optional[Any]         =False
         super().__init__(SCREAMING_SNAKE_CASE__      ,	SCREAMING_SNAKE_CASE__     )
         A						:     Tuple         =self.image_processor







  def __call__(				self    :					List[Any]      ,	SCREAMING_SNAKE_CASE__    :					ImageInput = None      ,	SCREAMING_SNAKE_CASE__    :					Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None      ,	SCREAMING_SNAKE_CASE__    :					bool = True      ,	SCREAMING_SNAKE_CASE__    :					Union[bool, str, PaddingStrategy] = False      ,	SCREAMING_SNAKE_CASE__    :					Union[bool, str, TruncationStrategy] = None      ,	SCREAMING_SNAKE_CASE__    :					Optional[int] = None      ,	SCREAMING_SNAKE_CASE__    :					int = 0      ,	SCREAMING_SNAKE_CASE__    :					Optional[int] = None      ,	SCREAMING_SNAKE_CASE__    :					Optional[bool] = None      ,	SCREAMING_SNAKE_CASE__    :					bool = False      ,	SCREAMING_SNAKE_CASE__    :					bool = False      ,	SCREAMING_SNAKE_CASE__    :					bool = False      ,	SCREAMING_SNAKE_CASE__    :					bool = False      ,	SCREAMING_SNAKE_CASE__    :					bool = False      ,	SCREAMING_SNAKE_CASE__    :					bool = True      ,	SCREAMING_SNAKE_CASE__    :					Optional[Union[str, TensorType]] = None      ,	**SCREAMING_SNAKE_CASE__    :					Optional[Any]      ,	)    ->				BatchEncoding:
         if images is None and text is None:
                raise ValueError('You have to specify either images or text.'     )

         # Get only text
         if images is None:
                A						:     Optional[int]         =self.tokenizer
                A						:     Union[str, Any]         =self.tokenizer(
                    text=SCREAMING_SNAKE_CASE__      ,	add_special_tokens=SCREAMING_SNAKE_CASE__      ,	padding=SCREAMING_SNAKE_CASE__      ,	truncation=SCREAMING_SNAKE_CASE__      ,	max_length=SCREAMING_SNAKE_CASE__      ,	stride=SCREAMING_SNAKE_CASE__      ,	pad_to_multiple_of=SCREAMING_SNAKE_CASE__      ,	return_attention_mask=SCREAMING_SNAKE_CASE__      ,	return_overflowing_tokens=SCREAMING_SNAKE_CASE__      ,	return_special_tokens_mask=SCREAMING_SNAKE_CASE__      ,	return_offsets_mapping=SCREAMING_SNAKE_CASE__      ,	return_token_type_ids=SCREAMING_SNAKE_CASE__      ,	return_length=SCREAMING_SNAKE_CASE__      ,	verbose=SCREAMING_SNAKE_CASE__      ,	return_tensors=SCREAMING_SNAKE_CASE__      ,	**SCREAMING_SNAKE_CASE__      ,	)
                return text_encoding

         # add pixel_values
         A						:     int         =self.image_processor(SCREAMING_SNAKE_CASE__      ,	return_tensors=SCREAMING_SNAKE_CASE__     )

         if text is not None:
                A						:     Union[str, Any]         =self.tokenizer(
                    text=SCREAMING_SNAKE_CASE__      ,	add_special_tokens=SCREAMING_SNAKE_CASE__      ,	padding=SCREAMING_SNAKE_CASE__      ,	truncation=SCREAMING_SNAKE_CASE__      ,	max_length=SCREAMING_SNAKE_CASE__      ,	stride=SCREAMING_SNAKE_CASE__      ,	pad_to_multiple_of=SCREAMING_SNAKE_CASE__      ,	return_attention_mask=SCREAMING_SNAKE_CASE__      ,	return_overflowing_tokens=SCREAMING_SNAKE_CASE__      ,	return_special_tokens_mask=SCREAMING_SNAKE_CASE__      ,	return_offsets_mapping=SCREAMING_SNAKE_CASE__      ,	return_token_type_ids=SCREAMING_SNAKE_CASE__      ,	return_length=SCREAMING_SNAKE_CASE__      ,	verbose=SCREAMING_SNAKE_CASE__      ,	return_tensors=SCREAMING_SNAKE_CASE__      ,	**SCREAMING_SNAKE_CASE__      ,	)
         else:
                A						:     str         =None

         if text_encoding is not None:
                encoding_image_processor.update(SCREAMING_SNAKE_CASE__     )

         return encoding_image_processor







  def 		SCREAMING_SNAKE_CASE_		(				self    :					int      ,	*SCREAMING_SNAKE_CASE__    :					List[str]      ,	**SCREAMING_SNAKE_CASE__    :					Union[str, Any]     )    ->				Tuple:
         return self.tokenizer.batch_decode(*SCREAMING_SNAKE_CASE__      ,	**SCREAMING_SNAKE_CASE__     )







  def 		SCREAMING_SNAKE_CASE_		(				self    :					str      ,	*SCREAMING_SNAKE_CASE__    :					Dict      ,	**SCREAMING_SNAKE_CASE__    :					Any     )    ->				Optional[Any]:
         return self.tokenizer.decode(*SCREAMING_SNAKE_CASE__      ,	**SCREAMING_SNAKE_CASE__     )







  @property
  def 		SCREAMING_SNAKE_CASE_		(				self    :					List[str]     )    ->				Any:
         A						:     Dict         =self.tokenizer.model_input_names
         A						:     Optional[int]         =self.image_processor.model_input_names
         return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names     )     )







_lowercase							:      Dict      							='''0.21.0'''

from .accelerator import Accelerator
from .big_modeling import (
    cpu_offload,
    cpu_offload_with_hook,
    disk_offload,
    dispatch_model,
    init_empty_weights,
    init_on_device,
    load_checkpoint_and_dispatch,
)
from .data_loader import skip_first_batches
from .launchers import debug_launcher, notebook_launcher
from .state import PartialState
from .utils import (
    DeepSpeedPlugin,
    DistributedDataParallelKwargs,
    DistributedType,
    FullyShardedDataParallelPlugin,
    GradScalerKwargs,
    InitProcessGroupKwargs,
    find_executable_batch_size,
    infer_auto_device_map,
    is_rich_available,
    load_checkpoint_in_model,
    synchronize_rng_states,
)


if is_rich_available():
    from .utils import rich






