





from typing import List, Optional, Union

from ...image_utils import ImageInput
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType

class      lowerCAmelCase							(      __UpperCamelCase    ):
 UpperCAmelCase__									=	["""image_processor""", """tokenizer"""]
 UpperCAmelCase__									=	"""BlipImageProcessor"""
 UpperCAmelCase__									=	("""BertTokenizer""", """BertTokenizerFast""")
 def __init__(   self						:   Tuple    ,  UpperCAmelCase						:   Dict    ,  UpperCAmelCase						:   int			)    ->			List[Any]:
     lowerCamelCase__					:   Optional[int]      				=	False
     super().__init__(UpperCAmelCase    ,  UpperCAmelCase			)
     lowerCamelCase__					:   int      				=	self.image_processor
 def __call__(   self						:   Dict    ,  UpperCAmelCase						:   ImageInput = None    ,  UpperCAmelCase						:   Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None    ,  UpperCAmelCase						:   bool = True    ,  UpperCAmelCase						:   Union[bool, str, PaddingStrategy] = False    ,  UpperCAmelCase						:   Union[bool, str, TruncationStrategy] = None    ,  UpperCAmelCase						:   Optional[int] = None    ,  UpperCAmelCase						:   int = 0    ,  UpperCAmelCase						:   Optional[int] = None    ,  UpperCAmelCase						:   Optional[bool] = None    ,  UpperCAmelCase						:   bool = False    ,  UpperCAmelCase						:   bool = False    ,  UpperCAmelCase						:   bool = False    ,  UpperCAmelCase						:   bool = False    ,  UpperCAmelCase						:   bool = False    ,  UpperCAmelCase						:   bool = True    ,  UpperCAmelCase						:   Optional[Union[str, TensorType]] = None    ,  **UpperCAmelCase						:   Union[str, Any]    ,  )    ->			BatchEncoding:
     if images is None and text is None:
         raise ValueError('You have to specify either images or text.'			)

     # Get only text
     if images is None:
         lowerCamelCase__					:   Any      				=	self.tokenizer
         lowerCamelCase__					:   Any      				=	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    ,  )
         return text_encoding

     # add pixel_values
     lowerCamelCase__					:   Union[str, Any]      				=	self.image_processor(UpperCAmelCase    ,  return_tensors=UpperCAmelCase			)

     if text is not None:
         lowerCamelCase__					:   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    ,  )
     else:
         lowerCamelCase__					:   List[Any]      				=	None

     if text_encoding is not None:
         encoding_image_processor.update(UpperCAmelCase			)

     return encoding_image_processor
 def   A_			(   self						:   int    ,  *UpperCAmelCase						:   Dict    ,  **UpperCAmelCase						:   str			)    ->			Optional[int]:
     return self.tokenizer.batch_decode(*UpperCAmelCase    ,  **UpperCAmelCase			)
 def   A_			(   self						:   Dict    ,  *UpperCAmelCase						:   int    ,  **UpperCAmelCase						:   List[str]			)    ->			Tuple:
     return self.tokenizer.decode(*UpperCAmelCase    ,  **UpperCAmelCase			)







 @property
 def   A_			(   self						:   Dict			)    ->			Optional[Any]:
     lowerCamelCase__					:   List[str]      				=	self.tokenizer.model_input_names
     lowerCamelCase__					:   Optional[Any]      				=	self.image_processor.model_input_names
     return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names			)			)












from ...configuration_utils import PretrainedConfig
from ...utils import logging


_UpperCAmelCase       : Dict			     =       logging.get_logger(__name__)

_UpperCAmelCase       : Union[str, Any]			     =       {
    """naver-clova-ix/donut-base""": """https://huggingface.co/naver-clova-ix/donut-base/resolve/main/config.json""",
    # See all Donut models at https://huggingface.co/models?filter=donut-swin
}

class      lowerCAmelCase							(      __UpperCamelCase    ):
 UpperCAmelCase__									=	"""donut-swin"""

 UpperCAmelCase__									=	{
     """num_attention_heads""": """num_heads""",
     """num_hidden_layers""": """num_layers""",
 }
 def __init__(   self						:   Tuple    ,  UpperCAmelCase						:   List[str]=224    ,  UpperCAmelCase						:   Optional[Any]=4    ,  UpperCAmelCase						:   Union[str, Any]=3    ,  UpperCAmelCase						:   Union[str, Any]=96    ,  UpperCAmelCase						:   int=[2, 2, 6, 2]    ,  UpperCAmelCase						:   Dict=[3, 6, 12, 24]    ,  UpperCAmelCase						:   Any=7    ,  UpperCAmelCase						:   Optional[int]=4.0    ,  UpperCAmelCase						:   List[Any]=True    ,  UpperCAmelCase						:   Any=0.0    ,  UpperCAmelCase						:   Optional[Any]=0.0    ,  UpperCAmelCase						:   int=0.1    ,  UpperCAmelCase						:   List[str]="gelu"    ,  UpperCAmelCase						:   List[str]=False    ,  UpperCAmelCase						:   str=0.0_2    ,  UpperCAmelCase						:   str=1e-5    ,  **UpperCAmelCase						:   Tuple    ,  )    ->			int:
     super().__init__(**UpperCAmelCase			)

     lowerCamelCase__					:   Optional[Any]      				=	image_size
     lowerCamelCase__					:   Optional[int]      				=	patch_size
     lowerCamelCase__					:   int      				=	num_channels
     lowerCamelCase__					:   int      				=	embed_dim
     lowerCamelCase__					:   Optional[Any]      				=	depths
     lowerCamelCase__					:   Optional[int]      				=	len(UpperCAmelCase			)
     lowerCamelCase__					:   Optional[int]      				=	num_heads
     lowerCamelCase__					:   Tuple      				=	window_size
     lowerCamelCase__					:   Dict      				=	mlp_ratio
     lowerCamelCase__					:   str      				=	qkv_bias
     lowerCamelCase__					:   Tuple      				=	hidden_dropout_prob
     lowerCamelCase__					:   str      				=	attention_probs_dropout_prob
     lowerCamelCase__					:   str      				=	drop_path_rate
     lowerCamelCase__					:   int      				=	hidden_act
     lowerCamelCase__					:   str      				=	use_absolute_embeddings
     lowerCamelCase__					:   List[Any]      				=	layer_norm_eps
     lowerCamelCase__					:   Optional[Any]      				=	initializer_range
     # we set the hidden_size attribute in order to make Swin work with VisionEncoderDecoderModel
     # this indicates the channel dimension after the last stage of the model
     lowerCamelCase__					:   Optional[int]      				=	int(embed_dim * 2 ** (len(UpperCAmelCase			) - 1)			)





