
    fTh`                     <    S r SSKJr  SSKJr   " S S\5      rS/rg)z
Processor class for TVP.
   )ProcessorMixin)BatchEncodingc                   l   ^  \ 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 r\S 5       rSrU =r$ )TvpProcessor   a  
Constructs an TVP processor which wraps a TVP image processor and a Bert tokenizer into a single processor.

[`TvpProcessor`] offers all the functionalities of [`TvpImageProcessor`] and [`BertTokenizerFast`]. See the
[`~TvpProcessor.__call__`] and [`~TvpProcessor.decode`] for more information.

Args:
    image_processor ([`TvpImageProcessor`], *optional*):
        The image processor is a required input.
    tokenizer ([`BertTokenizerFast`], *optional*):
        The tokenizer is a required input.
image_processor	tokenizerTvpImageProcessor)BertTokenizerBertTokenizerFastc                 \   > Uc  [        S5      eUc  [        S5      e[        TU ]	  X5        g )Nz)You need to specify an `image_processor`.z"You need to specify a `tokenizer`.)
ValueErrorsuper__init__)selfr   r	   kwargs	__class__s       ^/var/www/auris/envauris/lib/python3.13/site-packages/transformers/models/tvp/processing_tvp.pyr   TvpProcessor.__init__)   s4    "HIIABB4    c           
          UR                  SS5      nUc  Uc  [        S5      e0 nUb5  U R                  R                  " U4SSUSUSS.UD6nUR	                  U5        Ub&  U R
                  " U4SU0UD6nUR	                  U5        [        XcS	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 BertTokenizerFast's [`~BertTokenizerFast.__call__`] if `text` is not `None` to encode
the text. To prepare the image(s), this method forwards the `videos` and `kwargs` arguments to
TvpImageProcessor's [`~TvpImageProcessor.__call__`] if `videos` 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).
    videos (`List[PIL.Image.Image]`, `List[np.ndarray]`, `List[torch.Tensor]`, `List[List[PIL.Image.Image]]`, `List[List[np.ndarray]]`,:
        `List[List[torch.Tensor]]`): The video or batch of videos to be prepared. Each video should be a list
        of frames, which can be either PIL images or NumPy arrays. In case of NumPy arrays/PyTorch tensors,
        each frame should be of shape (H, W, C), where H and W are frame height and width, and C is a number of
        channels.

    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 `videos` is not `None`.
max_text_lengthNz?You have to specify either text or videos. Both cannot be none.T
max_lengthF)
truncationpaddingr   pad_to_max_lengthreturn_tensorsreturn_token_type_idsr   )datatensor_type)popr   r	   batch_encode_plusupdater   r   )	r   textvideosr   r   r   encodingtextual_inputimage_featuress	            r   __call__TvpProcessor.__call__1   s    J !**%6=<FN^__ NN<<	$*"&-&+	 	M OOM*!11&bb[abNOON+(GGr   c                 :    U R                   R                  " U0 UD6$ )z
This method forwards all its arguments to BertTokenizerFast's [`~PreTrainedTokenizer.batch_decode`]. Please
refer to the docstring of this method for more information.
)r	   batch_decoder   argsr   s      r   r,   TvpProcessor.batch_decodeo   s    
 ~~**D;F;;r   c                 :    U R                   R                  " U0 UD6$ )z
This method forwards all its arguments to BertTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
the docstring of this method for more information.
)r	   decoder-   s      r   r1   TvpProcessor.decodev   s    
 ~~$$d5f55r   c                     [        UR                  5       S   S   U-  S5      [        UR                  5       S   S   U-  S5      pCX44$ )a.  
Compute the time of the video.

Args:
    logits (`torch.Tensor`):
        The logits output of TvpForVideoGrounding.
    video_durations (`float`):
        The video's duration.

Returns:
    start (`float`):
        The start time of the video.
    end (`float`):
        The end time of the video.
       )roundtolist)r   logitsvideo_durationsstartends        r   post_process_video_grounding)TvpProcessor.post_process_video_grounding}   sQ    " &--/!$Q'/91=&--/!$Q'/91= 
 zr   c                     U R                   R                  nU R                  R                  n[        [        R                  X-   5      5      $ )N)r	   model_input_namesr   listdictfromkeys)r   tokenizer_input_namesimage_processor_input_namess      r   r?   TvpProcessor.model_input_names   s>     !% @ @&*&:&:&L&L#DMM"7"UVWWr    )NN)NNN)__name__
__module____qualname____firstlineno____doc__
attributesimage_processor_classtokenizer_classr   r)   r,   r1   r<   propertyr?   __static_attributes____classcell__)r   s   @r   r   r      sP     $[1J/<O5<H|<6. X Xr   r   N)rK   processing_utilsr   tokenization_utils_baser   r   __all__rF   r   r   <module>rU      s-    / 4BX> BXJ 
r   