





import re
import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin




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



 def __init__(				self,__lowerCamelCase=None,__lowerCamelCase=None,**__lowerCamelCase					):
        A__		   =		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__		   =		kwargs.pop('''feature_extractor'''					)

        A__		   =		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__		   =		self.image_processor
        A__		   =		False



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

        A__		   =		kwargs.pop('''images''',__lowerCamelCase					)
        A__		   =		kwargs.pop('''text''',__lowerCamelCase					)
        if len(__lowerCamelCase					) > 0:
               A__		   =		args[0]
               A__		   =		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__		   =		self.image_processor(__lowerCamelCase,*__lowerCamelCase,**__lowerCamelCase					)
        if text is not None:
               A__		   =		self.tokenizer(__lowerCamelCase,**__lowerCamelCase					)

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



 def 							UpperCamelCase     (				self,*__lowerCamelCase,**__lowerCamelCase					):
        return self.tokenizer.batch_decode(*__lowerCamelCase,**__lowerCamelCase					)



 def 							UpperCamelCase     (				self,*__lowerCamelCase,**__lowerCamelCase					):
        return self.tokenizer.decode(*__lowerCamelCase,**__lowerCamelCase					)



 @contextmanager
 def 							UpperCamelCase     (				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__		   =		True
        A__		   =		self.tokenizer
        yield
        A__		   =		self.image_processor
        A__		   =		False



 def 							UpperCamelCase     (				self,__lowerCamelCase,__lowerCamelCase=False,__lowerCamelCase=None					):
        if added_vocab is None:
               A__		   =		self.tokenizer.get_added_vocab()

        A__		   =		{}

        while tokens:
               A__		   =		re.search(r'''<s_(.*?)>''',__lowerCamelCase,re.IGNORECASE					)
               if start_token is None:
                      break
               A__		   =		start_token.group(1					)
               A__		   =		re.search(rf"</s_{key}>",__lowerCamelCase,re.IGNORECASE					)
               A__		   =		start_token.group()
               if end_token is None:
                      A__		   =		tokens.replace(__lowerCamelCase,''''''					)
               else:
                      A__		   =		end_token.group()
                      A__		   =		re.escape(__lowerCamelCase					)
                      A__		   =		re.escape(__lowerCamelCase					)
                      A__		   =		re.search(f"{start_token_escaped}(.*?){end_token_escaped}",__lowerCamelCase,re.IGNORECASE					)
                      if content is not None:
                             A__		   =		content.group(1					).strip()
                             if r"<s_" in content and r"</s_" in content:  # non-leaf node
                                    A__		   =		self.tokenajson(__lowerCamelCase,is_inner_value=__lowerCamelCase,added_vocab=__lowerCamelCase					)
                                    if value:
                                           if len(__lowerCamelCase					) == 1:
                                                  A__		   =		value[0]
                                           A__		   =		value
                             else:  # leaf nodes
                                    A__		   =		[]
                                    for leaf in content.split(r'''<sep/>'''					):
                                           A__		   =		leaf.strip()
                                           if leaf in added_vocab and leaf[0] == "<" and leaf[-2:] == "/>":
                                                  A__		   =		leaf[1:-2]  # for categorical special tokens
                                           output[key].append(__lowerCamelCase					)
                                    if len(output[key]					) == 1:
                                           A__		   =		output[key][0]

                      A__		   =		tokens[tokens.find(__lowerCamelCase					) + len(__lowerCamelCase					) :].strip()
                      if tokens[:6] == r"<sep/>":  # non-leaf nodes
                             return [output] + self.tokenajson(tokens[6:],is_inner_value=__lowerCamelCase,added_vocab=__lowerCamelCase					)

        if len(__lowerCamelCase					):
               return [output] if is_inner_value else output
        else:
               return [] if is_inner_value else {"text_sequence": tokens}



 @property
 def 							UpperCamelCase     (				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 							UpperCamelCase     (				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 TYPE_CHECKING

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


a__: str							   =						{
    'configuration_mega': ['MEGA_PRETRAINED_CONFIG_ARCHIVE_MAP', 'MegaConfig', 'MegaOnnxConfig'],
}

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       a__: Union[str, Any]							   =						[
           'MEGA_PRETRAINED_MODEL_ARCHIVE_LIST',
           'MegaForCausalLM',
           'MegaForMaskedLM',
           'MegaForMultipleChoice',
           'MegaForQuestionAnswering',
           'MegaForSequenceClassification',
           'MegaForTokenClassification',
           'MegaModel',
           'MegaPreTrainedModel',
       ]

if TYPE_CHECKING:
       from .configuration_mega import MEGA_PRETRAINED_CONFIG_ARCHIVE_MAP, MegaConfig, MegaOnnxConfig

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_mega import (
                  MEGA_PRETRAINED_MODEL_ARCHIVE_LIST,
                  MegaForCausalLM,
                  MegaForMaskedLM,
                  MegaForMultipleChoice,
                  MegaForQuestionAnswering,
                  MegaForSequenceClassification,
                  MegaForTokenClassification,
                  MegaModel,
                  MegaPreTrainedModel,
              )

else:
       import sys

       a__: Union[str, Any]							   =						_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)





