Ë
    S^(h1!  ã                   ó°   — d Z ddlmZmZm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  G d„ d	ed
¬«      Z G d„ de
d
¬«      Z G d„ de«      ZdgZy)z 
Processor class for Chameleon.
é    )ÚListÚOptionalÚUnioné   )ÚBatchFeature)Ú
ImageInput)ÚProcessingKwargsÚProcessorMixinÚ
TextKwargsÚUnpackÚ!_validate_images_text_input_order)ÚPreTokenizedInputÚ	TextInputc                   ó   — e Zd ZU eed<   y)ÚChameleonTextKwargsÚreturn_for_text_completionN)Ú__name__Ú
__module__Ú__qualname__ÚboolÚ__annotations__© ó    úp/var/www/skyplay_api_hub/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idœZy)ÚChameleonProcessorKwargsÚtext_kwargsF)Úpaddingr   Ú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dZddgZdZddgZdZddede	fˆ fd„Z
	 	 	 	 dd	ee   d
eeeeee   ee   f      dee   defd„Zd„ Zd„ Zed„ «       Zˆ xZS )ÚChameleonProcessora/  
    Constructs a Chameleon processor which wraps a Chameleon image processor and a Chameleon tokenizer into a single
    processor.

    [`ChameleonProcessor`] offers all the functionalities of [`ChameleonImageProcessor`] and [`LlamaTokenizerFast`].
    See the [`~ChameleonProcessor.__call__`] and [`~ChameleonProcessor.decode`] for more information.

    Args:
        image_processor ([`ChameleonImageProcessor`]):
            The image processor is a required input.
        tokenizer ([`LlamaTokenizerFast`]):
            The tokenizer is a required input.
        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.
    Úimage_processorÚ	tokenizer)ÚLlamaTokenizerÚLlamaTokenizerFastÚimage_seq_lengthÚimage_tokenÚChameleonImageProcessorc                 óî   •— || _         t        |d«      r|j                  n|| _        t        |d«      r|j                  nd| _        t        |d«      r|j
                  nd| _        t        ‰| �!  ||«       y )Nr+   Ú	boi_tokenz<racm3:break>Ú	eoi_tokenz<eoss>)	r*   Úhasattrr+   r.   Úimage_start_tokenr/   Úimage_end_tokenÚsuperÚ__init__)Úselfr&   r'   r*   r+   Ú	__class__s        €r   r4   zChameleonProcessor.__init__D   sl   ø€ Ø 0ˆÔÜ4;¸IÀ}Ô4U˜9×0Ò0Ð[fˆÔä#*¨9°kÔ#BˆI×ÒÈð 	Ôô 7>¸iÈÔ6U˜y×2Ò2Ð[cˆÔä‰Ñ˜¨)Õ4r   ÚimagesÚtextÚkwargsÚreturnc                 óÜ  — t        ||«      \  }}t        |t        «      r|g}n.t        |t        «      st        |d   t        «      st	        d«      ‚|€|€t        d«      ‚ | j                  t        fd| j                  j                  i|¤Ž}|d   j                  dd«      }g }| j                  | j                  | j                  z  z   | j                  z   }	|D ]J  }
