






import re
import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin


class       __lowercase      (	lowercase_  ):







     '''simple docstring'''
     SCREAMING_SNAKE_CASE   						=				["image_processor", "tokenizer"]
     SCREAMING_SNAKE_CASE   						=				"AutoImageProcessor"
     SCREAMING_SNAKE_CASE   						=				"AutoTokenizer"




     def __init__(				self       :			Any ,	UpperCamelCase_       :			int=None ,	UpperCamelCase_       :			int=None ,	**UpperCamelCase_       :			Any				):


         """simple docstring"""



         __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.""" ,	UpperCamelCase_ ,	)
             __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__(UpperCamelCase_ ,	UpperCamelCase_				)
         __A         =	self.image_processor
         __A         =	False




     def __call__(				self       :			Any ,	*UpperCamelCase_       :			str ,	**UpperCamelCase_       :			Optional[int]				):


         """simple docstring"""



         if self._in_target_context_manager:
             return self.current_processor(*UpperCamelCase_ ,	**UpperCamelCase_				)

         __A         =	kwargs.pop("""images""" ,	UpperCamelCase_				)
         __A         =	kwargs.pop("""text""" ,	UpperCamelCase_				)
         if len(UpperCamelCase_				) > 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(UpperCamelCase_ ,	*UpperCamelCase_ ,	**UpperCamelCase_				)
         if text is not None:
             __A         =	self.tokenizer(UpperCamelCase_ ,	**UpperCamelCase_				)

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




     def 		lowerCAmelCase_     (				self       :			List[Any] ,	*UpperCamelCase_       :			int ,	**UpperCamelCase_       :			int				):


         """simple docstring"""



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




     def 		lowerCAmelCase_     (				self       :			List[str] ,	*UpperCamelCase_       :			Optional[int] ,	**UpperCamelCase_       :			List[Any]				):


         """simple docstring"""



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




     @contextmanager
     def 		lowerCAmelCase_     (				self       :			str				):


         """simple docstring"""



         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 		lowerCAmelCase_     (				self       :			List[str] ,	UpperCamelCase_       :			List[Any] ,	UpperCamelCase_       :			Any=False ,	UpperCamelCase_       :			Tuple=None				):


         """simple docstring"""



         if added_vocab is None:
             __A         =	self.tokenizer.get_added_vocab()

         __A         =	{}

         while tokens:
             __A         =	re.search(R"""<s_(.*?)>""" ,	UpperCamelCase_ ,	re.IGNORECASE				)
             if start_token is None:
                 break
             __A         =	start_token.group(1				)
             __A         =	re.search(RF"</s_{key}>" ,	UpperCamelCase_ ,	re.IGNORECASE				)
             __A         =	start_token.group()
             if end_token is None:
                 __A         =	tokens.replace(UpperCamelCase_ ,	""""""				)
             else:
                 __A         =	end_token.group()
                 __A         =	re.escape(UpperCamelCase_				)
                 __A         =	re.escape(UpperCamelCase_				)
                 __A         =	re.search(F"{start_token_escaped}(.*?){end_token_escaped}" ,	UpperCamelCase_ ,	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(UpperCamelCase_ ,	is_inner_value=UpperCamelCase_ ,	added_vocab=UpperCamelCase_				)
                         if value:
                             if len(UpperCamelCase_				) == 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(UpperCamelCase_				)
                         if len(output[key]				) == 1:
                             __A         =	output[key][0]

                 __A         =	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 		lowerCAmelCase_     (				self       :			List[Any]				):


         """simple docstring"""



         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 		lowerCAmelCase_     (				self       :			str				):


         """simple docstring"""



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












from ...utils import (
    OptionalDependencyNotAvailable,
    is_torch_available,
    is_transformers_available,
    is_transformers_version,
)


try:
  if not (is_transformers_available() and is_torch_available()):
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  from ...utils.dummy_torch_and_transformers_objects import (
      ImageTextPipelineOutput,
      UniDiffuserPipeline,
  )
else:
  from .modeling_text_decoder import UniDiffuserTextDecoder
  from .modeling_uvit import UniDiffuserModel, UTransformeraDModel
  from .pipeline_unidiffuser import ImageTextPipelineOutput, UniDiffuserPipeline




