


import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin







class 	_snake_case						(   _snake_case							):
 SCREAMING_SNAKE_CASE__   = ['image_processor', 'tokenizer']
 SCREAMING_SNAKE_CASE__   = 'AutoImageProcessor'
 SCREAMING_SNAKE_CASE__   = 'AutoTokenizer'




 def __init__(	self      ,						_lowerCamelCase=None      ,						_lowerCamelCase=None      ,						**_lowerCamelCase					):
       a		:List[str]											= None
       if "feature_extractor" in kwargs:
             warnings.warn(
                 '''The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'''
                 ''' instead.'''      ,						_lowerCamelCase      ,						)
             a		:int											= kwargs.pop('''feature_extractor'''					)

       a		:Any											= 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__(_lowerCamelCase      ,						_lowerCamelCase					)
       a		:Any											= self.image_processor
       a		:Tuple											= False




 def __call__(	self      ,						*_lowerCamelCase      ,						**_lowerCamelCase					):
       # For backward compatibility
       if self._in_target_context_manager:
             return self.current_processor(*_lowerCamelCase      ,						**_lowerCamelCase					)

       a		:Tuple											= kwargs.pop('''images'''      ,						_lowerCamelCase					)
       a		:Union[str, Any]											= kwargs.pop('''text'''      ,						_lowerCamelCase					)
       if len(_lowerCamelCase					) > 0:
             a		:Any											= args[0]
             a		:Any											= args[1:]

       if images is None and text is None:
             raise ValueError('''You need to specify either an `images` or `text` input to process.'''					)

       if images is not None:
             a		:List[Any]											= self.image_processor(_lowerCamelCase      ,						*_lowerCamelCase      ,						**_lowerCamelCase					)
       if text is not None:
             a		:str											= self.tokenizer(_lowerCamelCase      ,						**_lowerCamelCase					)

       if text is None:
             return inputs
       elif images is None:
             return encodings
       else:
             a		:str											= encodings['''input_ids''']
             return inputs




 def  SCREAMING_SNAKE_CASE__       (	self      ,						*_lowerCamelCase      ,						**_lowerCamelCase					):
       return self.tokenizer.batch_decode(*_lowerCamelCase      ,						**_lowerCamelCase					)




 def  SCREAMING_SNAKE_CASE__       (	self      ,						*_lowerCamelCase      ,						**_lowerCamelCase					):
       return self.tokenizer.decode(*_lowerCamelCase      ,						**_lowerCamelCase					)




 @contextmanager
 def  SCREAMING_SNAKE_CASE__       (	self					):
       warnings.warn(
           '''`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your '''
           '''labels by using the argument `text` of the regular `__call__` method (either in the same call as '''
           '''your images inputs, or in a separate call.'''					)
       a		:Optional[Any]											= True
       a		:List[str]											= self.tokenizer
       yield
       a		:Optional[int]											= self.image_processor
       a		:Tuple											= False




 @property
 def  SCREAMING_SNAKE_CASE__       (	self					):
       warnings.warn(
           '''`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'''      ,						_lowerCamelCase      ,						)
       return self.image_processor_class




 @property
 def  SCREAMING_SNAKE_CASE__       (	self					):
       warnings.warn(
           '''`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.'''      ,						_lowerCamelCase      ,						)
       return self.image_processor









from typing import Optional, Union

from ...file_utils import TensorType
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, TruncationStrategy







class 	_snake_case						(   _snake_case							):
 SCREAMING_SNAKE_CASE__   = 'MarkupLMFeatureExtractor'
 SCREAMING_SNAKE_CASE__   = ('MarkupLMTokenizer', 'MarkupLMTokenizerFast')
 SCREAMING_SNAKE_CASE__   = True




 def __call__(	self      ,						_lowerCamelCase=None      ,						_lowerCamelCase=None      ,						_lowerCamelCase=None      ,						_lowerCamelCase=None      ,						_lowerCamelCase=None      ,						_lowerCamelCase = True      ,						_lowerCamelCase = False      ,						_lowerCamelCase = None      ,						_lowerCamelCase = None      ,						_lowerCamelCase = 0      ,						_lowerCamelCase = None      ,						_lowerCamelCase = None      ,						_lowerCamelCase = None      ,						_lowerCamelCase = False      ,						_lowerCamelCase = False      ,						_lowerCamelCase = False      ,						_lowerCamelCase = False      ,						_lowerCamelCase = True      ,						_lowerCamelCase = None      ,						**_lowerCamelCase      ,						):
       # first, create nodes and xpaths
       if self.parse_html:
             if html_strings is None:
                   raise ValueError('''Make sure to pass HTML strings in case `parse_html` is set to `True`'''					)

             if nodes is not None or xpaths is not None or node_labels is not None:
                   raise ValueError(
                       '''Please don\'t pass nodes, xpaths nor node labels in case `parse_html` is set to `True`'''					)

             a		:int											= self.feature_extractor(_lowerCamelCase					)
             a		:Tuple											= features['''nodes''']
             a		:Dict											= features['''xpaths''']
       else:
             if html_strings is not None:
                   raise ValueError('''You have passed HTML strings but `parse_html` is set to `False`.'''					)
             if nodes is None or xpaths is None:
                   raise ValueError('''Make sure to pass nodes and xpaths in case `parse_html` is set to `False`'''					)

        # # second, apply the tokenizer
       if questions is not None and self.parse_html:
             if isinstance(_lowerCamelCase      ,						_lowerCamelCase					):
                   a		:Tuple											= [questions]  # add batch dimension (as the feature extractor always adds a batch dimension)

       a		:Optional[int]											= self.tokenizer(
           text=questions if questions is not None else nodes      ,						text_pair=nodes if questions is not None else None      ,						xpaths=_lowerCamelCase      ,						node_labels=_lowerCamelCase      ,						add_special_tokens=_lowerCamelCase      ,						padding=_lowerCamelCase      ,						truncation=_lowerCamelCase      ,						max_length=_lowerCamelCase      ,						stride=_lowerCamelCase      ,						pad_to_multiple_of=_lowerCamelCase      ,						return_token_type_ids=_lowerCamelCase      ,						return_attention_mask=_lowerCamelCase      ,						return_overflowing_tokens=_lowerCamelCase      ,						return_special_tokens_mask=_lowerCamelCase      ,						return_offsets_mapping=_lowerCamelCase      ,						return_length=_lowerCamelCase      ,						verbose=_lowerCamelCase      ,						return_tensors=_lowerCamelCase      ,						**_lowerCamelCase      ,						)

       return encoded_inputs




 def  SCREAMING_SNAKE_CASE__       (	self      ,						*_lowerCamelCase      ,						**_lowerCamelCase					):
       return self.tokenizer.batch_decode(*_lowerCamelCase      ,						**_lowerCamelCase					)




 def  SCREAMING_SNAKE_CASE__       (	self      ,						*_lowerCamelCase      ,						**_lowerCamelCase					):
       return self.tokenizer.decode(*_lowerCamelCase      ,						**_lowerCamelCase					)




 @property
 def  SCREAMING_SNAKE_CASE__       (	self					):
       a		:Any											= self.tokenizer.model_input_names
       return tokenizer_input_names





