



"""simple docstring"""







from typing import Dict, List, Optional, Union

import numpy as np

from transformers.utils import is_vision_available
from transformers.utils.generic import TensorType

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    is_valid_image,
    to_numpy_array,
    valid_images,
)
from ...utils import logging


if is_vision_available():
							import PIL

lowerCAmelCase_   						=   logging.get_logger(__name__)



def      __UpperCAmelCase      (    __lowerCamelCase	)							->      List[List[ImageInput]]:
		if isinstance(__lowerCamelCase						,     (list, tuple)	) and isinstance(videos[0]						,     (list, tuple)	) and is_valid_image(videos[0][0]	):
				return videos

		elif isinstance(__lowerCamelCase						,     (list, tuple)	) and is_valid_image(videos[0]	):
				return [videos]

		elif is_valid_image(__lowerCamelCase	):
				return [[videos]]

		raise ValueError(f"""Could not make batched video from {videos}"""	)





class        __A       (	A_    ):







		'''simple docstring'''





		lowerCAmelCase			:					str   	=				["pixel_values"]







		def __init__(	self						:  List[Any]			,_snake_case						:  bool = True			,_snake_case						:  Dict[str, int] = None			,_snake_case						:  PILImageResampling = PILImageResampling.BILINEAR			,_snake_case						:  bool = True			,_snake_case						:  Dict[str, int] = None			,_snake_case						:  bool = True			,_snake_case						:  Union[int, float] = 1 / 255			,_snake_case						:  bool = True			,_snake_case						:  bool = True			,_snake_case						:  Optional[Union[float, List[float]]] = None			,_snake_case						:  Optional[Union[float, List[float]]] = None			,**_snake_case						:  List[str]			,)					->		None:






				"""simple docstring"""



				super().__init__(**_snake_case						)
				lowercase__   :    int				=			size if size is not None else {'''shortest_edge''': 256}
				lowercase__   :    Union[str, Any]				=			get_size_dict(_snake_case			,default_to_square=_snake_case						)
				lowercase__   :    List[str]				=			crop_size if crop_size is not None else {'''height''': 224, '''width''': 224}
				lowercase__   :    Optional[Any]				=			get_size_dict(_snake_case			,param_name='''crop_size'''						)

				lowercase__   :    List[Any]				=			do_resize
				lowercase__   :    Optional[int]				=			size
				lowercase__   :    Union[str, Any]				=			do_center_crop
				lowercase__   :    int				=			crop_size
				lowercase__   :    List[str]				=			resample
				lowercase__   :    int				=			do_rescale
				lowercase__   :    Tuple				=			rescale_factor
				lowercase__   :    List[Any]				=			offset
				lowercase__   :    Optional[int]				=			do_normalize
				lowercase__   :    List[Any]				=			image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
				lowercase__   :    Union[str, Any]				=			image_std if image_std is not None else IMAGENET_STANDARD_STD







		def 					UpperCAmelCase    (	self						:  Optional[int]			,_snake_case						:  np.ndarray			,_snake_case						:  Dict[str, int]			,_snake_case						:  PILImageResampling = PILImageResampling.BILINEAR			,_snake_case						:  Optional[Union[str, ChannelDimension]] = None			,**_snake_case						:  List[str]			,)					->		np.ndarray:






				"""simple docstring"""



				lowercase__   :    Optional[int]				=			get_size_dict(_snake_case			,default_to_square=_snake_case						)
				if "shortest_edge" in size:
						lowercase__   :    Optional[int]				=			get_resize_output_image_size(_snake_case			,size['''shortest_edge''']			,default_to_square=_snake_case						)
				elif "height" in size and "width" in size:
						lowercase__   :    Optional[Any]				=			(size['''height'''], size['''width'''])
				else:
						raise ValueError(f"""Size must have 'height' and 'width' or 'shortest_edge' as keys. Got {size.keys()}"""						)
				return resize(_snake_case			,size=_snake_case			,resample=_snake_case			,data_format=_snake_case			,**_snake_case						)







		def 					UpperCAmelCase    (	self						:  List[Any]			,_snake_case						:  np.ndarray			,_snake_case						:  Dict[str, int]			,_snake_case						:  Optional[Union[str, ChannelDimension]] = None			,**_snake_case						:  Union[str, Any]			,)					->		np.ndarray:






				"""simple docstring"""



				lowercase__   :    Dict				=			get_size_dict(_snake_case						)
				if "height" not in size or "width" not in size:
						raise ValueError(f"""Size must have 'height' and 'width' as keys. Got {size.keys()}"""						)
				return center_crop(_snake_case			,size=(size['''height'''], size['''width'''])			,data_format=_snake_case			,**_snake_case						)







		def 					UpperCAmelCase    (	self						:  List[str]			,_snake_case						:  np.ndarray			,_snake_case						:  Union[int, float]			,_snake_case						:  bool = True			,_snake_case						:  Optional[Union[str, ChannelDimension]] = None			,**_snake_case						:  Tuple			,)					->		Any:






				"""simple docstring"""



				lowercase__   :    List[Any]				=			image.astype(np.floataa						)
				if offset:
						lowercase__   :    List[str]				=			image - (scale / 2)
				return rescale(_snake_case			,scale=_snake_case			,data_format=_snake_case			,**_snake_case						)







		def 					UpperCAmelCase    (	self						:  List[str]			,_snake_case						:  np.ndarray			,_snake_case						:  Union[float, List[float]]			,_snake_case						:  Union[float, List[float]]			,_snake_case						:  Optional[Union[str, ChannelDimension]] = None			,**_snake_case						:  Tuple			,)					->		np.ndarray:






				"""simple docstring"""



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







		def 					UpperCAmelCase    (	self						:  Union[str, Any]			,_snake_case						:  ImageInput			,_snake_case						:  bool = None			,_snake_case						:  Dict[str, int] = None			,_snake_case						:  PILImageResampling = None			,_snake_case						:  bool = None			,_snake_case						:  Dict[str, int] = None			,_snake_case						:  bool = None			,_snake_case						:  float = None			,_snake_case						:  bool = None			,_snake_case						:  bool = None			,_snake_case						:  Optional[Union[float, List[float]]] = None			,_snake_case						:  Optional[Union[float, List[float]]] = None			,_snake_case						:  Optional[ChannelDimension] = ChannelDimension.FIRST			,)					->		np.ndarray:






				"""simple docstring"""



				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_center_crop and crop_size is None:
						raise ValueError('''Crop size must be specified if do_center_crop 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.'''						)

				if offset and not do_rescale:
						raise ValueError('''For offset, do_rescale must also be set to True.'''						)

				# All transformations expect numpy arrays.
				lowercase__   :    Dict				=			to_numpy_array(_snake_case						)

				if do_resize:
						lowercase__   :    Union[str, Any]				=			self.resize(image=_snake_case			,size=_snake_case			,resample=_snake_case						)

				if do_center_crop:
						lowercase__   :    Optional[Any]				=			self.center_crop(_snake_case			,size=_snake_case						)

				if do_rescale:
						lowercase__   :    List[Any]				=			self.rescale(image=_snake_case			,scale=_snake_case			,offset=_snake_case						)

				if do_normalize:
						lowercase__   :    List[Any]				=			self.normalize(image=_snake_case			,mean=_snake_case			,std=_snake_case						)

				lowercase__   :    List[str]				=			to_channel_dimension_format(_snake_case			,_snake_case						)
				return image







		def 					UpperCAmelCase    (	self						:  List[Any]			,_snake_case						:  ImageInput			,_snake_case						:  bool = None			,_snake_case						:  Dict[str, int] = None			,_snake_case						:  PILImageResampling = None			,_snake_case						:  bool = None			,_snake_case						:  Dict[str, int] = None			,_snake_case						:  bool = None			,_snake_case						:  float = None			,_snake_case						:  bool = None			,_snake_case						:  bool = None			,_snake_case						:  Optional[Union[float, List[float]]] = None			,_snake_case						:  Optional[Union[float, List[float]]] = None			,_snake_case						:  Optional[Union[str, TensorType]] = None			,_snake_case						:  ChannelDimension = ChannelDimension.FIRST			,**_snake_case						:  Dict			,)					->		PIL.Image.Image:






				"""simple docstring"""



				lowercase__   :    Union[str, Any]				=			do_resize if do_resize is not None else self.do_resize
				lowercase__   :    int				=			resample if resample is not None else self.resample
				lowercase__   :    List[Any]				=			do_center_crop if do_center_crop is not None else self.do_center_crop
				lowercase__   :    str				=			do_rescale if do_rescale is not None else self.do_rescale
				lowercase__   :    int				=			rescale_factor if rescale_factor is not None else self.rescale_factor
				lowercase__   :    Optional[Any]				=			offset if offset is not None else self.offset
				lowercase__   :    Optional[Any]				=			do_normalize if do_normalize is not None else self.do_normalize
				lowercase__   :    Any				=			image_mean if image_mean is not None else self.image_mean
				lowercase__   :    List[str]				=			image_std if image_std is not None else self.image_std

				lowercase__   :    Union[str, Any]				=			size if size is not None else self.size
				lowercase__   :    Union[str, Any]				=			get_size_dict(_snake_case			,default_to_square=_snake_case						)
				lowercase__   :    Tuple				=			crop_size if crop_size is not None else self.crop_size
				lowercase__   :    Union[str, Any]				=			get_size_dict(_snake_case			,param_name='''crop_size'''						)

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

				lowercase__   :    Any				=			make_batched(_snake_case						)

				lowercase__   :    Optional[int]				=			[
				    [
				        self._preprocess_image(
				            image=_snake_case			,do_resize=_snake_case			,size=_snake_case			,resample=_snake_case			,do_center_crop=_snake_case			,crop_size=_snake_case			,do_rescale=_snake_case			,rescale_factor=_snake_case			,offset=_snake_case			,do_normalize=_snake_case			,image_mean=_snake_case			,image_std=_snake_case			,data_format=_snake_case			,)
				        for img in video
				    ]
				    for video in videos
				]

				lowercase__   :    Dict				=			{'''pixel_values''': videos}
				return BatchFeature(data=_snake_case			,tensor_type=_snake_case						)





