




import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding




class     snake_case__							(_UpperCamelCase   ):
				"""simple docstring"""



				SCREAMING_SNAKE_CASE_       :							Union[str, Any]							 =					["""image_processor""", """tokenizer"""]
				SCREAMING_SNAKE_CASE_       :							Optional[Any]							 =					"""CLIPImageProcessor"""
				SCREAMING_SNAKE_CASE_       :							List[Any]							 =					("""CLIPTokenizer""", """CLIPTokenizerFast""")





				def __init__(      self				:     Optional[int]					,      __lowerCamelCase				:     int=None					,      __lowerCamelCase				:     Optional[Any]=None					,      **__lowerCamelCase				:     Optional[int]							)					->     List[Any]:
							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."					,      lowerCamelCase_					,      )
										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__(lowerCamelCase_					,      lowerCamelCase_							)





				def __call__(      self				:     Optional[Any]					,      __lowerCamelCase				:     Optional[Any]=None					,      __lowerCamelCase				:     int=None					,      __lowerCamelCase				:     List[str]=None					,      **__lowerCamelCase				:     str							)					->     Union[str, Any]:

							if text is None and images is None:
										raise ValueError("You have to specify either text or images. Both cannot be none."							)

							if text is not None:
										a    =			self.tokenizer(lowerCamelCase_					,      return_tensors=lowerCamelCase_					,      **lowerCamelCase_							)

							if images is not None:
										a    =			self.image_processor(lowerCamelCase_					,      return_tensors=lowerCamelCase_					,      **lowerCamelCase_							)

							if text is not None and images is not None:
										a    =			image_features.pixel_values
										return encoding
							elif text is not None:
										return encoding
							else:
										return BatchEncoding(data=dict(**lowerCamelCase_							)					,      tensor_type=lowerCamelCase_							)





				def 							__UpperCAmelCase							(      self				:     Optional[int]					,      *__lowerCamelCase				:     str					,      **__lowerCamelCase				:     Any							)					->     Optional[int]:
							return self.tokenizer.batch_decode(*lowerCamelCase_					,      **lowerCamelCase_							)





				def 							__UpperCAmelCase							(      self				:     int					,      *__lowerCamelCase				:     Optional[int]					,      **__lowerCamelCase				:     Any							)					->     Union[str, Any]:
							return self.tokenizer.decode(*lowerCamelCase_					,      **lowerCamelCase_							)





				@property
				def 							__UpperCAmelCase							(      self				:     Optional[int]							)					->     Dict:
							a    =			self.tokenizer.model_input_names
							a    =			self.image_processor.model_input_names
							return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names							)							)





				@property
				def 							__UpperCAmelCase							(      self				:     List[str]							)					->     List[Any]:
							warnings.warn(
							    "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."					,      lowerCamelCase_					,      )
							return self.image_processor_class





				@property
				def 							__UpperCAmelCase							(      self				:     Tuple							)					->     List[str]:
							warnings.warn(
							    "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."					,      lowerCamelCase_					,      )
							return self.image_processor











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


_lowercase: str      			=		logging.get_logger(__name__)

_lowercase: List[str]      			=		{
    "microsoft/trocr-base-handwritten": (
        "https://huggingface.co/microsoft/trocr-base-handwritten/resolve/main/config.json"
    ),
    # See all TrOCR models at https://huggingface.co/models?filter=trocr
}



class 	_lowercase							(   lowerCAmelCase	):





	"""simple docstring"""
	__A							=							"trocr"
	__A							=							["past_key_values"]
	__A							=							{
	    "num_attention_heads": "decoder_attention_heads",
	    "hidden_size": "d_model",
	    "num_hidden_layers": "decoder_layers",
	}




	def __init__(self		,       lowerCamelCase_=50265		,       lowerCamelCase_=1024		,       lowerCamelCase_=12		,       lowerCamelCase_=16		,       lowerCamelCase_=4096		,       lowerCamelCase_="gelu"		,       lowerCamelCase_=512		,       lowerCamelCase_=0.1		,       lowerCamelCase_=0.0		,       lowerCamelCase_=0.0		,       lowerCamelCase_=2		,       lowerCamelCase_=0.02		,       lowerCamelCase_=0.0		,       lowerCamelCase_=True		,       lowerCamelCase_=False		,       lowerCamelCase_=True		,       lowerCamelCase_=True		,       lowerCamelCase_=1		,       lowerCamelCase_=0		,       lowerCamelCase_=2		,       **lowerCamelCase_		,       ):
						"""simple docstring"""

						a					     =   vocab_size
						a					     =   d_model
						a					     =   decoder_layers
						a					     =   decoder_attention_heads
						a					     =   decoder_ffn_dim
						a					     =   activation_function
						a					     =   max_position_embeddings
						a					     =   dropout
						a					     =   attention_dropout
						a					     =   activation_dropout
						a					     =   init_std
						a					     =   decoder_layerdrop
						a					     =   use_cache
						a					     =   scale_embedding
						a					     =   use_learned_position_embeddings
						a					     =   layernorm_embedding

						super().__init__(
						    pad_token_id=lowerCamelCase_		,       bos_token_id=lowerCamelCase_		,       eos_token_id=lowerCamelCase_		,       decoder_start_token_id=lowerCamelCase_		,       **lowerCamelCase_		,       )
