






'''simple docstring'''

SCREAMING_SNAKE_CASE__     =       [4, 1, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5]
SCREAMING_SNAKE_CASE__     =       [3, 7, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5]
SCREAMING_SNAKE_CASE__     =       {
    0: 'Sunday',
    1: 'Monday',
    2: 'Tuesday',
    3: 'Wednesday',
    4: 'Thursday',
    5: 'Friday',
    6: 'Saturday',
}







def    lowercase__			(				__UpperCamelCase		,						__UpperCamelCase		,						__UpperCamelCase   )->			str:
      assert len(str(__UpperCamelCase   )   ) > 2, "year should be in YYYY format"
      assert 1 <= month <= 12, "month should be between 1 to 12"
      assert 1 <= day <= 31, "day should be between 1 to 31"

      # Doomsday algorithm:
      UpperCamelCase      = year // 100
      UpperCamelCase      = (5 * (century % 4) + 2) % 7
      UpperCamelCase      = year % 100
      UpperCamelCase      = centurian % 12
      UpperCamelCase      = (
          (centurian // 12) + centurian_m + (centurian_m // 4) + century_anchor
      ) % 7
      UpperCamelCase      = (
          DOOMSDAY_NOT_LEAP[month - 1]
          if (year % 4 != 0) or (centurian == 0 and (year % 400) == 0)
          else DOOMSDAY_LEAP[month - 1]
      )
      UpperCamelCase      = (dooms_day + day - day_anchor) % 7
      return WEEK_DAY_NAMES[week_day]


if __name__ == "__main__":
     import doctest

     doctest.testmod()








'''simple docstring'''

from typing import Dict, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import flip_channel_order, resize, to_channel_dimension_format, to_pil_image
from ...image_utils import (
    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

SCREAMING_SNAKE_CASE__     =       logging.get_logger(__name__)







def    lowercase__			(				__UpperCamelCase		,						__UpperCamelCase		,						__UpperCamelCase   )->			int:
      return [
          int(1000 * (box[0] / width)   ),
          int(1000 * (box[1] / height)   ),
          int(1000 * (box[2] / width)   ),
          int(1000 * (box[3] / height)   ),
      ]







def    lowercase__			(				__UpperCamelCase		,						__UpperCamelCase		,						__UpperCamelCase = None   )->			Dict:
      UpperCamelCase      = tesseract_config if tesseract_config is not None else """"""

      # apply OCR
      UpperCamelCase      = to_pil_image(__UpperCamelCase   )
      UpperCamelCase  ,UpperCamelCase      = pil_image.size
      UpperCamelCase      = pytesseract.image_to_data(__UpperCamelCase		,						lang=__UpperCamelCase		,						output_type="""dict"""		,						config=__UpperCamelCase   )
      UpperCamelCase  ,UpperCamelCase  ,UpperCamelCase  ,UpperCamelCase  ,UpperCamelCase      = data["""text"""], data["""left"""], data["""top"""], data["""width"""], data["""height"""]

      # filter empty words and corresponding coordinates
      UpperCamelCase      = [idx for idx, word in enumerate(__UpperCamelCase   ) if not word.strip()]
      UpperCamelCase      = [word for idx, word in enumerate(__UpperCamelCase   ) if idx not in irrelevant_indices]
      UpperCamelCase      = [coord for idx, coord in enumerate(__UpperCamelCase   ) if idx not in irrelevant_indices]
      UpperCamelCase      = [coord for idx, coord in enumerate(__UpperCamelCase   ) if idx not in irrelevant_indices]
      UpperCamelCase      = [coord for idx, coord in enumerate(__UpperCamelCase   ) if idx not in irrelevant_indices]
      UpperCamelCase      = [coord for idx, coord in enumerate(__UpperCamelCase   ) if idx not in irrelevant_indices]

      # turn coordinates into (left, top, left+width, top+height) format
      UpperCamelCase      = []
      for x, y, w, h in zip(__UpperCamelCase		,						__UpperCamelCase		,						__UpperCamelCase		,						__UpperCamelCase   ):
            UpperCamelCase      = [x, y, x + w, y + h]
            actual_boxes.append(__UpperCamelCase   )

      # finally, normalize the bounding boxes
      UpperCamelCase      = []
      for box in actual_boxes:
            normalized_boxes.append(normalize_box(__UpperCamelCase		,						__UpperCamelCase		,						__UpperCamelCase   )   )

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

      return words, normalized_boxes






class     a_						(      lowerCamelCase    ):
  lowercase							=				["""pixel_values"""]

  def __init__(				self      ,		_SCREAMING_SNAKE_CASE = True      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = PILImageResampling.BILINEAR      ,		_SCREAMING_SNAKE_CASE = True      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = ""      ,		**_SCREAMING_SNAKE_CASE      ,		)  ->				None:



        """simple docstring"""






        super().__init__(**_SCREAMING_SNAKE_CASE				)
        UpperCamelCase      = size if size is not None else {"""height""": 224, """width""": 224}
        UpperCamelCase      = get_size_dict(_SCREAMING_SNAKE_CASE				)

        UpperCamelCase      = do_resize
        UpperCamelCase      = size
        UpperCamelCase      = resample
        UpperCamelCase      = apply_ocr
        UpperCamelCase      = ocr_lang
        UpperCamelCase      = tesseract_config

  def   A__						(				self      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE = PILImageResampling.BILINEAR      ,		_SCREAMING_SNAKE_CASE = None      ,		**_SCREAMING_SNAKE_CASE      ,		)  ->				np.ndarray:



        """simple docstring"""






        UpperCamelCase      = get_size_dict(_SCREAMING_SNAKE_CASE				)
        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(_SCREAMING_SNAKE_CASE      ,		size=_SCREAMING_SNAKE_CASE      ,		resample=_SCREAMING_SNAKE_CASE      ,		data_format=_SCREAMING_SNAKE_CASE      ,		**_SCREAMING_SNAKE_CASE				)


  def   A__						(				self      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = ChannelDimension.FIRST      ,		**_SCREAMING_SNAKE_CASE      ,		)  ->				PIL.Image.Image:



        """simple docstring"""






        UpperCamelCase      = do_resize if do_resize is not None else self.do_resize
        UpperCamelCase      = size if size is not None else self.size
        UpperCamelCase      = get_size_dict(_SCREAMING_SNAKE_CASE				)
        UpperCamelCase      = resample if resample is not None else self.resample
        UpperCamelCase      = apply_ocr if apply_ocr is not None else self.apply_ocr
        UpperCamelCase      = ocr_lang if ocr_lang is not None else self.ocr_lang
        UpperCamelCase      = tesseract_config if tesseract_config is not None else self.tesseract_config

        UpperCamelCase      = make_list_of_images(_SCREAMING_SNAKE_CASE				)

        if not valid_images(_SCREAMING_SNAKE_CASE				):
              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."""				)

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

        if apply_ocr:
              requires_backends(self      ,		"""pytesseract"""				)
              UpperCamelCase      = []
              UpperCamelCase      = []
              for image in images:
                    UpperCamelCase  ,UpperCamelCase      = apply_tesseract(_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE				)
                    words_batch.append(_SCREAMING_SNAKE_CASE				)
                    boxes_batch.append(_SCREAMING_SNAKE_CASE				)

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

        # flip color channels from RGB to BGR (as Detectron2 requires this)
        UpperCamelCase      = [flip_channel_order(_SCREAMING_SNAKE_CASE				) for image in images]
        UpperCamelCase      = [to_channel_dimension_format(_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE				) for image in images]

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

        if apply_ocr:
              UpperCamelCase      = words_batch
              UpperCamelCase      = boxes_batch
        return data
