




'''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

UpperCamelCase_						:      List[Any]       =						logging.get_logger(__name__)





def      __a     (       _UpperCamelCase:   Optional[int] ,						_UpperCamelCase:   Dict ,						_UpperCamelCase:   List[str]   )						->			Dict:

     """simple docstring"""




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





def      __a     (       _UpperCamelCase:   np.ndarray ,						_UpperCamelCase:   Optional[str] ,						_UpperCamelCase:   Optional[str] = None   )						->			Any:

     """simple docstring"""




     _snake_case							=				tesseract_config if tesseract_config is not None else ""

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

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

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

     # finally, normalize the bounding boxes
     _snake_case							=				[]
     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							):
     SCREAMING_SNAKE_CASE_							:   Tuple       =						["""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:
          super().__init__(**_SCREAMING_SNAKE_CASE   )
          _snake_case							=				size if size is not None else {"height": 224, "width": 224}
          _snake_case							=				get_size_dict(_SCREAMING_SNAKE_CASE   )

          _snake_case							=				do_resize
          _snake_case							=				size
          _snake_case							=				resample
          _snake_case							=				apply_ocr
          _snake_case							=				ocr_lang
          _snake_case							=				tesseract_config






     def     _lowercase     (			self ,_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE = PILImageResampling.BILINEAR ,_SCREAMING_SNAKE_CASE = None ,**_SCREAMING_SNAKE_CASE ,)							->      np.ndarray:
          _snake_case							=				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()}"""   )
          _snake_case							=				(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     _lowercase     (			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:
          _snake_case							=				do_resize if do_resize is not None else self.do_resize
          _snake_case							=				size if size is not None else self.size
          _snake_case							=				get_size_dict(_SCREAMING_SNAKE_CASE   )
          _snake_case							=				resample if resample is not None else self.resample
          _snake_case							=				apply_ocr if apply_ocr is not None else self.apply_ocr
          _snake_case							=				ocr_lang if ocr_lang is not None else self.ocr_lang
          _snake_case							=				tesseract_config if tesseract_config is not None else self.tesseract_config

          _snake_case							=				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.
          _snake_case							=				[to_numpy_array(_SCREAMING_SNAKE_CASE   ) for image in images]

          if apply_ocr:
               requires_backends(self ,"pytesseract"   )
               _snake_case							=				[]
               _snake_case							=				[]
               for image in images:
                    _snake_case							, _snake_case							=				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:
               _snake_case							=				[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)
          _snake_case							=				[flip_channel_order(_SCREAMING_SNAKE_CASE   ) for image in images]
          _snake_case							=				[to_channel_dimension_format(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   ) for image in images]

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

          if apply_ocr:
               _snake_case							=				words_batch
               _snake_case							=				boxes_batch
          return data








'''simple docstring'''





import pprint

import requests

UpperCamelCase_						:      Tuple       =						'''https://zenquotes.io/api'''





def      __a     (       )						->			list:

     """simple docstring"""




     return requests.get(API_ENDPOINT_URL + "/today"   ).json()





def      __a     (       )						->			list:

     """simple docstring"""




     return requests.get(API_ENDPOINT_URL + "/random"   ).json()


if __name__ == "__main__":
   UpperCamelCase_						:      Any       =						random_quotes()
   pprint.pprint(response)


