





"""simple docstring"""





import logging
import os
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

from tqdm import auto as tqdm_lib


SCREAMING_SNAKE_CASE__					=   {
    "debug": logging.DEBUG,
    "info": logging.INFO,
    "warning": logging.WARNING,
    "error": logging.ERROR,
    "critical": logging.CRITICAL,
}

SCREAMING_SNAKE_CASE__					=   logging.WARNING


def 			UpperCAmelCase__							(  ):







      '''simple docstring'''




      lowerCAmelCase  						=       os.getenv("""DATASETS_VERBOSITY"""							,						SCREAMING_SNAKE_CASE			)
      if env_level_str:
            if env_level_str in log_levels:
                  return log_levels[env_level_str]
            else:
                  logging.getLogger().warning(
                      F'Unknown option DATASETS_VERBOSITY={env_level_str}, '
                      F'has to be one of: { ", ".join(log_levels.keys()			) }'			)
      return _default_log_level


def 			UpperCAmelCase__							(  ):







      '''simple docstring'''




      return __name__.split("""."""			)[0]


def 			UpperCAmelCase__							(  ):







      '''simple docstring'''




      return logging.getLogger(_get_library_name()			)


def 			UpperCAmelCase__							(  ):







      '''simple docstring'''




      lowerCAmelCase  						=       _get_library_root_logger()
      library_root_logger.setLevel(_get_default_logging_level()			)


def 			UpperCAmelCase__							(  ):







      '''simple docstring'''




      lowerCAmelCase  						=       _get_library_root_logger()
      library_root_logger.setLevel(logging.NOTSET			)


def 			UpperCAmelCase__							(  SCREAMING_SNAKE_CASE     :						Optional[str] = None			):







      '''simple docstring'''




      if name is None:
            lowerCAmelCase  						=       _get_library_name()
      return logging.getLogger(SCREAMING_SNAKE_CASE			)


def 			UpperCAmelCase__							(  ):







      '''simple docstring'''




      return _get_library_root_logger().getEffectiveLevel()


def 			UpperCAmelCase__							(  SCREAMING_SNAKE_CASE     :						int			):







      '''simple docstring'''




      _get_library_root_logger().setLevel(SCREAMING_SNAKE_CASE			)


def 			UpperCAmelCase__							(  ):







      '''simple docstring'''




      return set_verbosity(SCREAMING_SNAKE_CASE			)


def 			UpperCAmelCase__							(  ):







      '''simple docstring'''




      return set_verbosity(SCREAMING_SNAKE_CASE			)


def 			UpperCAmelCase__							(  ):







      '''simple docstring'''




      return set_verbosity(SCREAMING_SNAKE_CASE			)


def 			UpperCAmelCase__							(  ):







      '''simple docstring'''




      return set_verbosity(SCREAMING_SNAKE_CASE			)


def 			UpperCAmelCase__							(  ):







      '''simple docstring'''




      lowerCAmelCase  						=       False


def 			UpperCAmelCase__							(  ):







      '''simple docstring'''




      lowerCAmelCase  						=       True


# Configure the library root logger at the module level (singleton-like)
_configure_library_root_logger()

class 		lowercase					:





      def __init__(       self      ,						*lowercase      ,						**lowercase )		->     List[Any]:  # pylint: disable=unused-argument
            lowerCAmelCase  						=       args[0] if args else None





      def __iter__(       self )		->     Dict:
            return iter(self._iterator )





      def __getattr__(       self      ,						lowercase )		->     int:

            def empty_fn(*lowercase      ,						**lowercase ):  # pylint: disable=unused-argument
                  return

            return empty_fn





      def __enter__(       self )		->     Tuple:
            return self





      def __exit__(       self      ,						lowercase      ,						lowercase      ,						lowercase )		->     List[str]:
            return







SCREAMING_SNAKE_CASE__					=   True

class 		lowercase					:





      def __call__(       self      ,						*lowercase      ,						lowercase=False      ,						**lowercase )		->     Union[str, Any]:
            if _tqdm_active and not disable:
                  return tqdm_lib.tqdm(*lowercase      ,						**lowercase )
            else:
                  return EmptyTqdm(*lowercase      ,						**lowercase )





      def     _snake_case			(       self      ,						*lowercase      ,						**lowercase )		->     Tuple:
            lowerCAmelCase  						=       None
            if _tqdm_active:
                  return tqdm_lib.tqdm.set_lock(*lowercase      ,						**lowercase )





      def     _snake_case			(       self )		->     List[Any]:
            if _tqdm_active:
                  return tqdm_lib.tqdm.get_lock()







SCREAMING_SNAKE_CASE__					=   _tqdm_cls()


def 			UpperCAmelCase__							(  ):







      '''simple docstring'''




      global _tqdm_active
      return bool(_tqdm_active			)


