Ë
    T^(hµ  ã                   ó€   — d Z ddlmZmZmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZmZmZmZ ddlmZ  G d	„ d
e
«      Zd
gZy)z(
Image/Text processor class for SigLIP.
é    )ÚListÚOptionalÚUnioné   )ÚBatchFeature)Ú
ImageInput)ÚProcessorMixin)ÚPaddingStrategyÚPreTokenizedInputÚ	TextInputÚTruncationStrategy)Ú
TensorTypec                   óÜ   ‡ — e Zd ZdZddgZdZdZˆ fd„Zdddddej                  fd	e
eeee   ee   f   d
ede
eeef   de
eeef   dee   dee
eef      defd„Zd„ Zd„ Zed„ «       Zˆ xZS )ÚSiglipProcessora  
    Constructs a Siglip processor which wraps a Siglip image processor and a Siglip tokenizer into a single processor.

    [`SiglipProcessor`] offers all the functionalities of [`SiglipImageProcessor`] and [`SiglipTokenizer`]. See the
    [`~SiglipProcessor.__call__`] and [`~SiglipProcessor.decode`] for more information.

    Args:
        image_processor ([`SiglipImageProcessor`]):
            The image processor is a required input.
        tokenizer ([`SiglipTokenizer`]):
            The tokenizer is a required input.
    Úimage_processorÚ	tokenizer)ÚSiglipImageProcessorÚSiglipImageProcessorFastÚAutoTokenizerc                 ó&   •— t         ‰| �  ||«       y ©N)ÚsuperÚ__init__)Úselfr   r   Ú	__class__s      €új/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/siglip/processing_siglip.pyr   zSiglipProcessor.__init__.   s   ø€ Ü‰Ñ˜¨)Õ4ó    NFÚtextÚimagesÚpaddingÚ
truncationÚ
max_lengthÚreturn_tensorsÚreturnc                 óÜ   — |€|€t        d«      ‚|�| j                  |||||¬«      }|�| j                  ||¬«      }|�|�j                  «       |S |�S t	        t        di ¤Ž|¬«      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 SiglipTokenizer's [`~SiglipTokenizer.__call__`] if `text` is not `None` to encode
        the text. To prepare the image(s), this method forwards the `images` argument to
        SiglipImageProcessor's [`~SiglipImageProcessor.__call__`] if `images` is not `None`. Please refer to the docstring
        of the above two methods for more information.

        Args:
            text (`str`, `List[str]`, `List[List[str]]`):
                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).
            images (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `List[PIL.Image.Image]`, `List[np.ndarray]`, `List[torch.Tensor]`):
                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.
            padding (`bool`, `str` or [`~utils.PaddingStrategy`], *optional*, defaults to `False`):
                Select a strategy to pad the returned sequences (according to the model's padding side and padding
                index) among:
                - `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
                  sequence if provided).
                - `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the maximum
                  acceptable input length for the model if that argument is not provided.
                - `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of different
                  lengths).
            max_length (`int`, *optional*):
                Maximum length of the returned list and optionally padding length (see above).
            truncation (`bool`, *optional*):
                Activates truncation to cut input sequences longer than `max_length` to `max_length`.
            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:
            [`BatchFeature`]: A [`BatchFeature`] 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`.
        z?You have to specify either text or images. Both cannot be none.)r#   r    r!   r"   )r#   )ÚdataÚtensor_type© )Ú
ValueErrorr   r   Úupdater   Údict)	r   r   r   r    r!   r"   r#   ÚencodingÚimage_featuress	            r   Ú__call__zSiglipProcessor.__call__1   s™   € ðn ˆ<˜F˜NÜÐ^Ó_Ð_àÐØ—~‘~Ø ^¸WÐQ[Ðhrð &ó ˆHð ÐØ!×1Ñ1°&ÈÐ1ÓXˆNàÐ Ð 2Ø�O‰O˜NÔ+ØˆOØÐØˆOä¤TÑ%;¨NÑ%;ÈÔXÐXr   c                 ó:   —  | j                   j                  |i |¤ŽS )z¹
        This method forwards all its arguments to SiglipTokenizer's [`~PreTrainedTokenizer.decode`]. Please refer to
        the docstring of this method for more information.
        )r   Údecode©r   ÚargsÚkwargss      r   r0   zSiglipProcessor.decode{   s    € ð
 %ˆt�~‰~×$Ñ$ dÐ5¨fÑ5Ð5r   c                 ó:   —  | j                   j                  |i |¤ŽS )z¿
        This method forwards all its arguments to SiglipTokenizer's [`~PreTrainedTokenizer.batch_decode`]. Please
        refer to the docstring of this method for more information.
        )r   Úbatch_decoder1   s      r   r5   zSiglipProcessor.batch_decode‚   s    € ð
 +ˆt�~‰~×*Ñ*¨DÐ;°FÑ;Ð;r   c                 óœ   — | j                   j                  }| j                  j                  }t        t        j                  ||z   «      «      S r   )r   Úmodel_input_namesr   Úlistr+   Úfromkeys)r   Útokenizer_input_namesÚimage_processor_input_namess      r   r7   z!SiglipProcessor.model_input_names‰   sA   € ð !%§¡× @Ñ @ÐØ&*×&:Ñ&:×&LÑ&LÐ#Ü”D—M‘MÐ"7Ð:UÑ"UÓVÓWÐWr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
attributesÚimage_processor_classÚtokenizer_classr   r   ÚPYTORCHr   r   r   r   r   ÚboolÚstrr
   r   r   Úintr   r.   r0   r5   Úpropertyr7   Ú__classcell__)r   s   @r   r   r      sþ   ø„ ñð $ [Ð1€JØPÐØ%€Oô5ð
 _cØ!Ø5:Ø;?Ø$(Ø;E×;MÑ;MñHYà�IÐ0°$°y±/À4ÐHYÑCZÐZÑ[ðHYð ðHYð �t˜S /Ð1Ñ2ð	HYð
 ˜$ Ð%7Ð7Ñ8ðHYð ˜S‘MðHYð !  s¨J Ñ!7Ñ8ðHYð 
óHYòT6ò<ð ñXó ôXr   r   N)r?   Útypingr   r   r   Úfeature_extraction_utilsr   Úimage_utilsr   Úprocessing_utilsr	   Útokenization_utils_baser
   r   r   r   Úutilsr   r   Ú__all__r(   r   r   ú<module>rP      s?   ðñ÷ )Ñ (å 4Ý %Ý .ß hÓ hÝ ôrX�nô rXðj Ð
�r   