|
j                  | j                  |	«      }
|s|
| j                  j                   z  }
|j#                  |
«       ŒL  | j                  |fi |d   ¤Ž}|� | j$                  |fi |d   ¤Žd	   |d	<   t'        ||d
   d   ¬«      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 LlamaTokenizerFast's [`~LlamaTokenizerFast.__call__`] if `text` is not `None` to encode
        the text. To prepare the image(s), this method forwards the `images` and `kwrags` arguments to
        CLIPImageProcessor's [`~CLIPImageProcessor.__call__`] if `images` is not `None`. Please refer to the docstring
        of the above two methods for more information.

        Args:
            images (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `List[PIL.Image.Image]`, `List[np.ndarray]`, `List[torch.Tensor]`):
                The image or batch of images to be prepared. Each image can be a PIL image, NumPy array or PyTorch
                tensor. Both channels-first and channels-last formats are supported.
            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).
            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:
            [`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   zAInvalid input text. Please provide a string, or a list of stringsz&You must provide either text or imagesÚtokenizer_init_kwargsr   r   FÚimages_kwargsÚpixel_valuesr"   r    )ÚdataÚtensor_type)r   Ú
isinstanceÚstrÚlistÚ	TypeErrorÚ
ValueErrorÚ_merge_kwargsr   r'   Úinit_kwargsÚpopr1   r+   r*   r2   ÚreplaceÚ	sep_tokenÚappendr&   r   )r5   r7   r8   ÚaudioÚvideosr9   Úoutput_kwargsr   Úprompt_stringsÚone_img_tokensÚsampler?   s               r   Ú__call__zChameleonProcessor.__call__N   s‹  € ôR 9¸ÀÓF‰ˆ�Ü�dœCÔ Ø�6‰DÜ˜D¤$Ô'´
¸4À¹7ÄCÔ0HÜÐ_Ó`Ð`Øˆ<˜F˜NÜÐEÓFÐFà*˜×*Ñ*Ü$ñ
à"&§.¡.×"<Ñ"<ð
ð ñ
ˆð
 &3°=Ñ%A×%EÑ%EÐFbÐdiÓ%jÐ"ð ˆØ×/Ñ/°4×3CÑ3CÀd×F[ÑF[Ñ3[Ñ\Ð_c×_sÑ_sÑsˆØò 	*ˆFØ—^‘^ D×$4Ñ$4°nÓEˆFÙ-Ø˜$Ÿ.™.×2Ñ2Ñ2�Ø×!Ñ! &Õ)ð		*ð ˆt�~‰~˜nÑM°¸mÑ0LÑMˆàÐØ#7 4×#7Ñ#7¸Ñ#aÀ-ÐP_ÑB`Ñ#aÐbpÑ#qˆD�Ñ ä °=ÀÑ3QÐRbÑ3cÔdÐdr   c                 ó:   —  | j                   j                  |i |¤ŽS )zÂ
        This method forwards all its arguments to LlamaTokenizerFast's [`~PreTrainedTokenizer.batch_decode`]. Please
        refer to the docstring of this method for more information.
        )r'   Úbatch_decode©r5   Úargsr9   s      r   rT   zChameleonProcessor.batch_decode—   s    € ð
 +ˆt�~‰~×*Ñ*¨DÐ;°FÑ;Ð;r   c                 ó:   —  | j                   j                  |i |¤ŽS )z¼
        This method forwards all its arguments to LlamaTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
        the docstring of this method for more information.
        )r'   ÚdecoderU   s      r   rX   zChameleonProcessor.decodeŸ   s    € ð
 %ˆt�~‰~×$Ñ$ dÐ5¨fÑ5Ð5r   c                 óœ   — | j                   j                  }| j                  j                  }t        t        j                  ||z   «      «      S )N)r'   Úmodel_input_namesr&   rC   ÚdictÚfromkeys)r5   Útokenizer_input_namesÚimage_processor_input_namess      r   rZ   z$ChameleonProcessor.model_input_names¦   sA   € ð !%§¡× @Ñ @ÐØ&*×&:Ñ&:×&LÑ&LÐ#Ü”D—M‘MÐ"7Ð:UÑ"UÓVÓWÐWr   )i   z<image>)NNNN)r   r   r   Ú__doc__Ú
attributesÚtokenizer_classÚvalid_kwargsÚimage_processor_classÚintrB   r4   r   r   r   r   r   r   r   r   r   rR   rT   rX   ÚpropertyrZ   Ú__classcell__)r6   s   @r   r%   r%   ,   sÊ   ø„ ñð$ $ [Ð1€JØ>€OØ&¨Ð6€LØ5Ðñ5ÀSð 5Ð^aõ 5ð (,ØhlØØñFeà˜Ñ$ðFeð �u˜YÐ(9¸4À	¹?ÈDÐQbÑLcÐcÑdÑeðFeð Ð1Ñ2ðFeð 
óFeòR<ò6ð ñXó ôXr   r%   N)r_   Útypingr   r   r   Úfeature_extraction_utilsr   Úimage_utilsr   Úprocessing_utilsr	   r
   r   r   r   Útokenization_utils_baser   r   r   r   r%   Ú__all__r   r   r   ú<module>rm      sY   ðñ÷ )Ñ (å 4Ý %ß wÕ wß Cô%˜*¨Eõ %ô
Ð/°uõ 
ôX˜ô XðD  Ð
 �r   