


'''simple docstring'''


import os
from typing import List, Optional, Union

from ...image_processing_utils import BatchFeature
from ...image_utils import ImageInput
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType
from ..auto import AutoTokenizer






class 	lowerCAmelCase__			(			lowercase__	):
			lowerCAmelCase :	List[Any]          =     ["image_processor", "tokenizer"]
			lowerCAmelCase :	Optional[int]          =     "BlipImageProcessor"
			lowerCAmelCase :	Optional[int]          =     "AutoTokenizer"




			def __init__(		self  :     Dict	,  lowerCamelCase__  :     List[str]	,  lowerCamelCase__  :     Optional[int]	,  lowerCamelCase__  :     List[Any] )   ->Optional[Any]:



					'''simple docstring'''







					super().__init__(UpperCAmelCase__	,  UpperCAmelCase__ )

					# add QFormer tokenizer
					_UpperCAmelCase		:       Optional[int]								=      qformer_tokenizer




			def __call__(		self  :     Union[str, Any]	,  lowerCamelCase__  :     ImageInput = None	,  lowerCamelCase__  :     Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None	,  lowerCamelCase__  :     bool = True	,  lowerCamelCase__  :     Union[bool, str, PaddingStrategy] = False	,  lowerCamelCase__  :     Union[bool, str, TruncationStrategy] = None	,  lowerCamelCase__  :     Optional[int] = None	,  lowerCamelCase__  :     int = 0	,  lowerCamelCase__  :     Optional[int] = None	,  lowerCamelCase__  :     Optional[bool] = None	,  lowerCamelCase__  :     bool = False	,  lowerCamelCase__  :     bool = False	,  lowerCamelCase__  :     bool = False	,  lowerCamelCase__  :     bool = False	,  lowerCamelCase__  :     bool = False	,  lowerCamelCase__  :     bool = True	,  lowerCamelCase__  :     Optional[Union[str, TensorType]] = None	,  **lowerCamelCase__  :     Union[str, Any]	,  )   ->List[Any]:



					'''simple docstring'''







					if images is None and text is None:
							raise ValueError("You have to specify at least images or text." )

					_UpperCAmelCase		:       List[str]								=      BatchFeature()

					if text is not None:
							_UpperCAmelCase		:       str								=      self.tokenizer(
							    text=UpperCAmelCase__	,  add_special_tokens=UpperCAmelCase__	,  padding=UpperCAmelCase__	,  truncation=UpperCAmelCase__	,  max_length=UpperCAmelCase__	,  stride=UpperCAmelCase__	,  pad_to_multiple_of=UpperCAmelCase__	,  return_attention_mask=UpperCAmelCase__	,  return_overflowing_tokens=UpperCAmelCase__	,  return_special_tokens_mask=UpperCAmelCase__	,  return_offsets_mapping=UpperCAmelCase__	,  return_token_type_ids=UpperCAmelCase__	,  return_length=UpperCAmelCase__	,  verbose=UpperCAmelCase__	,  return_tensors=UpperCAmelCase__	,  **UpperCAmelCase__	,  )
							encoding.update(UpperCAmelCase__ )
							_UpperCAmelCase		:       Optional[int]								=      self.qformer_tokenizer(
							    text=UpperCAmelCase__	,  add_special_tokens=UpperCAmelCase__	,  padding=UpperCAmelCase__	,  truncation=UpperCAmelCase__	,  max_length=UpperCAmelCase__	,  stride=UpperCAmelCase__	,  pad_to_multiple_of=UpperCAmelCase__	,  return_attention_mask=UpperCAmelCase__	,  return_overflowing_tokens=UpperCAmelCase__	,  return_special_tokens_mask=UpperCAmelCase__	,  return_offsets_mapping=UpperCAmelCase__	,  return_token_type_ids=UpperCAmelCase__	,  return_length=UpperCAmelCase__	,  verbose=UpperCAmelCase__	,  return_tensors=UpperCAmelCase__	,  **UpperCAmelCase__	,  )
							_UpperCAmelCase		:       Any								=      qformer_text_encoding.pop("input_ids" )
							_UpperCAmelCase		:       Optional[Any]								=      qformer_text_encoding.pop("attention_mask" )

					if images is not None:
							_UpperCAmelCase		:       Union[str, Any]								=      self.image_processor(UpperCAmelCase__	,  return_tensors=UpperCAmelCase__ )
							encoding.update(UpperCAmelCase__ )

					return encoding




			def 							lowerCAmelCase__    (		self  :     Dict	,  *lowerCamelCase__  :     Optional[int]	,  **lowerCamelCase__  :     Optional[Any] )   ->Dict:



					'''simple docstring'''







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




			def 							lowerCAmelCase__    (		self  :     str	,  *lowerCamelCase__  :     Dict	,  **lowerCamelCase__  :     Optional[Any] )   ->Optional[Any]:



					'''simple docstring'''







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




			@property
			# Copied from transformers.models.blip.processing_blip.BlipProcessor.model_input_names
			def 							lowerCAmelCase__    (		self  :     List[str] )   ->Optional[int]:



					'''simple docstring'''







					_UpperCAmelCase		:       Optional[Any]								=      self.tokenizer.model_input_names
					_UpperCAmelCase		:       Union[str, Any]								=      self.image_processor.model_input_names
					return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names ) )




			def 							lowerCAmelCase__    (		self  :     Dict	,  lowerCamelCase__  :     int	,  **lowerCamelCase__  :     str )   ->List[str]:



					'''simple docstring'''







					if os.path.isfile(UpperCAmelCase__ ):
							raise ValueError(F"""Provided path ({save_directory}) should be a directory, not a file""" )
					os.makedirs(UpperCAmelCase__	,  exist_ok=UpperCAmelCase__ )
					_UpperCAmelCase		:       Tuple								=      os.path.join(UpperCAmelCase__	,  "qformer_tokenizer" )
					self.qformer_tokenizer.save_pretrained(UpperCAmelCase__ )
					return super().save_pretrained(UpperCAmelCase__	,  **UpperCAmelCase__ )






			@classmethod
			def 							lowerCAmelCase__    (		cls  :     Optional[int]	,  lowerCamelCase__  :     Any	,  **lowerCamelCase__  :     List[str] )   ->List[str]:



					'''simple docstring'''







					_UpperCAmelCase		:       Tuple								=      AutoTokenizer.from_pretrained(UpperCAmelCase__	,  subfolder="qformer_tokenizer" )
					_UpperCAmelCase		:       int								=      cls._get_arguments_from_pretrained(UpperCAmelCase__	,  **UpperCAmelCase__ )
					args.append(UpperCAmelCase__ )
					return cls(*UpperCAmelCase__ )







'''simple docstring'''


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


try:
						if not (is_transformers_available() and is_torch_available()):
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						from ...utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
						from .multicontrolnet import MultiControlNetModel
						from .pipeline_controlnet import StableDiffusionControlNetPipeline
						from .pipeline_controlnet_imgaimg import StableDiffusionControlNetImgaImgPipeline
						from .pipeline_controlnet_inpaint import StableDiffusionControlNetInpaintPipeline


if is_transformers_available() and is_flax_available():
						from .pipeline_flax_controlnet import FlaxStableDiffusionControlNetPipeline



