Ë
    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
mZmZmZ ddlmZmZ  G d„ d	e
d
¬«      Z G d„ ded
¬«      Z G d„ de«      ZdgZy)z)
Image/Text processor class for SigLIP2.
é    )ÚListÚOptionalÚUnioné   )ÚBatchFeature)Ú
ImageInput)ÚImagesKwargsÚProcessingKwargsÚProcessorMixinÚUnpack)ÚPreTokenizedInputÚ	TextInputc                   ó.   — e Zd ZU ee   ed<   ee   ed<   y)ÚSiglip2ImagesKwargsÚmax_num_patchesÚ
patch_sizeN)Ú__name__Ú
__module__Ú__qualname__r   ÚintÚ__annotations__© ó    úl/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/siglip2/processing_siglip2.pyr   r      s   … Ø˜c‘]Ó"Ø˜‘Ôr   r   F)Útotalc                   ó0   — e Zd ZU eed<   ddddœdddœd	œZy
)ÚSiglip2ProcessorKwargsÚimages_kwargsÚ
max_lengthTé@   )ÚpaddingÚ
truncationr   é   é   )r   r   )Útext_kwargsr   N)r   r   r   r   r   Ú	_defaultsr   r   r   r   r       s,   … Ø&Ó&ð $ØØñ
ð  #Øñ
ñ
�Ir   r   c                   óº   ‡ — e Zd ZdZddgZdZdZˆ fd„Z	 	 	 	 ddee	e
ee
   eee
      f      dee	ed	ee   ed	   f      d
ee   defd„Zd„ Zd„ Zed„ «       Zˆ xZS )ÚSiglip2Processora!  
    Constructs a Siglip2 processor which wraps a Siglip2 image processor and a Gemma tokenizer into a single processor.

    [`Siglip2Processor`] offers all the functionalities of [`Siglip2ImageProcessor`] and [`GemmaTokenizerFast`]. See the
    [`~Siglip2Processor.__call__`] and [`~Siglip2Processor.decode`] for more information.

    Args:
        image_processor ([`Siglip2ImageProcessor`]):
            The image processor is a required input.
        tokenizer ([`GemmaTokenizerFast`]):
            The tokenizer is a required input.
    Úimage_processorÚ	tokenizerÚAutoImageProcessorÚAutoTokenizerc                 ó&   •— t         ‰| �  ||«       y ©N)ÚsuperÚ__init__)Úselfr)   r*   Ú	__class__s      €r   r0   zSiglip2Processor.__init__C   s   ø€ Ü‰Ñ˜¨)Õ4r   ÚimagesÚtextr   ÚkwargsÚreturnc                 óL  —  | j                   t        fd| j                  j                  i|¤Ž}|€|€t	        d«      ‚|� | j                  |fi |d   ¤Ž}|� | j
                  |fi |d   ¤Ž}|�|�j                  «       |S |�S |d   d   }	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 GemmaTokenizerFast's [`~GemmaTokenizerFast.__call__`] if `text` is not `None` to encode
        the text. To prepare the image(s), this method forwards the `images` argument to
        Siglip2ImageProcessor's [`~Siglip2ImageProcessor.__call__`] if `images` is not `None`. Please refer to the docstring
        of the above two methods for more information.

        Args:
            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.
            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).
            padding (`bool`, `str` or [`~utils.PaddingStrategy`], *optional*, defaults to `max_length`):
                Select a strategy to pad the returned sequences (according to the model's padding side and padding
                index) among:
                - `'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.
                - `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
                  sequence if provided).
                - `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of different
                  lengths).
            max_length (`int`, *optional*, defaults to 64):
                Maximum length of the returned list and optionally padding length (see above).
            truncation (`bool`, *optional*, defaults to `True`):
                Activates truncation to cut input sequences longer than `max_length` to `max_length`.
            return_tensors (`str` or [`~utils.TensorType`], *optional*, defaults to `'pt'`):
                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`.
            - **pixel_attention_mask** -- Attention mask for the pixel values. Returned when `images` is not `None`.
            - **spatial_shapes** -- The number of horizontal and vertical patches per image.
              Returned when `images` is not `None`.
        Útokenizer_init_kwargsz?You have to specify either text or images. Both cannot be none.r%   r   Úcommon_kwargsÚreturn_tensors)ÚdataÚtensor_typer   )	Ú_merge_kwargsr   r*   Úinit_kwargsÚ
