
    fTh"                         S r SSKJrJrJr  SSKJr  SSKJr  SSK	J
r
JrJrJrJr  SSKJrJr   " S S	\S
S9r " S S\
S
S9r " S S\5      rS/rg)z 
Processor class for Chameleon.
    )ListOptionalUnion   )BatchFeature)
ImageInput)ProcessingKwargsProcessorMixin
TextKwargsUnpack!_validate_images_text_input_order)PreTokenizedInput	TextInputc                        \ rS rSr% \\S'   Srg)ChameleonTextKwargs   return_for_text_completion N)__name__
__module____qualname____firstlineno__bool__annotations____static_attributes__r       j/var/www/auris/envauris/lib/python3.13/site-packages/transformers/models/chameleon/processing_chameleon.pyr   r      s     $$r   r   F)totalc                   4    \ rS rSr% \\S'   SSS.SS0S.rSrg	)
ChameleonProcessorKwargs   text_kwargsF)paddingr   return_tensorspt)r"   common_kwargsr   N)r   r   r   r   r   r   	_defaultsr   r   r   r   r    r       s(    $$ */

 d
Ir   r    c                      ^  \ rS rSrSrSS/rSrSS/rSrSS\	S\
4U 4S	 jjjr    SS
\\   S\\\\\\   \\   4      S\\   S\4S jjrS rS r\S 5       rSrU =r$ )ChameleonProcessor,   a  
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                 H  > X0l         [        US5      (       a  UR                  OUU l        UR                  U R                  5      U l        [        US5      (       a  UR
                  OSU l        [        US5      (       a  UR                  OSU l        [        TU ])  X5        g )Nr0   	boi_tokenz<racm3:break>	eoi_tokenz<eoss>)r/   hasattrr0   convert_tokens_to_idsimage_token_idr3   image_start_tokenr4   image_end_tokensuper__init__)selfr+   r,   r/   r0   	__class__s        r   r;   ChameleonProcessor.__init__D   s     04;I}4U4U900[f'==d>N>NO#*9k#B#BI 	 7>i6U6Uy22[c4r   imagestextkwargsreturnc                 @   [        X5      u  p[        U[        5      (       a  U/nO8[        U[        5      (       d#  [        US   [        5      (       d  [	        S5      eUc  Uc  [        S5      eU R                  " [        4SU R                  R                  0UD6nUS   R                  SS5      n/ nU R                  U R                  U R                  -  -   U R                  -   n	U HO  n
U
R                  U R                  U	5      n
U(       d  XR                  R                   -  n
UR#                  U
5        MQ     US   R                  S	S5      nU R                  " U40 US   D6nU R%                  XS
/S9  Ub  U R&                  " U40 US   D6S   US'   [)        XS9$ )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 stringsNz&You must provide either text or imagestokenizer_init_kwargsr"   r   Fr$   image)
modalitiesimages_kwargspixel_values)datatensor_type)r   
isinstancestrlist	TypeError
ValueError_merge_kwargsr    r,   init_kwargspopr8   r0   r/   r9   replace	sep_tokenappend_check_special_mm_tokensr+   r   )r<   r?   r@   audiovideosrA   output_kwargsr   prompt_stringsone_img_tokenssampler$   rI   s                r   __call__ChameleonProcessor.__call__O   s   R 9FdC  6DD$''
47C0H0H_``<FNEFF**$
"&.."<"<
 

 &3=%A%E%EFbdi%j" //43C3CdF[F[3[\_c_s_ssF^^D$4$4nEF-..222!!&)	  '}599:JDQ~~nMm0LM%%ny%Q#'#7#7#a-P_B`#abp#qD BBr   c                 :    U R                   R                  " U0 UD6$ )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r<   argsrA   s      r   r`   ChameleonProcessor.batch_decode   s    
 ~~**D;F;;r   c                 :    U R                   R                  " U0 UD6$ )z
This method forwards all its arguments to LlamaTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
the docstring of this method for more information.
)r,   decodera   s      r   re   ChameleonProcessor.decode   s    
 ~~$$d5f55r   c                     U R                   R                  nU R                  R                  n[        [        R                  X-   5      5      $ )N)r,   model_input_namesr+   rM   dictfromkeys)r<   tokenizer_input_namesimage_processor_input_namess      r   rh   $ChameleonProcessor.model_input_names   s>     !% @ @&*&:&:&L&L#DMM"7"UVWWr   )r9   r/   r8   r0   r7   )i   z<image>)NNNN)r   r   r   r   __doc__
attributestokenizer_classvalid_kwargsimage_processor_classintrL   r;   r   r   r   r   r   r   r   r    r   r]   r`   re   propertyrh   r   __classcell__)r=   s   @r   r)   r)   ,   s    $ $[1J>O&6L5	5S 	5^a 	5 	5 (,hlHC$HC uY(94	?DQbLccdeHC 12HC 
HCV<6 X Xr   r)   N)rn   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>r|      sY    ) ( 4 % w w C%*E %
/u 
BX BXJ  
 r   