Ë
    S^(hª  ã                   óD   — d Z ddlZddlmZ ddlmZ  G d„ de«      ZdgZy)z(
Image/Text processor class for CLIPSeg
é    Né   )ÚProcessorMixin)ÚBatchEncodingc                   óh   ‡ — e Zd ZdZddgZdZdZdˆ fd„	Zdd„Zd„ Z	d	„ Z
ed
„ «       Zed„ «       Zˆ xZS )ÚCLIPSegProcessora.  
    Constructs a CLIPSeg processor which wraps a CLIPSeg image processor and a CLIP tokenizer into a single processor.

    [`CLIPSegProcessor`] offers all the functionalities of [`ViTImageProcessor`] and [`CLIPTokenizerFast`]. See the
    [`~CLIPSegProcessor.__call__`] and [`~CLIPSegProcessor.decode`] for more information.

    Args:
        image_processor ([`ViTImageProcessor`], *optional*):
            The image processor is a required input.
        tokenizer ([`CLIPTokenizerFast`], *optional*):
            The tokenizer is a required input.
    Úimage_processorÚ	tokenizer)ÚViTImageProcessorÚViTImageProcessorFast)ÚCLIPTokenizerÚCLIPTokenizerFastc                 óÈ   •— d }d|v r+t        j                  dt        «       |j                  d«      }|�|n|}|€t	        d«      ‚|€t	        d«      ‚t
        ‰| �  ||«       y )NÚfeature_extractorzhThe `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor` instead.z)You need to specify an `image_processor`.z"You need to specify a `tokenizer`.)ÚwarningsÚwarnÚFutureWarningÚpopÚ
ValueErrorÚsuperÚ__init__)Úselfr   r	   Úkwargsr   Ú	__class__s        €úl/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/clipseg/processing_clipseg.pyr   zCLIPSegProcessor.__init__+   sw   ø€ Ø ÐØ &Ñ(Ü�M‰Mðäôð
 !'§
¡
Ð+>Ó ?Ðà-<Ð-H™/ÐN_ˆØÐ"ÜÐHÓIÐIØÐÜÐAÓBÐBä‰Ñ˜¨)Õ4ó    c                 óŒ  — |€|€|€t        d«      ‚|�|�t        d«      ‚|� | j                  |fd|i|¤Ž}|� | j                  |fd|i|¤Ž}|� | j                  |fd|i|¤Ž}|�|�j                  j                  dœ}|S |�|�j                  d<   |S |�S |�dj                  i}|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 CLIPTokenizerFast's [`~CLIPTokenizerFast.__call__`] if `text` is not `None` to encode
        the text. To prepare the image(s), this method forwards the `images` and `kwrags` arguments to
        ViTImageProcessor's [`~ViTImageProcessor.__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.
            visual_prompt (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `List[PIL.Image.Image]`, `List[np.ndarray]`, `List[torch.Tensor]`):
                The visual prompt image or batch of images to be prepared. Each visual prompt image can be a PIL image,
                NumPy array or PyTorch tensor. In case of a NumPy array/PyTorch tensor, each image should be of shape
                (C, H, W), where C is a number of channels, H and W are image height and width.

            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`.
        z9You have to specify either text, visual prompt or images.zMYou have to specify exactly one type of prompt. Either text or visual prompt.Úreturn_tensors)Úpixel_valuesÚconditional_pixel_valuesr   r   )ÚdataÚtensor_type© )r   r	   r   r   r   Údict)	r   ÚtextÚimagesÚvisual_promptr   r   ÚencodingÚprompt_featuresÚimage_featuress	            r   Ú__call__zCLIPSegProcessor.__call__=   s'  € ðL ˆ<˜MÐ1°f°nÜÐXÓYÐYàÐ Ð 9ÜÐlÓmÐmàÐØ%�t—~‘~ dÑT¸>ÐTÈVÑTˆHàÐ$Ø2˜d×2Ñ2°=ÑjÐQ_ÐjÐciÑjˆOàÐØ1˜T×1Ñ1°&ÑbÈÐbÐ[aÑbˆNàÐ$¨Ð);à .× ;Ñ ;Ø,;×,HÑ,HñˆHð ˆOØÐ &Ð"4Ø'5×'BÑ'BˆH�^Ñ$ØˆOØÐØˆOØÐ&à*¨O×,HÑ,HðˆHð ˆOä ¤dÑ&<¨^Ñ&<È.ÔYÐYr   c                 ó:   —  | j                   j                  |i |¤ŽS )zÁ
        This method forwards all its arguments to CLIPTokenizerFast's [`~PreTrainedTokenizer.batch_decode`]. Please
        refer to the docstring of this method for more information.
        )r	   Úbatch_decode©r   Úargsr   s      r   r,   zCLIPSegProcessor.batch_decode…   s    € ð
 +ˆt�~‰~×*Ñ*¨DÐ;°FÑ;Ð;r   c                 ó:   —  | j                   j                  |i |¤ŽS )z»
        This method forwards all its arguments to CLIPTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
        the docstring of this method for more information.
        )r	   Údecoder-   s      r   r0   zCLIPSegProcessor.decodeŒ   s    € ð
 %ˆt�~‰~×$Ñ$ dÐ5¨fÑ5Ð5r   c                 óN   — t        j                  dt        «       | j                  S )Nzg`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.)r   r   r   Úimage_processor_class©r   s    r   Úfeature_extractor_classz(CLIPSegProcessor.feature_extractor_class“   s"   € ä�‰ØuÜô	
ð ×)Ñ)Ð)r   c                 óN   — t        j                  dt        «       | j                  S )Nz[`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.)r   r   r   r   r3   s    r   r   z"CLIPSegProcessor.feature_extractor›   s"   € ä�‰ØiÜô	
ð ×#Ñ#Ð#r   )NN)NNNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
attributesr2   Útokenizer_classr   r*   r,   r0   Úpropertyr4   r   Ú__classcell__)r   s   @r   r   r      s^   ø„ ñð $ [Ð1€JØJÐØ<€Oõ5ó$FZòP<ò6ð ñ*ó ð*ð ñ$ó ô$r   r   )r9   r   Úprocessing_utilsr   Útokenization_utils_baser   r   Ú__all__r"   r   r   ú<module>rA      s.   ðñó å .Ý 4ôH$�~ô H$ðV Ð
�r   