def 			UpperCAmelCase__							(  ):







      '''simple docstring'''




      global _tqdm_active
      lowerCAmelCase  						=       True






def 			UpperCAmelCase__							(  ):







      '''simple docstring'''




      global _tqdm_active
      lowerCAmelCase  						=       False












import warnings
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 __snake_case			(			a		):
   UpperCAmelCase__  :    Dict          =  ['''image_processor''', '''tokenizer''']
   UpperCAmelCase__  :    Dict          =  '''FlavaImageProcessor'''
   UpperCAmelCase__  :    Dict          =  ('''BertTokenizer''', '''BertTokenizerFast''')







   def __init__(      self		:						Union[str, Any]					,						_snake_case		:						List[str]=None					,						_snake_case		:						str=None					,						**_snake_case		:						int):

        """simple docstring"""


        UpperCAmelCase_          =							None
        if "feature_extractor" in kwargs:
             warnings.warn(
                 '''The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'''
                 ''' instead.'''					,						_snake_case					,						)
             UpperCAmelCase_          =							kwargs.pop('''feature_extractor''')

        UpperCAmelCase_          =							image_processor if image_processor is not None else feature_extractor
        if image_processor is None:
             raise ValueError('''You need to specify an `image_processor`.''')
        if tokenizer is None:
             raise ValueError('''You need to specify a `tokenizer`.''')

        super().__init__(_snake_case					,						_snake_case)
        UpperCAmelCase_          =							self.image_processor







   def __call__(      self		:						List[Any]					,						_snake_case		:						Optional[ImageInput] = None					,						_snake_case		:						Optional[Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]]] = None					,						_snake_case		:						bool = True					,						_snake_case		:						Union[bool, str, PaddingStrategy] = False					,						_snake_case		:						Union[bool, str, TruncationStrategy] = False					,						_snake_case		:						Optional[int] = None					,						_snake_case		:						int = 0					,						_snake_case		:						Optional[int] = None					,						_snake_case		:						Optional[bool] = None					,						_snake_case		:						Optional[bool] = None					,						_snake_case		:						Optional[bool] = None					,						_snake_case		:						Optional[bool] = None					,						_snake_case		:						bool = False					,						_snake_case		:						bool = False					,						_snake_case		:						bool = False					,						_snake_case		:						bool = False					,						_snake_case		:						bool = True					,						_snake_case		:						Optional[Union[str, TensorType]] = None					,						**_snake_case		:						Any					,						):

        """simple docstring"""


        if text is None and images is None:
             raise ValueError('''You have to specify either text or images. Both cannot be none.''')

        if text is not None:
             UpperCAmelCase_          =							self.tokenizer(
                 text=_snake_case					,						add_special_tokens=_snake_case					,						padding=_snake_case					,						truncation=_snake_case					,						max_length=_snake_case					,						stride=_snake_case					,						pad_to_multiple_of=_snake_case					,						return_token_type_ids=_snake_case					,						return_attention_mask=_snake_case					,						return_overflowing_tokens=_snake_case					,						return_special_tokens_mask=_snake_case					,						return_offsets_mapping=_snake_case					,						return_length=_snake_case					,						verbose=_snake_case					,						return_tensors=_snake_case					,						**_snake_case					,						)
        if images is not None:
             UpperCAmelCase_          =							self.image_processor(
                 _snake_case					,						return_image_mask=_snake_case					,						return_codebook_pixels=_snake_case					,						return_tensors=_snake_case					,						**_snake_case					,						)

        if text is not None and images is not None:
             encoding.update(_snake_case)
             return encoding
        elif text is not None:
             return encoding
        else:
             return BatchEncoding(data=dict(**_snake_case)					,						tensor_type=_snake_case)







   def lowerCamelCase						(      self		:						Any					,						*_snake_case		:						Optional[Any]					,						**_snake_case		:						int):

        """simple docstring"""


        return self.tokenizer.batch_decode(*_snake_case					,						**_snake_case)







   def lowerCamelCase						(      self		:						Optional[int]					,						*_snake_case		:						int					,						**_snake_case		:						Dict):

        """simple docstring"""


        return self.tokenizer.decode(*_snake_case					,						**_snake_case)







   @property
   def lowerCamelCase						(      self		:						str):

        """simple docstring"""


        UpperCAmelCase_          =							self.tokenizer.model_input_names
        UpperCAmelCase_          =							self.image_processor.model_input_names
        return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names))







   @property
   def lowerCamelCase						(      self		:						str):

        """simple docstring"""


        warnings.warn(
            '''`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'''					,						_snake_case					,						)
        return self.image_processor_class







   @property
   def lowerCamelCase						(      self		:						Any):

        """simple docstring"""


        warnings.warn(
            '''`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.'''					,						_snake_case					,						)
        return self.image_processor






