§
    ‚Štj#  ã                   óÌ   — 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dS )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<   dS )Ú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__© ó    úp/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/transformers/models/chameleon/processing_chameleon.pyr   r      s*   € € € € € € ðð ð !%Ð$Ð$Ñ$Ð$Ð$r   r   F)Útotalc                   ó0   — e Zd ZU eed<   ddddœddidœZdS )Ú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   *   sI   € € € € € € Ø$Ð$Ð$Ñ$ð Ø*/Ø(-ð
ð 
ð ˜dð
ð	ð 	€I€I€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>Úimage_seq_lengthÚimage_tokenc                 ó  •— t          ¦   «                              ||¦  «         || _        t          |d¦  «        r|j        n|| _        |                     | j        ¦  «        | _        t          |d¦  «        r|j        nd| _        t          |d¦  «        r|j	        nd| _
        |                     | j        ¦  «        | _        |                     | j        ¦  «        | _        |                     | j
        ¦  «        | _        dS )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Ô4Ð4à 0ˆÔÝ4;¸IÀ}Ñ4UÔ4UÐf˜9Ô0Ð0Ð[fˆÔØ'×=Ò=¸dÔ>NÑOÔOˆÔå#*¨9°kÑ#BÔ#BÐWˆIÔÐÈð 	Ôõ 7>¸iÈÑ6UÔ6UÐc˜yÔ2Ð2Ð[cˆÔØ'×=Ò=¸dÔ>NÑOÔOˆÔØ$-×$CÒ$CÀDÔDZÑ$[Ô$[ˆÔ!Ø"+×"AÒ"AÀ$ÔBVÑ"WÔ"WˆÔÐÐr   Úreturnc                 ó*   — | j         | j        | j        gS ©N)r0   r3   r4   )r5   s    r   Úimage_token_idsz"ChameleonProcessor.image_token_idsP   s   € àÔ# TÔ%>ÀÔ@WÐXÐXr   NÚimagesÚtextÚkwargsc                 óŽ   •‡ — t          |t          ¦  «        r|g}ˆ fd„|D ¦   «         } t          ¦   «         j        d||dœ|¤Ž}|S )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`.
        c                 ó0   •— g | ]}|› ‰j         j        › �‘ŒS r   )r7   Ú	sep_token)Ú.0Úsampler5   s     €r   ú
<listcomp>z/ChameleonProcessor.__call__.<locals>.<listcomp>i   s)   ø€ ÐIÐIÐI¸&�6Ð5˜4œ>Ô3Ð5Ð5ÐIÐIÐIr   )r=   r>   r   )Ú
isinstanceÚstrr,   Ú__call__)r5   r=   r>   r?   Úmodel_inputsr8   s   `    €r   rH   zChameleonProcessor.__call__T   sd   øø€ õ" �d�CÑ Ô ð 	Ø�6ˆDð JÐIÐIÐIÀDÐIÑIÔIˆØ'•u‘w”wÔ'ÐK¨v¸DÐKÐKÀFÐKÐKˆØÐr   Úimage_inputsÚ	image_idxc                 óD   — | j         | j        | j        z  z   | j        z   }|S r;   )r1   r(   r'   r2   )r5   rJ   rK   Úone_img_tokenss       r   Úreplace_image_tokenz&ChameleonProcessor.replace_image_tokenm   s)   € ØÔ/°4Ô3CÀdÔF[Ñ3[Ñ\Ð_cÔ_sÑsˆØÐr   c                 ó®   — i }|�F| j         dz   gt          |¦  «        z  }dgt          |¦  «        z  }|                     ||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.
        Né   é   )Únum_image_tokensÚnum_image_patchesr   )r'   ÚlenÚupdater   )r5   Úimage_sizesr?   Úvision_datarR   rS   s         r   Ú_get_num_multimodal_tokensz-ChameleonProcessor._get_num_multimodal_tokensq   st   € ð ˆØÐ"à $Ô 5¸Ñ 9Ð:½SÀÑ=MÔ=MÑMÐØ!" ¥c¨+Ñ&6Ô&6Ñ 6Ðà×ÒÐ4DÐ[lÐmÐmÑnÔnÐnåÐ,Ð, Ð,Ð,Ð,r   )r%   r&   )NNr;   )r   r   r   r   Úvalid_processor_kwargsÚintrG   r-   ÚpropertyÚlistr<   r   r   r   r
   r	   r   rH   ÚdictrN   rX   Ú__classcell__)r8   s   @r   r$   r$   8   sU  ø€ € € € € à5ÐðXð XÀSð XÐ^að Xð Xð Xð Xð Xð Xð( ðY  c¤ð Yð Yð Yñ „Xð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>re      sX  ððð ð 5Ð 4Ð 4Ð 4Ð 4Ð 4Ø %Ð %Ð %Ð %Ð %Ð %ðð ð ð ð ð ð ð ð ð ð ð ð ð ð DÐ CÐ CÐ CÐ CÐ CÐ CÐ CØ #Ð #Ð #Ð #Ð #Ð #ð%ð %ð %ð %ð %˜*¨Eð %ñ %ô %ð %ðð ð ð ð Ð/°uð ñ ô ð ð ðM-ð M-ð M-ð M-ð M-˜ñ M-ô M-ñ „ðM-ð`  Ð
 €€€r   