import re
import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin




class 					_UpperCAmelCase			(     lowerCAmelCase  ):



 '''simple docstring'''




 __A			       =					['''image_processor''', '''tokenizer''']
 __A			       =					'''AutoImageProcessor'''
 __A			       =					'''AutoTokenizer'''







 def __init__(		self				:   List[Any]							, lowercase_				:   str=None							, lowercase_				:   str=None							, **lowercase_				:   Tuple)						->	Tuple:


   """simple docstring"""







   _UpperCamelCase           =    None
   if "feature_extractor" in kwargs:
     warnings.warn(
         "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"
         " instead."							, lowercase_							, )
     _UpperCamelCase           =    kwargs.pop("feature_extractor")

   _UpperCamelCase           =    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__(lowercase_							, lowercase_)
   _UpperCamelCase           =    self.image_processor
   _UpperCamelCase           =    False







 def __call__(		self				:   Tuple							, *lowercase_				:   Optional[int]							, **lowercase_				:   List[Any])						->	Dict:


   """simple docstring"""







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

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

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







 def 		__UpperCAmelCase				(		self				:   Any							, *lowercase_				:   Union[str, Any]							, **lowercase_				:   List[Any])						->	Any:


   """simple docstring"""







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







 def 		__UpperCAmelCase				(		self				:   List[str]							, *lowercase_				:   Tuple							, **lowercase_				:   str)						->	int:


   """simple docstring"""







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







 @contextmanager
 def 		__UpperCAmelCase				(		self				:   Optional[int])						->	Dict:


   """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.")
   _UpperCamelCase           =    True
   _UpperCamelCase           =    self.tokenizer
   yield
   _UpperCamelCase           =    self.image_processor
   _UpperCamelCase           =    False







 def 		__UpperCAmelCase				(		self				:   List[Any]							, lowercase_				:   Dict							, lowercase_				:   int=False							, lowercase_				:   str=None)						->	Optional[int]:


   """simple docstring"""







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

   _UpperCamelCase           =    {}

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

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

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







 @property
 def 		__UpperCAmelCase				(		self				:   Dict)						->	Tuple:


   """simple docstring"""







   warnings.warn(
       "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."							, lowercase_							, )
   return self.image_processor_class







 @property
 def 		__UpperCAmelCase				(		self				:   Optional[int])						->	Optional[Any]:


   """simple docstring"""







   warnings.warn(
       "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."							, lowercase_							, )
   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 KandinskyPipeline, KandinskyPriorPipeline
else:
   from .pipeline_kandinsky import KandinskyPipeline
   from .pipeline_kandinsky_imgaimg import KandinskyImgaImgPipeline
   from .pipeline_kandinsky_inpaint import KandinskyInpaintPipeline
   from .pipeline_kandinsky_prior import KandinskyPriorPipeline, KandinskyPriorPipelineOutput
   from .text_encoder import MultilingualCLIP




