






from typing import List, Optional, TypeVar

from .arrow_dataset import Dataset, _concatenate_map_style_datasets, _interleave_map_style_datasets
from .dataset_dict import DatasetDict, IterableDatasetDict
from .info import DatasetInfo
from .iterable_dataset import IterableDataset, _concatenate_iterable_datasets, _interleave_iterable_datasets
from .splits import NamedSplit
from .utils import logging
from .utils.py_utils import Literal


__UpperCamelCase    :						Tuple		     =  logging.get_logger(__name__)


__UpperCamelCase    :						int		     =  TypeVar("""DatasetType""", Dataset, IterableDataset)
def    a_       (					_A					,      _A = None					,      _A = None					,      _A = None					,      _A = None					,      _A = "first_exhausted"					,      )	->	DatasetType:







				"""simple docstring"""
				from .arrow_dataset import Dataset
				from .iterable_dataset import IterableDataset

				if not datasets:
								raise ValueError('Unable to interleave an empty list of datasets.'     )
				for i, dataset in enumerate(snake_case_     ):
								if not isinstance(snake_case_					,      (Dataset, IterableDataset)     ):
												if isinstance(snake_case_					,      (DatasetDict, IterableDatasetDict)     ):
																if not dataset:
																				raise ValueError(
																				    f'''Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} '''
																				    'is an empty dataset dictionary.'     )
																raise ValueError(
																    f'''Dataset at position {i} has at least one split: {list(snake_case_     )}\n'''
																    f'''Please pick one to interleave with the other datasets, for example: dataset[\'{next(iter(snake_case_     )     )}\']'''     )
												raise ValueError(
												    f'''Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(snake_case_     ).__name__}.'''     )
								if i == 0:
												snake_case__							,  snake_case__													=   (
												    (Dataset, IterableDataset) if isinstance(snake_case_					,      snake_case_     ) else (IterableDataset, Dataset)
												)
								elif not isinstance(snake_case_					,      snake_case_     ):
												raise ValueError(
												    f'''Unable to interleave a {dataset_type.__name__} (at position 0) with a {other_type.__name__} (at position {i}). Expected a list of Dataset objects or a list of IterableDataset objects.'''     )
				if stopping_strategy not in ["first_exhausted", "all_exhausted"]:
								raise ValueError(f'''{stopping_strategy} is not supported. Please enter a valid stopping_strategy.'''     )
				if dataset_type is Dataset:
								return _interleave_map_style_datasets(
								    snake_case_					,      snake_case_					,      snake_case_					,      info=snake_case_					,      split=snake_case_					,      stopping_strategy=snake_case_     )
				else:
								return _interleave_iterable_datasets(
								    snake_case_					,      snake_case_					,      snake_case_					,      info=snake_case_					,      split=snake_case_					,      stopping_strategy=snake_case_     )


def    a_       (					_A					,      _A = None					,      _A = None					,      _A = 0					,      )	->	DatasetType:







				"""simple docstring"""

				if not dsets:
								raise ValueError('Unable to concatenate an empty list of datasets.'     )
				for i, dataset in enumerate(snake_case_     ):
								if not isinstance(snake_case_					,      (Dataset, IterableDataset)     ):
												if isinstance(snake_case_					,      (DatasetDict, IterableDatasetDict)     ):
																if not dataset:
																				raise ValueError(
																				    f'''Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} '''
																				    'is an empty dataset dictionary.'     )
																raise ValueError(
																    f'''Dataset at position {i} has at least one split: {list(snake_case_     )}\n'''
																    f'''Please pick one to interleave with the other datasets, for example: dataset[\'{next(iter(snake_case_     )     )}\']'''     )
												raise ValueError(
												    f'''Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(snake_case_     ).__name__}.'''     )
								if i == 0:
												snake_case__							,  snake_case__													=   (
												    (Dataset, IterableDataset) if isinstance(snake_case_					,      snake_case_     ) else (IterableDataset, Dataset)
												)
								elif not isinstance(snake_case_					,      snake_case_     ):
												raise ValueError(
												    f'''Unable to interleave a {dataset_type.__name__} (at position 0) with a {other_type.__name__} (at position {i}). Expected a list of Dataset objects or a list of IterableDataset objects.'''     )
				if dataset_type is Dataset:
								return _concatenate_map_style_datasets(snake_case_					,      info=snake_case_					,      split=snake_case_					,      axis=snake_case_     )
				else:
								return _concatenate_iterable_datasets(snake_case_					,      info=snake_case_					,      split=snake_case_					,      axis=snake_case_     )











import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding

class 		SCREAMING_SNAKE_CASE__				(       _UpperCAmelCase  ):
      A_						:				List[str]							=    ['image_processor', 'tokenizer']
      A_						:				Optional[Any]							=    'CLIPImageProcessor'
      A_						:				Any							=    ('XLMRobertaTokenizer', 'XLMRobertaTokenizerFast')


      def __init__(self       :      int				,			a__       :      int=None				,			a__       :      Dict=None				,			**a__       :      List[str]      ):





         """simple docstring"""



         __snake_case							       =   None
         if "feature_extractor" in kwargs:
            warnings.warn(
                '''The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'''
                ''' instead.'''				,			a__				,			)
            __snake_case							       =   kwargs.pop('''feature_extractor'''      )

         __snake_case							       =   image_processor if image_processor is not None else feature_extractor
         if image_processor is None:
            raise ValueError('''You need to specify an `image_processor`.'''      )
         if tokenizer is None:
            raise ValueError('''You need to specify a `tokenizer`.'''      )

         super().__init__(a__				,			a__      )


      def __call__(self       :      Any				,			a__       :      Dict=None				,			a__       :      List[str]=None				,			a__       :      Dict=None				,			**a__       :      Tuple      ):





         """simple docstring"""



         if text is None and images is None:
            raise ValueError('''You have to specify either text or images. Both cannot be none.'''      )

         if text is not None:
            __snake_case							       =   self.tokenizer(a__				,			return_tensors=a__				,			**a__      )

         if images is not None:
            __snake_case							       =   self.image_processor(a__				,			return_tensors=a__				,			**a__      )

         if text is not None and images is not None:
            __snake_case							       =   image_features.pixel_values
            return encoding
         elif text is not None:
            return encoding
         else:
            return BatchEncoding(data=dict(**a__      )				,			tensor_type=a__      )


      def    a (self       :      Union[str, Any]				,			*a__       :      int				,			**a__       :      List[Any]      ):





         """simple docstring"""



         return self.tokenizer.batch_decode(*a__				,			**a__      )


      def    a (self       :      Any				,			*a__       :      List[Any]				,			**a__       :      List[str]      ):





         """simple docstring"""



         return self.tokenizer.decode(*a__				,			**a__      )


      @property
      def    a (self       :      int      ):





         """simple docstring"""



         __snake_case							       =   self.tokenizer.model_input_names
         __snake_case							       =   self.image_processor.model_input_names
         return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names      )      )

