Ë
    ÛÓ^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À}Ô4U˜9×0Ò0Ð[fˆÔØ'×=Ñ=¸d×>NÑ>NÓOˆÔä#*¨9°kÔ#BˆI×ÒÈð 	Ôô 7>¸iÈÔ6U˜y×2Ò2Ð[cˆÔØ'×=Ñ=¸d×>NÑ>NÓOˆÔØ$-×$CÑ$CÀD×DZÑDZÓ$[ˆÔ!Ø"+×"AÑ"AÀ$×BVÑBVÓ"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   ø€ ô" �dœCÔ Ø�6ˆDð EIÖI¸&�6�(˜4Ÿ>™>×3Ñ3Ð4Ò5ÐIˆÐIÜ‘wÑ'ÐK¨v¸DÑKÀFÑ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   € Ø×/Ñ/°4×3CÑ3CÀd×F[Ñ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Ñ!ðð Ð+Ñ+¨d°9©oÑ=ÀÐEVÑ@WÑWÐZ^Ñ^ðð Ð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   