
    fTh                     D    S r SSKrSSKJr  SSKJr   " S S\5      rS/rg)z(
Image/Text processor class for CLIPSeg
    N   )ProcessorMixin)BatchEncodingc                   v   ^  \ rS rSrSrSS/rSrSrSU 4S jjrSS jr	S	 r
S
 r\S 5       r\S 5       rSrU =r$ )CLIPSegProcessor   a
  
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                    > S nSU;   a,  [         R                  " S[        5        UR                  S5      nUb  UOUnUc  [	        S5      eUc  [	        S5      e[
        TU ]  X5        g )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        f/var/www/auris/envauris/lib/python3.13/site-packages/transformers/models/clipseg/processing_clipseg.pyr   CLIPSegProcessor.__init__+   su     &(MM
 !'

+> ?-<-H/N_"HIIABB4    c                    Uc  Uc  Uc  [        S5      eUb  Ub  [        S5      eUb  U R                  " U4SU0UD6nUb  U R                  " U4SU0UD6nUb  U R                  " U4SU0UD6nUb  Ub  WR                  WR                  S.nU$ Ub  Ub  WR                  WS'   U$ Ub  W$ Ub  SWR                  0nU$ [	        [        S0 WD6US9$ )	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__CLIPSegProcessor.__call__=   s!   L <M1fnXYY 9lmm~~dT>TVTH$"22=jQ_jcijO!11&bb[abN$); . ; ;,;,H,HH O&"4'5'B'BH^$OO&*O,H,HH O d&<^&<.YYr   c                 :    U R                   R                  " U0 UD6$ )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/   CLIPSegProcessor.batch_decode   s    
 ~~**D;F;;r   c                 :    U R                   R                  " U0 UD6$ )z
This method forwards all its arguments to CLIPTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
the docstring of this method for more information.
)r
   decoder0   s      r   r4   CLIPSegProcessor.decode   s    
 ~~$$d5f55r   c                 P    [         R                  " S[        5        U R                  $ )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_class(CLIPSegProcessor.feature_extractor_class   s"    u	
 )))r   c                 P    [         R                  " S[        5        U R                  $ )Nz[`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.)r   r   r   r	   r8   s    r   r   "CLIPSegProcessor.feature_extractor   s"    i	
 ###r   r$   )NN)NNNN)__name__
__module____qualname____firstlineno____doc__
attributesr7   tokenizer_classr   r,   r/   r4   propertyr9   r   __static_attributes____classcell__)r   s   @r   r   r      s^     $[1JJ<O5$FZP<6 * * $ $r   r   )rA   r   processing_utilsr   tokenization_utils_baser   r   __all__r$   r   r   <module>rJ      s.     . 4H$~ H$V 
r   