Ë
    T^(h`  ã                   ó<   — d Z ddlmZ ddlmZ  G d„ de«      ZdgZy)z
Processor class for TVP.
é   )ÚProcessorMixin)ÚBatchEncodingc                   ó^   ‡ — 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
d
„ Zed„ «       Zˆ xZS )ÚTvpProcessora  
    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                 óZ   •— |€t        d«      ‚|€t        d«      ‚t        ‰| �	  ||«       y )Nz)You need to specify an `image_processor`.z"You need to specify a `tokenizer`.)Ú
ValueErrorÚsuperÚ__init__)Úselfr   r   ÚkwargsÚ	__class__s       €úd/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/tvp/processing_tvp.pyr   zTvpProcessor.__init__)   s6   ø€ ØÐ"ÜÐHÓIÐIØÐÜÐAÓBÐBä‰Ñ˜¨)Õ4ó    c           
      ó   — |j                  dd«      }|€|€t        d«      ‚i }|�5 | j                  j                  |fdd|d|ddœ|¤Ž}|j	                  |«       |�& | j
                  |fd|i|¤Ž}|j	                  |«       t        ||¬	«      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 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__zTvpProcessor.__call__1   sº   € ðJ !Ÿ*™*Ð%6¸Ó=ˆàˆ<˜F˜NÜÐ^Ó_Ð_àˆØÐØ<˜DŸN™N×<Ñ<Øð	àØ$Ø*Ø"&Ø-Ø&+ñ	ð ñ	ˆMð �O‰O˜MÔ*àÐØ1˜T×1Ñ1°&ÑbÈÐbÐ[aÑbˆNØ�O‰O˜NÔ+ä (¸ÔGÐGr   c                 ó:   —  | j                   j                  |i |¤ŽS )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)   zTvpProcessor.batch_decodeo   s    € ð
 +ˆt�~‰~×*Ñ*¨DÐ;°FÑ;Ð;r   c                 ó:   —  | j                   j                  |i |¤ŽS )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   r-   zTvpProcessor.decodev   s    € ð
 %ˆt�~‰~×$Ñ$ dÐ5¨fÑ5Ð5r   c                 ó–   — t        |j                  «       d   d   |z  d«      t        |j                  «       d   d   |z  d«      }}||fS )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_groundingz)TvpProcessor.post_process_video_grounding}   sU   € ô" �&—-‘-“/ !Ñ$ QÑ'¨/Ñ9¸1Ó=Ü�&—-‘-“/ !Ñ$ QÑ'¨/Ñ9¸1Ó=ð ˆð
 �cˆzÐr   c                 óœ   — | j                   j                  }| j                  j                  }t        t        j                  ||z   «      «      S )N)r   Úmodel_input_namesr   ÚlistÚdictÚfromkeys)r   Útokenizer_input_namesÚimage_processor_input_namess      r   r9   zTvpProcessor.model_input_names”   sA   € ð !%§¡× @Ñ @ÐØ&*×&:Ñ&:×&LÑ&LÐ#Ü”D—M‘MÐ"7Ð:UÑ"UÓVÓWÐWr   )NN)NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
attributesÚimage_processor_classÚtokenizer_classr   r'   r)   r-   r7   Úpropertyr9   Ú__classcell__)r   s   @r   r   r      sP   ø„ ñð $ [Ð1€JØ/ÐØ<€Oõ5ó<Hò|<ò6òð. ñXó ôXr   r   N)rB   Úprocessing_utilsr   Útokenization_utils_baser   r   Ú__all__© r   r   ú<module>rL      s-   ðñõ /Ý 4ôBX�>ô BXðJ Ð
�r   