






import re
import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin


class 			SCREAMING_SNAKE_CASE      (      lowerCAmelCase       ):
     '''simple docstring'''


     UpperCamelCase_				:		str								=						['''image_processor''', '''tokenizer''']
     UpperCamelCase_				:		Tuple								=						'''AutoImageProcessor'''
     UpperCamelCase_				:		Dict								=						'''AutoTokenizer'''


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

       SCREAMING_SNAKE_CASE							:   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__(UpperCAmelCase_       ,			UpperCAmelCase_   )
       SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     self.image_processor
       SCREAMING_SNAKE_CASE							:   Any						    =     False


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

       SCREAMING_SNAKE_CASE							:   Optional[int]						    =     kwargs.pop("images"       ,			UpperCAmelCase_   )
       SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     kwargs.pop("text"       ,			UpperCAmelCase_   )
       if len(UpperCAmelCase_   ) > 0:
         SCREAMING_SNAKE_CASE							:   Tuple						    =     args[0]
         SCREAMING_SNAKE_CASE							:   str						    =     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:
         SCREAMING_SNAKE_CASE							:   Dict						    =     self.image_processor(UpperCAmelCase_       ,			*UpperCAmelCase_       ,			**UpperCAmelCase_   )
       if text is not None:
         SCREAMING_SNAKE_CASE							:   str						    =     self.tokenizer(UpperCAmelCase_       ,			**UpperCAmelCase_   )

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


     def 					_A							(					self							:						Optional[Any]       ,			*UpperCAmelCase_							:						List[Any]       ,			**UpperCAmelCase_							:						str   ):
       return self.tokenizer.batch_decode(*UpperCAmelCase_       ,			**UpperCAmelCase_   )


     def 					_A							(					self							:						Dict       ,			*UpperCAmelCase_							:						Optional[Any]       ,			**UpperCAmelCase_							:						List[Any]   ):
       return self.tokenizer.decode(*UpperCAmelCase_       ,			**UpperCAmelCase_   )


     @contextmanager
     def 					_A							(					self							:						str   ):
       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."   )
       SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     True
       SCREAMING_SNAKE_CASE							:   List[str]						    =     self.tokenizer
       yield
       SCREAMING_SNAKE_CASE							:   int						    =     self.image_processor
       SCREAMING_SNAKE_CASE							:   Tuple						    =     False


     def 					_A							(					self							:						Union[str, Any]       ,			UpperCAmelCase_							:						int       ,			UpperCAmelCase_							:						Optional[Any]=False       ,			UpperCAmelCase_							:						Tuple=None   ):
       if added_vocab is None:
         SCREAMING_SNAKE_CASE							:   Any						    =     self.tokenizer.get_added_vocab()

       SCREAMING_SNAKE_CASE							:   str						    =     {}

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

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

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


     @property
     def 					_A							(					self							:						Optional[int]   ):
       warnings.warn(
           "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."       ,			UpperCAmelCase_       ,			)
       return self.image_processor_class






     @property
     def 					_A							(					self							:						Optional[int]   ):
       warnings.warn(
           "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."       ,			UpperCAmelCase_       ,			)
       return self.image_processor










from ..utils import DummyObject, requires_backends







class        __lowercase       (							metaclass=a_  ):



		"""simple docstring"""

		UpperCamelCase     :					Tuple			       =		["flax"]







		def __init__( self		,      *A		,      **A	)  -> str:







					'''simple docstring'''







					requires_backends(self		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> int:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> str:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







class        __lowercase       (							metaclass=a_  ):



		"""simple docstring"""

		UpperCamelCase     :					Optional[Any]			       =		["flax"]







		def __init__( self		,      *A		,      **A	)  -> Dict:







					'''simple docstring'''







					requires_backends(self		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> List[str]:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> Dict:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







class        __lowercase       (							metaclass=a_  ):



		"""simple docstring"""

		UpperCamelCase     :					str			       =		["flax"]







		def __init__( self		,      *A		,      **A	)  -> Dict:







					'''simple docstring'''







					requires_backends(self		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> Union[str, Any]:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> Optional[int]:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







class        __lowercase       (							metaclass=a_  ):



		"""simple docstring"""

		UpperCamelCase     :					str			       =		["flax"]







		def __init__( self		,      *A		,      **A	)  -> List[Any]:







					'''simple docstring'''







					requires_backends(self		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> Any:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> Union[str, Any]:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







class        __lowercase       (							metaclass=a_  ):



		"""simple docstring"""

		UpperCamelCase     :					Dict			       =		["flax"]







		def __init__( self		,      *A		,      **A	)  -> Optional[Any]:







					'''simple docstring'''







					requires_backends(self		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> Optional[Any]:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> Any:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







class        __lowercase       (							metaclass=a_  ):



		"""simple docstring"""

		UpperCamelCase     :					Optional[int]			       =		["flax"]







		def __init__( self		,      *A		,      **A	)  -> int:







					'''simple docstring'''







					requires_backends(self		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> int:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> str:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







class        __lowercase       (							metaclass=a_  ):



		"""simple docstring"""

		UpperCamelCase     :					Union[str, Any]			       =		["flax"]







		def __init__( self		,      *A		,      **A	)  -> List[Any]:







					'''simple docstring'''







					requires_backends(self		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> Tuple:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> Optional[int]:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







class        __lowercase       (							metaclass=a_  ):



		"""simple docstring"""

		UpperCamelCase     :					Optional[Any]			       =		["flax"]







		def __init__( self		,      *A		,      **A	)  -> Optional[Any]:







					'''simple docstring'''







					requires_backends(self		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> int:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> int:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







class        __lowercase       (							metaclass=a_  ):



		"""simple docstring"""

		UpperCamelCase     :					Tuple			       =		["flax"]







		def __init__( self		,      *A		,      **A	)  -> str:







					'''simple docstring'''







					requires_backends(self		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> List[Any]:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> str:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







class        __lowercase       (							metaclass=a_  ):



		"""simple docstring"""

		UpperCamelCase     :					Any			       =		["flax"]







		def __init__( self		,      *A		,      **A	)  -> List[str]:







					'''simple docstring'''







					requires_backends(self		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> int:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> str:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







class        __lowercase       (							metaclass=a_  ):



		"""simple docstring"""

		UpperCamelCase     :					str			       =		["flax"]







		def __init__( self		,      *A		,      **A	)  -> Dict:







					'''simple docstring'''







					requires_backends(self		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> Optional[int]:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> Dict:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







class        __lowercase       (							metaclass=a_  ):



		"""simple docstring"""

		UpperCamelCase     :					Optional[int]			       =		["flax"]







		def __init__( self		,      *A		,      **A	)  -> List[str]:







					'''simple docstring'''







					requires_backends(self		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> Any:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> Any:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







class        __lowercase       (							metaclass=a_  ):



		"""simple docstring"""

		UpperCamelCase     :					Tuple			       =		["flax"]







		def __init__( self		,      *A		,      **A	)  -> str:







					'''simple docstring'''







					requires_backends(self		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> Dict:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)







		@classmethod
		def 					__A   ( cls		,      *A		,      **A	)  -> Union[str, Any]:







					'''simple docstring'''







					requires_backends(cls		,      ["""flax"""]	)

