


'''simple docstring'''






import unittest

from transformers import (
    MODEL_FOR_CAUSAL_LM_MAPPING,
    TF_MODEL_FOR_CAUSAL_LM_MAPPING,
    TextGenerationPipeline,
    logging,
    pipeline,
)
from transformers.testing_utils import (
    CaptureLogger,
    is_pipeline_test,
    require_accelerate,
    require_tf,
    require_torch,
    require_torch_gpu,
    require_torch_or_tf,
)

from .test_pipelines_common import ANY




@is_pipeline_test
@require_torch_or_tf
class 		a__    (							unittest.TestCase  ):





							'''simple docstring'''






							lowercase__      :       Union[str, Any]     						=				MODEL_FOR_CAUSAL_LM_MAPPING
							lowercase__      :       Union[str, Any]     						=				TF_MODEL_FOR_CAUSAL_LM_MAPPING







							@require_torch
							def   __SCREAMING_SNAKE_CASE							(		self       )	->							Any:
														lowerCAmelCase__	       =     pipeline(task='''text-generation''' ,   model='''sshleifer/tiny-ctrl''' ,   framework='''pt'''       )
														# Using `do_sample=False` to force deterministic output
														lowerCAmelCase__	       =     text_generator('''This is a test''' ,   do_sample=lowerCamelCase_       )
														self.assertEqual(
														    lowerCamelCase_ ,   [
														        {
														            '''generated_text''': (
														                '''This is a test ☃ ☃ segmental segmental segmental 议议eski eski flutter flutter Lacy oscope.'''
														                ''' oscope. FiliFili@@'''
														            )
														        }
														    ] ,   )

														lowerCAmelCase__	       =     text_generator(['''This is a test''', '''This is a second test''']       )
														self.assertEqual(
														    lowerCamelCase_ ,   [
														        [
														            {
														                '''generated_text''': (
														                    '''This is a test ☃ ☃ segmental segmental segmental 议议eski eski flutter flutter Lacy oscope.'''
														                    ''' oscope. FiliFili@@'''
														                )
														            }
														        ],
														        [
														            {
														                '''generated_text''': (
														                    '''This is a second test ☃ segmental segmental segmental 议议eski eski flutter flutter Lacy'''
														                    ''' oscope. oscope. FiliFili@@'''
														                )
														            }
														        ],
														    ] ,   )

														lowerCAmelCase__	       =     text_generator('''This is a test''' ,   do_sample=lowerCamelCase_ ,   num_return_sequences=2 ,   return_tensors=lowerCamelCase_       )
														self.assertEqual(
														    lowerCamelCase_ ,   [
														        {'''generated_token_ids''': ANY(lowerCamelCase_       )},
														        {'''generated_token_ids''': ANY(lowerCamelCase_       )},
														    ] ,   )
														lowerCAmelCase__	       =     text_generator.model.config.eos_token_id
														lowerCAmelCase__	       =     '''<pad>'''
														lowerCAmelCase__	       =     text_generator(
														    ['''This is a test''', '''This is a second test'''] ,   do_sample=lowerCamelCase_ ,   num_return_sequences=2 ,   batch_size=2 ,   return_tensors=lowerCamelCase_ ,   )
														self.assertEqual(
														    lowerCamelCase_ ,   [
														        [
														            {'''generated_token_ids''': ANY(lowerCamelCase_       )},
														            {'''generated_token_ids''': ANY(lowerCamelCase_       )},
														        ],
														        [
														            {'''generated_token_ids''': ANY(lowerCamelCase_       )},
														            {'''generated_token_ids''': ANY(lowerCamelCase_       )},
														        ],
														    ] ,   )







							@require_tf
							def   __SCREAMING_SNAKE_CASE							(		self       )	->							List[str]:
														lowerCAmelCase__	       =     pipeline(task='''text-generation''' ,   model='''sshleifer/tiny-ctrl''' ,   framework='''tf'''       )

														# Using `do_sample=False` to force deterministic output
														lowerCAmelCase__	       =     text_generator('''This is a test''' ,   do_sample=lowerCamelCase_       )
														self.assertEqual(
														    lowerCamelCase_ ,   [
														        {
														            '''generated_text''': (
														                '''This is a test FeyFeyFey(Croatis.), s.), Cannes Cannes Cannes 閲閲Cannes Cannes Cannes 攵'''
														                ''' please,'''
														            )
														        }
														    ] ,   )

														lowerCAmelCase__	       =     text_generator(['''This is a test''', '''This is a second test'''] ,   do_sample=lowerCamelCase_       )
														self.assertEqual(
														    lowerCamelCase_ ,   [
														        [
														            {
														                '''generated_text''': (
														                    '''This is a test FeyFeyFey(Croatis.), s.), Cannes Cannes Cannes 閲閲Cannes Cannes Cannes 攵'''
														                    ''' please,'''
														                )
														            }
														        ],
														        [
														            {
														                '''generated_text''': (
														                    '''This is a second test Chieftain Chieftain prefecture prefecture prefecture Cannes Cannes'''
														                    ''' Cannes 閲閲Cannes Cannes Cannes 攵 please,'''
														                )
														            }
														        ],
														    ] ,   )







							def   __SCREAMING_SNAKE_CASE							(		self ,   lowerCamelCase_ ,   lowerCamelCase_ ,   lowerCamelCase_       )	->							str:
														lowerCAmelCase__	       =     TextGenerationPipeline(model=lowerCamelCase_ ,   tokenizer=lowerCamelCase_       )
														return text_generator, ["This is a test", "Another test"]







							def   __SCREAMING_SNAKE_CASE							(		self       )	->							Optional[int]:
														lowerCAmelCase__	       =     '''Hello I believe in'''
														lowerCAmelCase__	       =     pipeline('''text-generation''' ,   model='''hf-internal-testing/tiny-random-gpt2'''       )
														lowerCAmelCase__	       =     text_generator(lowerCamelCase_       )
														self.assertEqual(
														    lowerCamelCase_ ,   [{'''generated_text''': '''Hello I believe in fe fe fe fe fe fe fe fe fe fe fe fe'''}] ,   )

														lowerCAmelCase__	       =     text_generator(lowerCamelCase_ ,   stop_sequence=''' fe'''       )
														self.assertEqual(lowerCamelCase_ ,   [{'''generated_text''': '''Hello I believe in fe'''}]       )







							def   __SCREAMING_SNAKE_CASE							(		self ,   lowerCamelCase_ ,   lowerCamelCase_       )	->							Union[str, Any]:
														lowerCAmelCase__	       =     text_generator.model
														lowerCAmelCase__	       =     text_generator.tokenizer

														lowerCAmelCase__	       =     text_generator('''This is a test'''       )
														self.assertEqual(lowerCamelCase_ ,   [{'''generated_text''': ANY(lowerCamelCase_       )}]       )
														self.assertTrue(outputs[0]['''generated_text'''].startswith('''This is a test'''       )       )

														lowerCAmelCase__	       =     text_generator('''This is a test''' ,   return_full_text=lowerCamelCase_       )
														self.assertEqual(lowerCamelCase_ ,   [{'''generated_text''': ANY(lowerCamelCase_       )}]       )
														self.assertNotIn('''This is a test''' ,   outputs[0]['''generated_text''']       )

														lowerCAmelCase__	       =     pipeline(task='''text-generation''' ,   model=lowerCamelCase_ ,   tokenizer=lowerCamelCase_ ,   return_full_text=lowerCamelCase_       )
														lowerCAmelCase__	       =     text_generator('''This is a test'''       )
														self.assertEqual(lowerCamelCase_ ,   [{'''generated_text''': ANY(lowerCamelCase_       )}]       )
														self.assertNotIn('''This is a test''' ,   outputs[0]['''generated_text''']       )

														lowerCAmelCase__	       =     text_generator('''This is a test''' ,   return_full_text=lowerCamelCase_       )
														self.assertEqual(lowerCamelCase_ ,   [{'''generated_text''': ANY(lowerCamelCase_       )}]       )
														self.assertTrue(outputs[0]['''generated_text'''].startswith('''This is a test'''       )       )

														lowerCAmelCase__	       =     text_generator(['''This is great !''', '''Something else'''] ,   num_return_sequences=2 ,   do_sample=lowerCamelCase_       )
														self.assertEqual(
														    lowerCamelCase_ ,   [
														        [{'''generated_text''': ANY(lowerCamelCase_       )}, {'''generated_text''': ANY(lowerCamelCase_       )}],
														        [{'''generated_text''': ANY(lowerCamelCase_       )}, {'''generated_text''': ANY(lowerCamelCase_       )}],
														    ] ,   )

														if text_generator.tokenizer.pad_token is not None:
																					lowerCAmelCase__	       =     text_generator(
																					    ['''This is great !''', '''Something else'''] ,   num_return_sequences=2 ,   batch_size=2 ,   do_sample=lowerCamelCase_       )
																					self.assertEqual(
																					    lowerCamelCase_ ,   [
																					        [{'''generated_text''': ANY(lowerCamelCase_       )}, {'''generated_text''': ANY(lowerCamelCase_       )}],
																					        [{'''generated_text''': ANY(lowerCamelCase_       )}, {'''generated_text''': ANY(lowerCamelCase_       )}],
																					    ] ,   )

														with self.assertRaises(lowerCamelCase_       ):
																					lowerCAmelCase__	       =     text_generator('''test''' ,   return_full_text=lowerCamelCase_ ,   return_text=lowerCamelCase_       )
														with self.assertRaises(lowerCamelCase_       ):
																					lowerCAmelCase__	       =     text_generator('''test''' ,   return_full_text=lowerCamelCase_ ,   return_tensors=lowerCamelCase_       )
														with self.assertRaises(lowerCamelCase_       ):
																					lowerCAmelCase__	       =     text_generator('''test''' ,   return_text=lowerCamelCase_ ,   return_tensors=lowerCamelCase_       )

														# Empty prompt is slighly special
														# it requires BOS token to exist.
														# Special case for Pegasus which will always append EOS so will
														# work even without BOS.
														if (
														    text_generator.tokenizer.bos_token_id is not None
														    or "Pegasus" in tokenizer.__class__.__name__
														    or "Git" in model.__class__.__name__
														):
																					lowerCAmelCase__	       =     text_generator(''''''       )
																					self.assertEqual(lowerCamelCase_ ,   [{'''generated_text''': ANY(lowerCamelCase_       )}]       )
														else:
																					with self.assertRaises((ValueError, AssertionError)       ):
																												lowerCAmelCase__	       =     text_generator(''''''       )

														if text_generator.framework == "tf":
																					# TF generation does not support max_new_tokens, and it's impossible
																					# to control long generation with only max_length without
																					# fancy calculation, dismissing tests for now.
																					return
														# We don't care about infinite range models.
														# They already work.
														# Skip this test for XGLM, since it uses sinusoidal positional embeddings which are resized on-the-fly.
														lowerCAmelCase__	       =     ['''RwkvForCausalLM''', '''XGLMForCausalLM''', '''GPTNeoXForCausalLM''']
														if (
														    tokenizer.model_max_length < 1_00_00
														    and text_generator.model.__class__.__name__ not in EXTRA_MODELS_CAN_HANDLE_LONG_INPUTS
														):
																					# Handling of large generations
																					with self.assertRaises((RuntimeError, IndexError, ValueError, AssertionError)       ):
																												text_generator('''This is a test''' * 5_00 ,   max_new_tokens=20       )

																					lowerCAmelCase__	       =     text_generator('''This is a test''' * 5_00 ,   handle_long_generation='''hole''' ,   max_new_tokens=20       )
																					# Hole strategy cannot work
																					with self.assertRaises(lowerCamelCase_       ):
																												text_generator(
																												    '''This is a test''' * 5_00 ,   handle_long_generation='''hole''' ,   max_new_tokens=tokenizer.model_max_length + 10 ,   )







							@require_torch
							@require_accelerate
							@require_torch_gpu
							def   __SCREAMING_SNAKE_CASE							(		self       )	->							str:
														import torch

														# Classic `model_kwargs`
														lowerCAmelCase__	       =     pipeline(
														    model='''hf-internal-testing/tiny-random-bloom''' ,   model_kwargs={'''device_map''': '''auto''', '''torch_dtype''': torch.bfloataa} ,   )
														self.assertEqual(pipe.model.device ,   torch.device(0       )       )
														self.assertEqual(pipe.model.lm_head.weight.dtype ,   torch.bfloataa       )
														lowerCAmelCase__	       =     pipe('''This is a test'''       )
														self.assertEqual(
														    lowerCamelCase_ ,   [
														        {
														            '''generated_text''': (
														                '''This is a test test test test test test test test test test test test test test test test'''
														                ''' test'''
														            )
														        }
														    ] ,   )

														# Upgraded those two to real pipeline arguments (they just get sent for the model as they're unlikely to mean anything else.)
														lowerCAmelCase__	       =     pipeline(model='''hf-internal-testing/tiny-random-bloom''' ,   device_map='''auto''' ,   torch_dtype=torch.bfloataa       )
														self.assertEqual(pipe.model.device ,   torch.device(0       )       )
														self.assertEqual(pipe.model.lm_head.weight.dtype ,   torch.bfloataa       )
														lowerCAmelCase__	       =     pipe('''This is a test'''       )
														self.assertEqual(
														    lowerCamelCase_ ,   [
														        {
														            '''generated_text''': (
														                '''This is a test test test test test test test test test test test test test test test test'''
														                ''' test'''
														            )
														        }
														    ] ,   )

														# torch_dtype will be automatically set to float32 if not provided - check: https://github.com/huggingface/transformers/pull/20602
														lowerCAmelCase__	       =     pipeline(model='''hf-internal-testing/tiny-random-bloom''' ,   device_map='''auto'''       )
														self.assertEqual(pipe.model.device ,   torch.device(0       )       )
														self.assertEqual(pipe.model.lm_head.weight.dtype ,   torch.floataa       )
														lowerCAmelCase__	       =     pipe('''This is a test'''       )
														self.assertEqual(
														    lowerCamelCase_ ,   [
														        {
														            '''generated_text''': (
														                '''This is a test test test test test test test test test test test test test test test test'''
														                ''' test'''
														            )
														        }
														    ] ,   )







							@require_torch
							@require_torch_gpu
							def   __SCREAMING_SNAKE_CASE							(		self       )	->							Optional[int]:
														import torch

														lowerCAmelCase__	       =     pipeline(model='''hf-internal-testing/tiny-random-bloom''' ,   device=0 ,   torch_dtype=torch.floataa       )
														pipe('''This is a test'''       )







							@require_torch
							@require_accelerate
							@require_torch_gpu
							def   __SCREAMING_SNAKE_CASE							(		self       )	->							str:
														import torch

														lowerCAmelCase__	       =     pipeline(model='''hf-internal-testing/tiny-random-bloom''' ,   device_map='''auto''' ,   torch_dtype=torch.floataa       )
														pipe('''This is a test''' ,   do_sample=lowerCamelCase_ ,   top_p=0.5       )







							def   __SCREAMING_SNAKE_CASE							(		self       )	->							int:
														lowerCAmelCase__	       =     '''Hello world'''
														lowerCAmelCase__	       =     pipeline('''text-generation''' ,   model='''hf-internal-testing/tiny-random-gpt2'''       )
														if text_generator.model.framework == "tf":
																					lowerCAmelCase__	       =     logging.get_logger('''transformers.generation.tf_utils'''       )
														else:
																					lowerCAmelCase__	       =     logging.get_logger('''transformers.generation.utils'''       )
														lowerCAmelCase__	       =     '''Both `max_new_tokens`'''  # The beggining of the message to be checked in this test

														# Both are set by the user -> log warning
														with CaptureLogger(lowerCamelCase_       ) as cl:
																					lowerCAmelCase__	       =     text_generator(lowerCamelCase_ ,   max_length=10 ,   max_new_tokens=1       )
														self.assertIn(lowerCamelCase_ ,   cl.out       )

														# The user only sets one -> no warning
														with CaptureLogger(lowerCamelCase_       ) as cl:
																					lowerCAmelCase__	       =     text_generator(lowerCamelCase_ ,   max_new_tokens=1       )
														self.assertNotIn(lowerCamelCase_ ,   cl.out       )

														with CaptureLogger(lowerCamelCase_       ) as cl:
																					lowerCAmelCase__	       =     text_generator(lowerCamelCase_ ,   max_length=10       )
														self.assertNotIn(lowerCamelCase_ ,   cl.out       )



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