"""simple docstring"""







from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any, ClassVar, Dict, List, Optional, Union

import pyarrow as pa


if TYPE_CHECKING:
							from .features import FeatureType
@dataclass
class        __A       :







		'''simple docstring'''





		lowerCAmelCase			:					List[str]
		lowerCAmelCase			:					Optional[str]   	=				None
		# Automatically constructed
		lowerCAmelCase			:					ClassVar[str]   	=				"dict"
		lowerCAmelCase			:					ClassVar[Any]   	=				None
		lowerCAmelCase			:					str   	=				field(default="Translation"     ,init=A_     ,repr=A_    )







		def __call__(	self						:  List[str]						)					->		Any:






				"""simple docstring"""



				return pa.struct({lang: pa.string() for lang in sorted(self.languages						)}						)







		def 					UpperCAmelCase    (	self						:  List[str]						)					->		Union["FeatureType", Dict[str, "FeatureType"]]:






				"""simple docstring"""



				from .features import Value

				return {k: Value('''string'''						) for k in sorted(self.languages						)}





@dataclass
class        __A       :







		'''simple docstring'''





		lowerCAmelCase			:					Optional[List]   	=				None
		lowerCAmelCase			:					Optional[int]   	=				None
		lowerCAmelCase			:					Optional[str]   	=				None
		# Automatically constructed
		lowerCAmelCase			:					ClassVar[str]   	=				"dict"
		lowerCAmelCase			:					ClassVar[Any]   	=				None
		lowerCAmelCase			:					str   	=				field(default="TranslationVariableLanguages"     ,init=A_     ,repr=A_    )







		def 					UpperCAmelCase    (	self						:  List[Any]						)					->		Optional[int]:






				"""simple docstring"""



				lowercase__   :    Optional[int]				=			sorted(set(self.languages						)						) if self.languages else None
				lowercase__   :    Dict				=			len(self.languages						) if self.languages else None







		def __call__(	self						:  List[Any]						)					->		List[Any]:






				"""simple docstring"""



				return pa.struct({'''language''': pa.list_(pa.string()						), '''translation''': pa.list_(pa.string()						)}						)







		def 					UpperCAmelCase    (	self						:  Dict			,_snake_case						:  Tuple						)					->		int:






				"""simple docstring"""



				lowercase__   :    List[Any]				=			set(self.languages						)
				if self.languages and set(_snake_case						) - lang_set:
						raise ValueError(
						    f"""Some languages in example ({", ".join(sorted(set(_snake_case						) - lang_set						)						)}) are not in valid set ({", ".join(_snake_case						)})."""						)

				# Convert dictionary into tuples, splitting out cases where there are
				# multiple translations for a single language.
				lowercase__   :    str				=			[]
				for lang, text in translation_dict.items():
						if isinstance(_snake_case			,_snake_case						):
								translation_tuples.append((lang, text)						)
						else:
								translation_tuples.extend([(lang, el) for el in text]						)

        # Ensure translations are in ascending order by language code.
				lowercase__		,			lowercase__   :    Optional[Any]				=			zip(*sorted(_snake_case						)						)

				return {"language": languages, "translation": translations}







		def 					UpperCAmelCase    (	self						:  List[Any]						)					->		Union["FeatureType", Dict[str, "FeatureType"]]:






				"""simple docstring"""



				from .features import Sequence, Value

				return {
				    "language": Sequence(Value('''string'''						)						),
				    "translation": Sequence(Value('''string'''						)						),
				}
