



"""simple docstring"""







from typing import Dict, Iterable, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import normalize, rescale, resize, to_channel_dimension_format, to_pil_image
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_pytesseract_available, is_vision_available, logging, requires_backends


if is_vision_available():
			import PIL

# soft dependency
if is_pytesseract_available():
			import pytesseract

A		=						logging.get_logger(__name__)

def  __SCREAMING_SNAKE_CASE		(			lowerCamelCase_:							Any     ,		lowerCamelCase_:							Dict     ,		lowerCamelCase_:							Optional[int] ):
						"""simple docstring"""






						return [
						    int(1_0_0_0 * (box[0] / width) ),
						    int(1_0_0_0 * (box[1] / height) ),
						    int(1_0_0_0 * (box[2] / width) ),
						    int(1_0_0_0 * (box[3] / height) ),
						]

def  __SCREAMING_SNAKE_CASE		(			lowerCamelCase_:							np.ndarray     ,		lowerCamelCase_:							Optional[str]     ,		lowerCamelCase_:							Optional[str] ):
						"""simple docstring"""






						snake_case   :			List[str]						    = to_pil_image(lowerCamelCase_ )
						snake_case    ,			snake_case   :			List[str]						    = pil_image.size
						snake_case   :			List[str]						    = pytesseract.image_to_data(lowerCamelCase_     ,		lang=lowerCamelCase_     ,		output_type="dict"     ,		config=lowerCamelCase_ )
						snake_case    ,			snake_case    ,			snake_case    ,			snake_case    ,			snake_case   :			str						    = data["text"], data["left"], data["top"], data["width"], data["height"]

						# filter empty words and corresponding coordinates
						snake_case   :			Tuple						    = [idx for idx, word in enumerate(lowerCamelCase_ ) if not word.strip()]
						snake_case   :			Optional[Any]						    = [word for idx, word in enumerate(lowerCamelCase_ ) if idx not in irrelevant_indices]
						snake_case   :			int						    = [coord for idx, coord in enumerate(lowerCamelCase_ ) if idx not in irrelevant_indices]
						snake_case   :			List[str]						    = [coord for idx, coord in enumerate(lowerCamelCase_ ) if idx not in irrelevant_indices]
						snake_case   :			Optional[Any]						    = [coord for idx, coord in enumerate(lowerCamelCase_ ) if idx not in irrelevant_indices]
						snake_case   :			Tuple						    = [coord for idx, coord in enumerate(lowerCamelCase_ ) if idx not in irrelevant_indices]

						# turn coordinates into (left, top, left+width, top+height) format
						snake_case   :			Union[str, Any]						    = []
						for x, y, w, h in zip(lowerCamelCase_     ,		lowerCamelCase_     ,		lowerCamelCase_     ,		lowerCamelCase_ ):
												snake_case   :			Union[str, Any]						    = [x, y, x + w, y + h]
												actual_boxes.append(lowerCamelCase_ )

						# finally, normalize the bounding boxes
						snake_case   :			List[str]						    = []
						for box in actual_boxes:
												normalized_boxes.append(normalize_box(lowerCamelCase_     ,		lowerCamelCase_     ,		lowerCamelCase_ ) )

						assert len(lowerCamelCase_ ) == len(lowerCamelCase_ ), "Not as many words as there are bounding boxes"

						return words, normalized_boxes

