
    Z j                         S 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KJr   " S S\	S	S
9r " S S\S	S
9r\ " S S\5      5       rS/rg)z 
Processor class for Chameleon.
   )BatchFeature)
ImageInput)MultiModalDataProcessingKwargsProcessorMixin
TextKwargsUnpack)PreTokenizedInput	TextInput)auto_docstringc                   $    \ rS rSr% Sr\\S'   Srg)ChameleonTextKwargs   am  
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_completion N)__name__
__module____qualname____firstlineno____doc__bool__annotations____static_attributes__r       ڃ/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/transformers/models/chameleon/processing_chameleon.pyr   r      s     !%$r   r   F)totalc                   6    \ rS rSr% \\S'   SSSS.SS0S.rSrg	)
ChameleonProcessorKwargs*   text_kwargsF)paddingr   return_mm_token_type_ids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S\S\4U 4S jjjr\  SS\S-  S\	\
-  \\	   -  \\
   -  S-  S\\   S	\4S
 jj5       rSS jrSrU =r$ )ChameleonProcessor8   image_seq_lengthimage_tokenc                 X  > [         TU ]  X5        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
        UR                  U R                  5      U l        UR                  U R                  5      U l        UR                  U R                  5      U l        U R                  U R                  U R                  /U l        g)z
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	image_ids)selfimage_processor	tokenizerr*   r+   	__class__s        r   r0   ChameleonProcessor.__init__:   s     	4 04;I}4U4U900[f'==d>N>NO#*9k#B#BI 	 7>i6U6Uy22[c'==d>N>NO$-$C$CDDZDZ$[!"+"A"A$BVBV"W--t/H/H$JaJabr   Nimagestextkwargsreturnc                    [        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     0 n	Ub  U R"                  " U40 US	   D6n	US   R                  S
S5      n
US   R                  SS5      nU R                  " U40 US   DS
S0D6nU R%                  XlS/S9  U(       a  U R'                  US   5      US'   [)        0 UEU	EU
S9$ )a  
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`.
    zAInvalid input text. Please provide a string, or a list of stringsNz&You must provide either text or imagestokenizer_init_kwargsr    r   Fimages_kwargsr#   r"   image)
modalities	input_idsmm_token_type_ids)datatensor_type)
isinstancestrlist	TypeError
ValueError_merge_kwargsr   r;   init_kwargspopr4   r+   r*   r5   replace	sep_tokenappendr:   _check_special_mm_tokenscreate_mm_token_type_idsr   )r9   r>   r?   r@   output_kwargsr   prompt_stringsone_img_tokenssampleimage_inputsr#   r"   text_inputss                r   __call__ChameleonProcessor.__call__O   s   $ 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!!&)	  //Y-:XYL&}599:JDQ#0#?#C#CD^`e#f nn^i}]7Sidhi%%nwi%X#/3/L/L[YdMe/fK+,!@K!@<!@n]]r   c                     0 nUb>  U R                   S-   /[        U5      -  nS/[        U5      -  nUR                  XES.5        [        S0 UD6$ )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   )r9   image_sizesr@   vision_datard   re   s         r   _get_num_multimodal_tokens-ChameleonProcessor._get_num_multimodal_tokens   s_     " $ 5 5 9:S=MM!"c+&6 64Dmn,,,r   )r5   r7   r8   r*   r4   r6   r+   r3   )i   z<image>)NN)N)r   r   r   r   intrM   r0   r   r   r   r
   rN   r	   r   r   r_   rj   r   __classcell__)r<   s   @r   r(   r(   8   s    cS c^a c c*  %)ae3^T!3^ ++d9o=EV@WWZ^^3^ 12	3^
 
3^ 3^j- -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>rt      sk    5 %  D #%*E %/u  a- a- a-H  
 r   