


from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import convert_to_rgb, normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
			import PIL


__snake_case     :   Optional[int]            =   logging.get_logger(__name__)




class    UpperCAmelCase					(       lowercase_    ):
			lowercase						= ['''pixel_values''']




			def __init__(						self							:		Optional[int]       ,       __magic_name__							:		int = True       ,       __magic_name__							:		Union[str, Any] = None       ,       __magic_name__							:		int = PILImageResampling.BICUBIC       ,       __magic_name__							:		Optional[int] = True       ,       __magic_name__							:		Tuple = 1 / 2_5_5       ,       __magic_name__							:		Optional[Any] = True       ,       __magic_name__							:		Tuple = None       ,       __magic_name__							:		Tuple = None       ,       __magic_name__							:		Tuple = True       ,       **__magic_name__							:		Union[str, Any]       ,       ):







						"""simple docstring"""







						super().__init__(**__magic_name__						)
						UpperCamelCase         =					size if size is not None else {"""height""": 3_8_4, """width""": 3_8_4}
						UpperCamelCase         =					get_size_dict(__magic_name__       ,       default_to_square=__magic_name__						)

						UpperCamelCase         =					do_resize
						UpperCamelCase         =					size
						UpperCamelCase         =					resample
						UpperCamelCase         =					do_rescale
						UpperCamelCase         =					rescale_factor
						UpperCamelCase         =					do_normalize
						UpperCamelCase         =					image_mean if image_mean is not None else OPENAI_CLIP_MEAN
						UpperCamelCase         =					image_std if image_std is not None else OPENAI_CLIP_STD
						UpperCamelCase         =					do_convert_rgb




			def   lowerCamelCase_					(						self							:		int       ,       __magic_name__							:		int       ,       __magic_name__							:		int       ,       __magic_name__							:		Tuple = PILImageResampling.BICUBIC       ,       __magic_name__							:		int = None       ,       **__magic_name__							:		int       ,       ):







						"""simple docstring"""







						UpperCamelCase         =					get_size_dict(__magic_name__       ,       default_to_square=__magic_name__						)
						if "height" not in size or "width" not in size:
									raise ValueError(F'The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}'						)
						UpperCamelCase         =					(size["""height"""], size["""width"""])
						return resize(__magic_name__       ,       size=__magic_name__       ,       resample=__magic_name__       ,       data_format=__magic_name__       ,       **__magic_name__						)




			def   lowerCamelCase_					(						self							:		List[str]       ,       __magic_name__							:		List[str]       ,       __magic_name__							:		int       ,       __magic_name__							:		Dict = None       ,       **__magic_name__							:		str       ,       ):







						"""simple docstring"""







						return rescale(__magic_name__       ,       scale=__magic_name__       ,       data_format=__magic_name__       ,       **__magic_name__						)




			def   lowerCamelCase_					(						self							:		List[str]       ,       __magic_name__							:		Optional[Any]       ,       __magic_name__							:		Tuple       ,       __magic_name__							:		Dict       ,       __magic_name__							:		str = None       ,       **__magic_name__							:		Dict       ,       ):







						"""simple docstring"""







						return normalize(__magic_name__       ,       mean=__magic_name__       ,       std=__magic_name__       ,       data_format=__magic_name__       ,       **__magic_name__						)





			def   lowerCamelCase_					(						self							:		str       ,       __magic_name__							:		List[Any]       ,       __magic_name__							:		int = None       ,       __magic_name__							:		Any = None       ,       __magic_name__							:		Union[str, Any] = None       ,       __magic_name__							:		Union[str, Any] = None       ,       __magic_name__							:		Optional[Any] = None       ,       __magic_name__							:		List[str] = None       ,       __magic_name__							:		int = None       ,       __magic_name__							:		str = None       ,       __magic_name__							:		Optional[int] = None       ,       __magic_name__							:		Optional[int] = None       ,       __magic_name__							:		Optional[int] = ChannelDimension.FIRST       ,       **__magic_name__							:		List[str]       ,       ):







						"""simple docstring"""







						UpperCamelCase         =					do_resize if do_resize is not None else self.do_resize
						UpperCamelCase         =					resample if resample is not None else self.resample
						UpperCamelCase         =					do_rescale if do_rescale is not None else self.do_rescale
						UpperCamelCase         =					rescale_factor if rescale_factor is not None else self.rescale_factor
						UpperCamelCase         =					do_normalize if do_normalize is not None else self.do_normalize
						UpperCamelCase         =					image_mean if image_mean is not None else self.image_mean
						UpperCamelCase         =					image_std if image_std is not None else self.image_std
						UpperCamelCase         =					do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

						UpperCamelCase         =					size if size is not None else self.size
						UpperCamelCase         =					get_size_dict(__magic_name__       ,       default_to_square=__magic_name__						)

						UpperCamelCase         =					make_list_of_images(__magic_name__						)

						if not valid_images(__magic_name__						):
									raise ValueError(
									    """Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, """
									    """torch.Tensor, tf.Tensor or jax.ndarray."""						)

						if do_resize and size is None or resample is None:
									raise ValueError("""Size and resample must be specified if do_resize is True."""						)

						if do_rescale and rescale_factor is None:
									raise ValueError("""Rescale factor must be specified if do_rescale is True."""						)

						if do_normalize and (image_mean is None or image_std is None):
									raise ValueError("""Image mean and std must be specified if do_normalize is True."""						)

						# PIL RGBA images are converted to RGB
						if do_convert_rgb:
									UpperCamelCase         =					[convert_to_rgb(__magic_name__						) for image in images]

						# All transformations expect numpy arrays.
						UpperCamelCase         =					[to_numpy_array(__magic_name__						) for image in images]

						if do_resize:
									UpperCamelCase         =					[self.resize(image=__magic_name__       ,       size=__magic_name__       ,       resample=__magic_name__						) for image in images]

						if do_rescale:
									UpperCamelCase         =					[self.rescale(image=__magic_name__       ,       scale=__magic_name__						) for image in images]

						if do_normalize:
									UpperCamelCase         =					[self.normalize(image=__magic_name__       ,       mean=__magic_name__       ,       std=__magic_name__						) for image in images]

						UpperCamelCase         =					[to_channel_dimension_format(__magic_name__       ,       __magic_name__						) for image in images]

						UpperCamelCase         =					BatchFeature(data={"""pixel_values""": images}       ,       tensor_type=__magic_name__						)

						return encoded_outputs








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