class       _a  ( SCREAMING_SNAKE_CASE__):
			__magic_name__     					=     ["""pixel_values"""]



			def __init__(			self							:				int   ,	_lowercase							:				bool = True   ,	_lowercase							:				Dict[str, int] = None   ,	_lowercase							:				PILImageResampling = PILImageResampling.BILINEAR   ,	_lowercase							:				bool = True   ,	_lowercase							:				float = 1 / 255   ,	_lowercase							:				bool = True   ,	_lowercase							:				Union[float, Iterable[float]] = None   ,	_lowercase							:				Union[float, Iterable[float]] = None   ,	_lowercase							:				bool = True   ,	_lowercase							:				Optional[str] = None   ,	_lowercase							:				Optional[str] = ""   ,	**_lowercase							:				Any   ,	)							->					None:
									super().__init__(**_lowercase		)
									snake_case   :			Tuple						    = size if size is not None else {"height": 224, "width": 224}
									snake_case   :			int						    = get_size_dict(_lowercase		)

									snake_case   :			List[str]						    = do_resize
									snake_case   :			Optional[Any]						    = size
									snake_case   :			Tuple						    = resample
									snake_case   :			List[Any]						    = do_rescale
									snake_case   :			List[Any]						    = rescale_value
									snake_case   :			Tuple						    = do_normalize
									snake_case   :			Union[str, Any]						    = image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
									snake_case   :			str						    = image_std if image_std is not None else IMAGENET_STANDARD_STD
									snake_case   :			Optional[int]						    = apply_ocr
									snake_case   :			Tuple						    = ocr_lang
									snake_case   :			Optional[Any]						    = tesseract_config



			def 				__lowercase					(			self							:				int   ,	_lowercase							:				np.ndarray   ,	_lowercase							:				Dict[str, int]   ,	_lowercase							:				PILImageResampling = PILImageResampling.BILINEAR   ,	_lowercase							:				Optional[Union[str, ChannelDimension]] = None   ,	**_lowercase							:				Any   ,	)							->					np.ndarray:
									snake_case   :			Any						    = get_size_dict(_lowercase		)
									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()}'''		)
									snake_case   :			List[str]						    = (size["height"], size["width"])
									return resize(_lowercase   ,	size=_lowercase   ,	resample=_lowercase   ,	data_format=_lowercase   ,	**_lowercase		)



			def 				__lowercase					(			self							:				Dict   ,	_lowercase							:				np.ndarray   ,	_lowercase							:				Union[int, float]   ,	_lowercase							:				Optional[Union[str, ChannelDimension]] = None   ,	**_lowercase							:				int   ,	)							->					np.ndarray:
									return rescale(_lowercase   ,	scale=_lowercase   ,	data_format=_lowercase   ,	**_lowercase		)



			def 				__lowercase					(			self							:				Union[str, Any]   ,	_lowercase							:				np.ndarray   ,	_lowercase							:				Union[float, Iterable[float]]   ,	_lowercase							:				Union[float, Iterable[float]]   ,	_lowercase							:				Optional[Union[str, ChannelDimension]] = None   ,	**_lowercase							:				str   ,	)							->					np.ndarray:
									return normalize(_lowercase   ,	mean=_lowercase   ,	std=_lowercase   ,	data_format=_lowercase   ,	**_lowercase		)



			def 				__lowercase					(			self							:				Dict   ,	_lowercase							:				ImageInput   ,	_lowercase							:				bool = None   ,	_lowercase							:				Dict[str, int] = None   ,	_lowercase							:				Tuple=None   ,	_lowercase							:				bool = None   ,	_lowercase							:				float = None   ,	_lowercase							:				bool = None   ,	_lowercase							:				Union[float, Iterable[float]] = None   ,	_lowercase							:				Union[float, Iterable[float]] = None   ,	_lowercase							:				bool = None   ,	_lowercase							:				Optional[str] = None   ,	_lowercase							:				Optional[str] = None   ,	_lowercase							:				Optional[Union[str, TensorType]] = None   ,	_lowercase							:				ChannelDimension = ChannelDimension.FIRST   ,	**_lowercase							:				Tuple   ,	)							->					PIL.Image.Image:
									snake_case   :			List[Any]						    = do_resize if do_resize is not None else self.do_resize
									snake_case   :			Optional[int]						    = size if size is not None else self.size
									snake_case   :			Dict						    = get_size_dict(_lowercase		)
									snake_case   :			Union[str, Any]						    = resample if resample is not None else self.resample
									snake_case   :			Optional[Any]						    = do_rescale if do_rescale is not None else self.do_rescale
									snake_case   :			Tuple						    = rescale_factor if rescale_factor is not None else self.rescale_factor
									snake_case   :			Union[str, Any]						    = do_normalize if do_normalize is not None else self.do_normalize
									snake_case   :			int						    = image_mean if image_mean is not None else self.image_mean
									snake_case   :			List[Any]						    = image_std if image_std is not None else self.image_std
									snake_case   :			Tuple						    = apply_ocr if apply_ocr is not None else self.apply_ocr
									snake_case   :			Tuple						    = ocr_lang if ocr_lang is not None else self.ocr_lang
									snake_case   :			Optional[int]						    = tesseract_config if tesseract_config is not None else self.tesseract_config

									snake_case   :			Tuple						    = make_list_of_images(_lowercase		)

									if not valid_images(_lowercase		):
															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:
															raise ValueError("Size 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("If do_normalize is True, image_mean and image_std must be specified."		)

									# All transformations expect numpy arrays.
									snake_case   :			Union[str, Any]						    = [to_numpy_array(_lowercase		) for image in images]

									# Tesseract OCR to get words + normalized bounding boxes
									if apply_ocr:
															requires_backends(self   ,	"pytesseract"		)
															snake_case   :			Dict						    = []
															snake_case   :			Tuple						    = []
															for image in images:
																					snake_case    ,			snake_case   :			Any						    = apply_tesseract(_lowercase   ,	_lowercase   ,	_lowercase		)
																					words_batch.append(_lowercase		)
																					boxes_batch.append(_lowercase		)

									if do_resize:
															snake_case   :			Tuple						    = [self.resize(image=_lowercase   ,	size=_lowercase   ,	resample=_lowercase		) for image in images]

									if do_rescale:
															snake_case   :			Any						    = [self.rescale(image=_lowercase   ,	scale=_lowercase		) for image in images]

									if do_normalize:
															snake_case   :			str						    = [self.normalize(image=_lowercase   ,	mean=_lowercase   ,	std=_lowercase		) for image in images]

									snake_case   :			int						    = [to_channel_dimension_format(_lowercase   ,	_lowercase		) for image in images]

									snake_case   :			Optional[Any]						    = BatchFeature(data={"pixel_values": images}   ,	tensor_type=_lowercase		)

									if apply_ocr:
															snake_case   :			Optional[int]						    = words_batch
															snake_case   :			List[Any]						    = boxes_batch
									return data








"""simple docstring"""







def  __SCREAMING_SNAKE_CASE		(			lowerCamelCase_:							int     ,		lowerCamelCase_:							int ):
						"""simple docstring"""






						return int((input_a, input_a).count(0 ) != 0 )

def  __SCREAMING_SNAKE_CASE		(			):
						"""simple docstring"""






						assert nand_gate(0     ,		0 ) == 1
						assert nand_gate(0     ,		1 ) == 1
						assert nand_gate(1     ,		0 ) == 1
						assert nand_gate(1     ,		1 ) == 0


if __name__ == "__main__":
			print(nand_gate(0, 0))
			print(nand_gate(0, 1))
			print(nand_gate(1, 0))
			print(nand_gate(1, 1))



