
    ^j#                         d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
 ddlmZmZ ddlmZ  G d de	d	
      Z G d ded	
      Ze G d de             ZdgZy)z 
Processor class for Chameleon.
   )BatchFeature)
ImageInput)MultiModalDataProcessingKwargsProcessorMixin
TextKwargsUnpack)PreTokenizedInput	TextInput)auto_docstringc                       e Zd ZU dZeed<   y)ChameleonTextKwargsa  
    return_for_text_completion (`bool`, *optional*, defaults to `False`):
        Whether the processed text is intended for text completion tasks. When `True`, the processor does not
        append the separator token (`sep_token`) to the end of the prompt, which is typically used for chat
        mode. When `False`, the separator token is appended for proper chat formatting.
    return_for_text_completionN)__name__
__module____qualname____doc__bool__annotations__     }/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/models/chameleon/processing_chameleon.pyr   r      s     !%$r   r   F)totalc                   .    e Zd ZU eed<   ddddddidZy)ChameleonProcessorKwargstext_kwargsF)paddingr   return_mm_token_type_idsreturn_tensorspt)r   common_kwargsN)r   r   r   r   r   	_defaultsr   r   r   r   r   *   s+    $$ */(-
 d
	Ir   r   c            
            e Zd ZeZddedef fdZede	e   fd       Z
e	 	 ddedz  deez  e	e   z  e	e   z  dz  d	ee   def fd
       ZdededefdZddZ xZS )ChameleonProcessorimage_seq_lengthimage_tokenc                    t         |   ||       || _        t        |d      r|j                  n|| _        |j                  | j                        | _        t        |d      r|j                  nd| _        t        |d      r|j                  nd| _
        |j                  | j                        | _        |j                  | j                        | _        |j                  | j                        | _        y)a  
        image_seq_length (`int`, *optional*, defaults to 1024):
            Sequence length of one image embedding.
        image_token (`str`, *optional*, defaults to `"<image>"`):
            The special token used to indicate image in the text.
        r&   	boi_tokenz<racm3:break>	eoi_tokenz<eoss>N)super__init__r%   hasattrr&   convert_tokens_to_idsimage_token_idr(   image_start_tokenr)   image_end_tokenimage_start_token_idimage_end_token_id)selfimage_processor	tokenizerr%   r&   	__class__s        r   r+   zChameleonProcessor.__init__<   s     	)4 04;I}4U900[f'==d>N>NO#*9k#BI 	 7>i6Uy22[c'==d>N>NO$-$C$CDDZDZ$[!"+"A"A$BVBV"Wr   returnc                 H    | j                   | j                  | j                  gS N)r.   r1   r2   )r3   s    r   image_token_idsz"ChameleonProcessor.image_token_idsP   s!    ##T%>%>@W@WXXr   Nimagestextkwargsc                     t        |t              r|g}|D cg c]  }| | j                  j                    }}t	        |   d||d|}|S c c}w )aA  
        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`.
        )r;   r<   r   )
isinstancestrr5   	sep_tokenr*   __call__)r3   r;   r<   r=   samplemodel_inputsr6   s         r   rB   zChameleonProcessor.__call__T   sf    " dC 6D EII&6(4>>3345IIw'KvDKFK Js   !Aimage_inputs	image_idxc                 l    | j                   | j                  | j                  z  z   | j                  z   }|S r9   )r/   r&   r%   r0   )r3   rE   rF   one_img_tokenss       r   replace_image_tokenz&ChameleonProcessor.replace_image_tokenm   s5    //43C3CdF[F[3[\_c_s_ssr   c                     i }|?| j                   dz   gt        |      z  }dgt        |      z  }|j                  ||d       t        di |S )a  
        Computes the number of placeholder tokens needed for multimodal inputs with the given sizes.

        Args:
            image_sizes (`list[list[int]]`, *optional*):
                The input sizes formatted as (height, width) per each image.

        Returns:
            `MultiModalData`: A `MultiModalData` object holding number of tokens per each of the provided
            input modalities, along with other useful data.
              )num_image_tokensnum_image_patchesr   )r%   lenupdater   )r3   image_sizesr=   vision_datarM   rN   s         r   _get_num_multimodal_tokensz-ChameleonProcessor._get_num_multimodal_tokensq   sb     " $ 5 5 9:S=MM!"c+&6 64D[lmn,,,r   )i   z<image>)NNr9   )r   r   r   r   valid_processor_kwargsintr@   r+   propertylistr:   r   r   r   r
   r	   r   rB   dictrI   rS   __classcell__)r6   s   @r   r$   r$   8   s    5XS X^a X( Yc Y Y  %)aeT! ++d9o=EV@WWZ^^ 12	
 
 0   -r   r$   N)r   feature_extraction_utilsr   image_utilsr   processing_utilsr   r   r   r   r	   tokenization_utils_baser
   r   utilsr   r   r   r$   __all__r   r   r   <module>r`      sk    5 %  D #%*E %/u  M- M- M-`  
 r   