__snake_case            =   logging.get_logger(__name__)

__snake_case            =   {
    "microsoft/markuplm-base": "https://huggingface.co/microsoft/markuplm-base/resolve/main/config.json",
    "microsoft/markuplm-large": "https://huggingface.co/microsoft/markuplm-large/resolve/main/config.json",
}




class    UpperCAmelCase					(       __snake_case    ):
			lowercase						= """markuplm"""




			def __init__(						self							:		Optional[Any]       ,       __magic_name__							:		List[Any]=3_0_5_2_2       ,       __magic_name__							:		int=7_6_8       ,       __magic_name__							:		List[Any]=1_2       ,       __magic_name__							:		List[Any]=1_2       ,       __magic_name__							:		str=3_0_7_2       ,       __magic_name__							:		Optional[int]="gelu"       ,       __magic_name__							:		Dict=0.1       ,       __magic_name__							:		Optional[int]=0.1       ,       __magic_name__							:		Any=5_1_2       ,       __magic_name__							:		List[str]=2       ,       __magic_name__							:		Dict=0.02       ,       __magic_name__							:		List[str]=1e-12       ,       __magic_name__							:		str=0       ,       __magic_name__							:		List[str]=0       ,       __magic_name__							:		Optional[Any]=2       ,       __magic_name__							:		Dict=2_5_6       ,       __magic_name__							:		Tuple=1_0_2_4       ,       __magic_name__							:		Any=2_1_6       ,       __magic_name__							:		str=1_0_0_1       ,       __magic_name__							:		Dict=3_2       ,       __magic_name__							:		Optional[int]=5_0       ,       __magic_name__							:		List[Any]="absolute"       ,       __magic_name__							:		Any=True       ,       __magic_name__							:		Optional[Any]=None       ,       **__magic_name__							:		List[str]       ,       ):







						"""simple docstring"""







						super().__init__(
						    pad_token_id=__magic_name__       ,       bos_token_id=__magic_name__       ,       eos_token_id=__magic_name__       ,       **__magic_name__       ,       )
						UpperCamelCase         =					vocab_size
						UpperCamelCase         =					hidden_size
						UpperCamelCase         =					num_hidden_layers
						UpperCamelCase         =					num_attention_heads
						UpperCamelCase         =					hidden_act
						UpperCamelCase         =					intermediate_size
						UpperCamelCase         =					hidden_dropout_prob
						UpperCamelCase         =					attention_probs_dropout_prob
						UpperCamelCase         =					max_position_embeddings
						UpperCamelCase         =					type_vocab_size
						UpperCamelCase         =					initializer_range
						UpperCamelCase         =					layer_norm_eps
						UpperCamelCase         =					position_embedding_type
						UpperCamelCase         =					use_cache
						UpperCamelCase         =					classifier_dropout
						# additional properties
						UpperCamelCase         =					max_depth
						UpperCamelCase         =					max_xpath_tag_unit_embeddings
						UpperCamelCase         =					max_xpath_subs_unit_embeddings
						UpperCamelCase         =					tag_pad_id
						UpperCamelCase         =					subs_pad_id
						UpperCamelCase         =					xpath_unit_hidden_size