__UpperCAmelCase       =							logging.get_logger(__name__)


def  _snake_case       (					A			,   A			,   A	)						->   Optional[Any]:
							return [
							    int(1000 * (box[0] / width)	),
							    int(1000 * (box[1] / height)	),
							    int(1000 * (box[2] / width)	),
							    int(1000 * (box[3] / height)	),
							]


def  _snake_case       (					A			,   A			,   A	)						->   Union[str, Any]:
							lowerCAmelCase__	       =     to_pil_image(A	)
							lowerCAmelCase__       , lowerCAmelCase__	       =     pil_image.size
							lowerCAmelCase__	       =     pytesseract.image_to_data(A			,   lang=A			,   output_type='''dict'''			,   config=A	)
							lowerCAmelCase__       , lowerCAmelCase__       , lowerCAmelCase__       , lowerCAmelCase__       , lowerCAmelCase__	       =     data['''text'''], data['''left'''], data['''top'''], data['''width'''], data['''height''']

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

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

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

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

							return words, normalized_boxes






class 		a__    (							a__  ):





							'''simple docstring'''






							lowercase__      :       Any     						=				["pixel_values"]







							def __init__(		self ,   lowerCamelCase_ = True ,   lowerCamelCase_ = None ,   lowerCamelCase_ = PILImageResampling.BILINEAR ,   lowerCamelCase_ = True ,   lowerCamelCase_ = 1 / 2_55 ,   lowerCamelCase_ = True ,   lowerCamelCase_ = None ,   lowerCamelCase_ = None ,   lowerCamelCase_ = True ,   lowerCamelCase_ = None ,   lowerCamelCase_ = "" ,   **lowerCamelCase_ ,   )	->							None:
														super().__init__(**lowerCamelCase_       )
														lowerCAmelCase__	       =     size if size is not None else {'''height''': 2_24, '''width''': 2_24}
														lowerCAmelCase__	       =     get_size_dict(lowerCamelCase_       )

														lowerCAmelCase__	       =     do_resize
														lowerCAmelCase__	       =     size
														lowerCAmelCase__	       =     resample
														lowerCAmelCase__	       =     do_rescale
														lowerCAmelCase__	       =     rescale_value
														lowerCAmelCase__	       =     do_normalize
														lowerCAmelCase__	       =     image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
														lowerCAmelCase__	       =     image_std if image_std is not None else IMAGENET_STANDARD_STD
														lowerCAmelCase__	       =     apply_ocr
														lowerCAmelCase__	       =     ocr_lang
														lowerCAmelCase__	       =     tesseract_config







							def   __SCREAMING_SNAKE_CASE							(		self ,   lowerCamelCase_ ,   lowerCamelCase_ ,   lowerCamelCase_ = PILImageResampling.BILINEAR ,   lowerCamelCase_ = None ,   **lowerCamelCase_ ,   )	->							np.ndarray:
														lowerCAmelCase__	       =     get_size_dict(lowerCamelCase_       )
														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()}"""       )
														lowerCAmelCase__	       =     (size['''height'''], size['''width'''])
														return resize(lowerCamelCase_ ,   size=lowerCamelCase_ ,   resample=lowerCamelCase_ ,   data_format=lowerCamelCase_ ,   **lowerCamelCase_       )







							def   __SCREAMING_SNAKE_CASE							(		self ,   lowerCamelCase_ ,   lowerCamelCase_ ,   lowerCamelCase_ = None ,   **lowerCamelCase_ ,   )	->							np.ndarray:
														return rescale(lowerCamelCase_ ,   scale=lowerCamelCase_ ,   data_format=lowerCamelCase_ ,   **lowerCamelCase_       )







							def   __SCREAMING_SNAKE_CASE							(		self ,   lowerCamelCase_ ,   lowerCamelCase_ ,   lowerCamelCase_ ,   lowerCamelCase_ = None ,   **lowerCamelCase_ ,   )	->							np.ndarray:
														return normalize(lowerCamelCase_ ,   mean=lowerCamelCase_ ,   std=lowerCamelCase_ ,   data_format=lowerCamelCase_ ,   **lowerCamelCase_       )







							def   __SCREAMING_SNAKE_CASE							(		self ,   lowerCamelCase_ ,   lowerCamelCase_ = None ,   lowerCamelCase_ = None ,   lowerCamelCase_=None ,   lowerCamelCase_ = None ,   lowerCamelCase_ = None ,   lowerCamelCase_ = None ,   lowerCamelCase_ = None ,   lowerCamelCase_ = None ,   lowerCamelCase_ = None ,   lowerCamelCase_ = None ,   lowerCamelCase_ = None ,   lowerCamelCase_ = None ,   lowerCamelCase_ = ChannelDimension.FIRST ,   **lowerCamelCase_ ,   )	->							PIL.Image.Image:
														lowerCAmelCase__	       =     do_resize if do_resize is not None else self.do_resize
														lowerCAmelCase__	       =     size if size is not None else self.size
														lowerCAmelCase__	       =     get_size_dict(lowerCamelCase_       )
														lowerCAmelCase__	       =     resample if resample is not None else self.resample
														lowerCAmelCase__	       =     do_rescale if do_rescale is not None else self.do_rescale
														lowerCAmelCase__	       =     rescale_factor if rescale_factor is not None else self.rescale_factor
														lowerCAmelCase__	       =     do_normalize if do_normalize is not None else self.do_normalize
														lowerCAmelCase__	       =     image_mean if image_mean is not None else self.image_mean
														lowerCAmelCase__	       =     image_std if image_std is not None else self.image_std
														lowerCAmelCase__	       =     apply_ocr if apply_ocr is not None else self.apply_ocr
														lowerCAmelCase__	       =     ocr_lang if ocr_lang is not None else self.ocr_lang
														lowerCAmelCase__	       =     tesseract_config if tesseract_config is not None else self.tesseract_config

														lowerCAmelCase__	       =     make_list_of_images(lowerCamelCase_       )

														if not valid_images(lowerCamelCase_       ):
																					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.
														lowerCAmelCase__	       =     [to_numpy_array(lowerCamelCase_       ) for image in images]

														# Tesseract OCR to get words + normalized bounding boxes
														if apply_ocr:
																					requires_backends(self ,   '''pytesseract'''       )
																					lowerCAmelCase__	       =     []
																					lowerCAmelCase__	       =     []
																					for image in images:
																												lowerCAmelCase__       , lowerCAmelCase__	       =     apply_tesseract(lowerCamelCase_ ,   lowerCamelCase_ ,   lowerCamelCase_       )
																												words_batch.append(lowerCamelCase_       )
																												boxes_batch.append(lowerCamelCase_       )

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

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

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

														lowerCAmelCase__	       =     [to_channel_dimension_format(lowerCamelCase_ ,   lowerCamelCase_       ) for image in images]

														lowerCAmelCase__	       =     BatchFeature(data={'''pixel_values''': images} ,   tensor_type=lowerCamelCase_       )

														if apply_ocr:
																					lowerCAmelCase__	       =     words_batch
																					lowerCAmelCase__	       =     boxes_batch
														return data