ValueErrorr)   Úupdater   Údict)
r1   r3   r4   ÚaudioÚvideosr5   Úoutput_kwargsÚencodingÚimage_featuresr:   s
             r   Ú__call__zSiglip2Processor.__call__F   sÛ   € ðp +˜×*Ñ*Ü"ñ
à"&§.¡.×"<Ñ"<ð
ð ñ
ˆð ˆ<˜F˜NÜÐ^Ó_Ð_àÐØ%�t—~‘~ dÑK¨m¸MÑ.JÑKˆHàÐØ1˜T×1Ñ1°&Ñ[¸MÈ/Ñ<ZÑ[ˆNàÐ Ð 2Ø�O‰O˜NÔ+ØˆOØÐØˆOà*¨?Ñ;Ð<LÑMˆNÜ¤TÑ%;¨NÑ%;ÈÔXÐXr   c                 ó:   —  | j                   j                  |i |¤ŽS )zº
        This method forwards all its arguments to Siglip2Tokenizer's [`~PreTrainedTokenizer.decode`]. Please refer to
        the docstring of this method for more information.
        )r*   Údecode©r1   Úargsr5   s      r   rI   zSiglip2Processor.decode–   s    € ð
 %ˆt�~‰~×$Ñ$ dÐ5¨fÑ5Ð5r   c                 ó:   —  | j                   j                  |i |¤ŽS )zÀ
        This method forwards all its arguments to Siglip2Tokenizer's [`~PreTrainedTokenizer.batch_decode`]. Please
        refer to the docstring of this method for more information.
        )r*   Úbatch_decoderJ   s      r   rM   zSiglip2Processor.batch_decode�   s    € ð
 +ˆt�~‰~×*Ñ*¨DÐ;°FÑ;Ð;r   c                 óœ   — | j                   j                  }| j                  j                  }t        t        j                  ||z   «      «      S r.   )r*   Úmodel_input_namesr)   ÚlistrA   Úfromkeys)r1   Útokenizer_input_namesÚimage_processor_input_namess      r   rO   z"Siglip2Processor.model_input_names¤   s?   € à $§¡× @Ñ @ÐØ&*×&:Ñ&:×&LÑ&LÐ#Ü”D—M‘MÐ"7Ð:UÑ"UÓVÓWÐWr   )NNNN)r   r   r   Ú__doc__Ú
attributesÚimage_processor_classÚtokenizer_classr0   r   r   r   r   r   r   r   r   rG   rI   rM   ÚpropertyrO   Ú__classcell__)r2   s   @r   r(   r(   0   sÎ   ø„ ñð $ [Ð1€Jà0ÐØ%€Oô5ð
 Y]ØlpØØñNYà˜˜z¨4°
Ñ+;¸TÀ$ÀzÑBRÑ=SÐSÑTÑUðNYð �u˜YÐ(;¸TÀ)¹_ÈdÐSfÑNgÐgÑhÑiðNYð Ð/Ñ0ðNYð 
óNYò`6ò<ð ñXó ôXr   r(   N)rT   Útypingr   r   r   Úfeature_extraction_utilsr   Úimage_utilsr   Úprocessing_utilsr	   r
   r   r   Útokenization_utils_baser   r   r   r   r(   Ú__all__r   r   r   ú<module>r`      sY   ðñ÷ )Ñ (å 4Ý %ß VÓ Vß Cô˜,¨eõ ô
Ð-°Uõ ô xX�~ô xXðv Ð
�r   