o
    wi                     @   s~   d Z ddlmZ ddlmZ ddlmZmZmZ ddl	m
Z
mZmZ ddlmZ G dd	 d	ed
dZG dd deZdgZdS )z(
Image/Text processor class for AltCLIP
    )Union   )
ImageInput)ProcessingKwargsProcessorMixinUnpack)BatchEncodingPreTokenizedInput	TextInput)deprecate_kwargc                   @   s   e Zd Zi ZdS )AltClipProcessorKwargsN)__name__
__module____qualname__	_defaults r   r   k/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/transformers/models/altclip/processing_altclip.pyr      s    r   F)totalc                
       s   e Zd ZdZddgZdZdZeddddd fd
d	Z								dde	de
eeee ee f dee defddZdd Zdd Zedd Z  ZS )AltCLIPProcessoraD  
    Constructs a AltCLIP processor which wraps a CLIP image processor and a XLM-Roberta tokenizer into a single
    processor.

    [`AltCLIPProcessor`] offers all the functionalities of [`CLIPImageProcessor`] and [`XLMRobertaTokenizerFast`]. See
    the [`~AltCLIPProcessor.__call__`] and [`~AltCLIPProcessor.decode`] for more information.

    Args:
        image_processor ([`CLIPImageProcessor`], *optional*):
            The image processor is a required input.
        tokenizer ([`XLMRobertaTokenizerFast`], *optional*):
            The tokenizer is a required input.
    image_processor	tokenizer)CLIPImageProcessorCLIPImageProcessorFast)XLMRobertaTokenizerXLMRobertaTokenizerFastfeature_extractorz5.0.0)old_nameversionnew_nameNc                    s2   |d u rt d|d u rt dt || d S )Nz)You need to specify an `image_processor`.z"You need to specify a `tokenizer`.)
ValueErrorsuper__init__)selfr   r   	__class__r   r   r!   2   s
   zAltCLIPProcessor.__init__imagestextkwargsreturnc           
      K   s   |du r|du rt d|du r|du rt d| jtfd| jji|}|dur4| j|fi |d }|durC| j|fi |d }d|d v rQ|d dd}	|dur`|dur`|j|d< |S |durf|S tt	d
i ||	d	S )a  
        Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the `text`
        and `kwargs` arguments to XLMRobertaTokenizerFast's [`~XLMRobertaTokenizerFast.__call__`] if `text` is not
        `None` to encode the text. To prepare the image(s), this method forwards the `images` and `kwrags` arguments to
        CLIPImageProcessor's [`~CLIPImageProcessor.__call__`] if `images` is not `None`. Please refer to the docstring
        of the above two methods for more information.

        Args:

            images (`ImageInput`):
                The image or batch of images to be prepared. Each image can be a PIL image, NumPy array or PyTorch
                tensor. Both channels-first and channels-last formats are supported.
            text (`TextInput`, `PreTokenizedInput`, `list[TextInput]`, `list[PreTokenizedInput]`):
                The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings
                (pretokenized string). If the sequences are provided as list of strings (pretokenized), you must set
                `is_split_into_words=True` (to lift the ambiguity with a batch of sequences).
            return_tensors (`str` or [`~utils.TensorType`], *optional*):
                If set, will return tensors of a particular framework. Acceptable values are:
                    - `'tf'`: Return TensorFlow `tf.constant` objects.
                    - `'pt'`: Return PyTorch `torch.Tensor` objects.
                    - `'np'`: Return NumPy `np.ndarray` objects.
                    - `'jax'`: Return JAX `jnp.ndarray` objects.
        Returns:
            [`BatchEncoding`]: A [`BatchEncoding`] with the following fields:

            - **input_ids** -- List of token ids to be fed to a model. Returned when `text` is not `None`.
            - **attention_mask** -- List of indices specifying which tokens should be attended to by the model (when
              `return_attention_mask=True` or if *"attention_mask"* is in `self.model_input_names` and if `text` is not
              `None`).
            - **pixel_values** -- Pixel values to be fed to a model. Returned when `images` is not `None`.
        Nz'You must specify either text or images.tokenizer_init_kwargstext_kwargsimages_kwargsreturn_tensorscommon_kwargspixel_values)datatensor_typer   )
r   _merge_kwargsr   r   init_kwargsr   popr.   r   dict)
r"   r%   r&   audiovideosr'   output_kwargsencodingimage_featuresr,   r   r   r   __call__;   s.   (
zAltCLIPProcessor.__call__c                 O      | j j|i |S )z
        This method forwards all its arguments to XLMRobertaTokenizerFast's [`~PreTrainedTokenizer.batch_decode`].
        Please refer to the docstring of this method for more information.
        )r   batch_decoder"   argsr'   r   r   r   r<         zAltCLIPProcessor.batch_decodec                 O   r;   )z
        This method forwards all its arguments to XLMRobertaTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please
        refer to the docstring of this method for more information.
        )r   decoder=   r   r   r   r@      r?   zAltCLIPProcessor.decodec                 C   s"   | j j}| jj}tt|| S )N)r   model_input_namesr   listr4   fromkeys)r"   tokenizer_input_namesimage_processor_input_namesr   r   r   rA      s   z"AltCLIPProcessor.model_input_names)NN)NNNN)r   r   r   __doc__
attributesimage_processor_classtokenizer_classr   r!   r   r   r
   r	   rB   r   r   r   r:   r<   r@   propertyrA   __classcell__r   r   r#   r   r      s0    

Dr   N)rF   typingr   image_utilsr   processing_utilsr   r   r   tokenization_utils_baser   r	   r
   utils.deprecationr   r   r   __all__r   r   r   r   <module>   s   
u