




'''simple docstring'''





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


lowercase__								=						{
    '''configuration_layoutlm''': ['''LAYOUTLM_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''LayoutLMConfig''', '''LayoutLMOnnxConfig'''],
    '''tokenization_layoutlm''': ['''LayoutLMTokenizer'''],
}

try:
       if not is_tokenizers_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowercase__								=						['''LayoutLMTokenizerFast''']

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowercase__								=						[
           '''LAYOUTLM_PRETRAINED_MODEL_ARCHIVE_LIST''',
           '''LayoutLMForMaskedLM''',
           '''LayoutLMForSequenceClassification''',
           '''LayoutLMForTokenClassification''',
           '''LayoutLMForQuestionAnswering''',
           '''LayoutLMModel''',
           '''LayoutLMPreTrainedModel''',
       ]

try:
       if not is_tf_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowercase__								=						[
           '''TF_LAYOUTLM_PRETRAINED_MODEL_ARCHIVE_LIST''',
           '''TFLayoutLMForMaskedLM''',
           '''TFLayoutLMForSequenceClassification''',
           '''TFLayoutLMForTokenClassification''',
           '''TFLayoutLMForQuestionAnswering''',
           '''TFLayoutLMMainLayer''',
           '''TFLayoutLMModel''',
           '''TFLayoutLMPreTrainedModel''',
       ]


if TYPE_CHECKING:
       from .configuration_layoutlm import LAYOUTLM_PRETRAINED_CONFIG_ARCHIVE_MAP, LayoutLMConfig, LayoutLMOnnxConfig
       from .tokenization_layoutlm import LayoutLMTokenizer

       try:
              if not is_tokenizers_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .tokenization_layoutlm_fast import LayoutLMTokenizerFast

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_layoutlm import (
                  LAYOUTLM_PRETRAINED_MODEL_ARCHIVE_LIST,
                  LayoutLMForMaskedLM,
                  LayoutLMForQuestionAnswering,
                  LayoutLMForSequenceClassification,
                  LayoutLMForTokenClassification,
                  LayoutLMModel,
                  LayoutLMPreTrainedModel,
              )
       try:
              if not is_tf_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_tf_layoutlm import (
                  TF_LAYOUTLM_PRETRAINED_MODEL_ARCHIVE_LIST,
                  TFLayoutLMForMaskedLM,
                  TFLayoutLMForQuestionAnswering,
                  TFLayoutLMForSequenceClassification,
                  TFLayoutLMForTokenClassification,
                  TFLayoutLMMainLayer,
                  TFLayoutLMModel,
                  TFLayoutLMPreTrainedModel,
              )

else:
       import sys

       lowercase__								=						_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)







'''simple docstring'''





from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding






class     lowercase  ( UpperCAmelCase_):
      __lowercase					=	['''image_processor''', '''tokenizer''']
      __lowercase					=	'''EfficientNetImageProcessor'''
      __lowercase					=	('''BertTokenizer''', '''BertTokenizerFast''')






      def __init__(self			,	a__			,	a__       )							-> Tuple:
         super().__init__(a__			,	a__       )






      def __call__(self			,	a__=None			,	a__=None			,	a__="max_length"			,	a__=6_4			,	a__=None			,	**a__       )							-> Any:
         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:
            SCREAMING_SNAKE_CASE__      :					List[Any]							    =			self.tokenizer(
                a__			,	padding=a__			,	max_length=a__			,	return_tensors=a__			,	**a__       )

         if images is not None:
            SCREAMING_SNAKE_CASE__      :					Any							    =			self.image_processor(a__			,	return_tensors=a__			,	**a__       )

         if text is not None and images is not None:
            SCREAMING_SNAKE_CASE__      :					str							    =			image_features.pixel_values
            return encoding
         elif text is not None:
            return encoding
         else:
            return BatchEncoding(data=dict(**a__       )			,	tensor_type=a__       )






      def  A__(self			,	*a__			,	**a__       )							-> str:
         return self.tokenizer.batch_decode(*a__			,	**a__       )






      def  A__(self			,	*a__			,	**a__       )							-> str:
         return self.tokenizer.decode(*a__			,	**a__       )






      @property
      def  A__(self       )							-> Optional[int]:
         SCREAMING_SNAKE_CASE__      :					Optional[Any]							    =			self.tokenizer.model_input_names
         SCREAMING_SNAKE_CASE__      :					Tuple							    =			self.image_processor.model_input_names
         return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names       )       )

