




'''simple docstring'''




import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin

class 						lowerCAmelCase_   ( lowerCamelCase_   ):







  '''simple docstring'''







  lowerCAmelCase_				:					str				     =						["""image_processor""", """tokenizer"""]
  lowerCAmelCase_				:					Tuple				     =						"""AutoImageProcessor"""
  lowerCAmelCase_				:					Optional[Any]				     =						"""AutoTokenizer"""


  def __init__(						self    :	Optional[int]						,		_UpperCAmelCase    :	Union[str, Any]=None						,		_UpperCAmelCase    :	Any=None						,		**_UpperCAmelCase    :	Optional[Any] ):






   """simple docstring"""






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

   UpperCAmelCase__										=    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__(_UpperCAmelCase						,		_UpperCAmelCase )
   UpperCAmelCase__										=    self.image_processor
   UpperCAmelCase__										=    False


  def __call__(						self    :	Any						,		*_UpperCAmelCase    :	Any						,		**_UpperCAmelCase    :	str ):






   """simple docstring"""






   if self._in_target_context_manager:
    return self.current_processor(*_UpperCAmelCase						,		**_UpperCAmelCase )

   UpperCAmelCase__										=    kwargs.pop("""images"""						,		_UpperCAmelCase )
   UpperCAmelCase__										=    kwargs.pop("""text"""						,		_UpperCAmelCase )
   if len(_UpperCAmelCase ) > 0:
    UpperCAmelCase__										=    args[0]
    UpperCAmelCase__										=    args[1:]

   if images is None and text is None:
    raise ValueError("""You need to specify either an `images` or `text` input to process.""" )

   if images is not None:
    UpperCAmelCase__										=    self.image_processor(_UpperCAmelCase						,		*_UpperCAmelCase						,		**_UpperCAmelCase )
   if text is not None:
    UpperCAmelCase__										=    self.tokenizer(_UpperCAmelCase						,		**_UpperCAmelCase )

   if text is None:
    return inputs
   elif images is None:
    return encodings
   else:
    UpperCAmelCase__										=    encodings["""input_ids"""]
    return inputs


  def 							SCREAMING_SNAKE_CASE__			(						self    :	Union[str, Any]						,		*_UpperCAmelCase    :	Any						,		**_UpperCAmelCase    :	str ):






   """simple docstring"""






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


  def 							SCREAMING_SNAKE_CASE__			(						self    :	Optional[Any]						,		*_UpperCAmelCase    :	Optional[int]						,		**_UpperCAmelCase    :	List[str] ):






   """simple docstring"""






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


  @contextmanager
  def 							SCREAMING_SNAKE_CASE__			(						self    :	List[str] ):






   """simple docstring"""






   warnings.warn(
       """`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your """
       """labels by using the argument `text` of the regular `__call__` method (either in the same call as """
       """your images inputs, or in a separate call.""" )
   UpperCAmelCase__										=    True
   UpperCAmelCase__										=    self.tokenizer
   yield
   UpperCAmelCase__										=    self.image_processor
   UpperCAmelCase__										=    False


  @property
  def 							SCREAMING_SNAKE_CASE__			(						self    :	Dict ):






   """simple docstring"""






   warnings.warn(
       """`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."""						,		_UpperCAmelCase						,		)
   return self.image_processor_class



  @property
  def 							SCREAMING_SNAKE_CASE__			(						self    :	int ):






   """simple docstring"""






   warnings.warn(
       """`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."""						,		_UpperCAmelCase						,		)
   return self.image_processor






'''simple docstring'''




import os

from apache_beam.io.filesystems import FileSystems
from apache_beam.pipeline import Pipeline

from .logging import get_logger


UpperCAmelCase_       				=      2 << 2_0  # 2mb
UpperCAmelCase_       				=      get_logger(__name__)

class 						lowerCAmelCase_   ( lowerCamelCase_   ):







  '''simple docstring'''







  def 							SCREAMING_SNAKE_CASE__			(						self    :	Any ):






   """simple docstring"""






   UpperCAmelCase__										=    self._options.get_all_options().get("""runner""" )
   return runner in [None, "DirectRunner", "PortableRunner"]

def    _UpperCamelCase      (				SCREAMING_SNAKE_CASE__			:      Any       ,						SCREAMING_SNAKE_CASE__			:      List[Any]       ,						SCREAMING_SNAKE_CASE__			:      Any=False       ):
 '''simple docstring'''





 UpperCAmelCase__										=    FileSystems
 if fs.exists(SCREAMING_SNAKE_CASE__       ):
  if force_upload:
   logger.info(F'''Remote path already exist: {remote_file_path}. Overwriting it as force_upload=True.'''       )
  else:
   logger.info(F'''Remote path already exist: {remote_file_path}. Skipping it as force_upload=False.'''       )
   return
 with fs.create(SCREAMING_SNAKE_CASE__       ) as remote_file:
  with open(SCREAMING_SNAKE_CASE__       ,						"""rb"""       ) as local_file:
   UpperCAmelCase__										=    local_file.read(SCREAMING_SNAKE_CASE__       )
   while chunk:
    remote_file.write(SCREAMING_SNAKE_CASE__       )
    UpperCAmelCase__										=    local_file.read(SCREAMING_SNAKE_CASE__       )







def    _UpperCamelCase      (				SCREAMING_SNAKE_CASE__			:      Dict       ,						SCREAMING_SNAKE_CASE__			:      Any       ,						SCREAMING_SNAKE_CASE__			:      Dict=False       ):
 '''simple docstring'''





 UpperCAmelCase__										=    FileSystems
 if os.path.exists(SCREAMING_SNAKE_CASE__       ):
  if force_download:
   logger.info(F'''Local path already exist: {remote_file_path}. Overwriting it as force_upload=True.'''       )
  else:
   logger.info(F'''Local path already exist: {remote_file_path}. Skipping it as force_upload=False.'''       )
   return
 with fs.open(SCREAMING_SNAKE_CASE__       ) as remote_file:
  with open(SCREAMING_SNAKE_CASE__       ,						"""wb"""       ) as local_file:
   UpperCAmelCase__										=    remote_file.read(SCREAMING_SNAKE_CASE__       )
   while chunk:
    local_file.write(SCREAMING_SNAKE_CASE__       )
    UpperCAmelCase__										=    remote_file.read(SCREAMING_SNAKE_CASE__       )
