
    Z j                         S SK Jr  S SKJr  S SKJrJrJr  S SKJ	r	J
r
  S SKJrJr  \R                  " \5      r " S S\SS	9r\ " S
 S\5      5       rS/rg)   )BatchFeature)
ImageInput)ProcessingKwargsProcessorMixinUnpack)PreTokenizedInput	TextInput)auto_docstringloggingc                   "    \ rS rSrSS00 S.rSrg)Ovis2ProcessorKwargs   paddingF)text_kwargsimage_kwargs N)__name__
__module____qualname____firstlineno__	_defaults__static_attributes__r       {/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/transformers/models/ovis2/processing_ovis2.pyr   r      s     u
 	Ir   r   F)totalc            
          ^  \ rS rSr     SU 4S jjr\  SS\S-  S\\-  \	\   -  \	\   -  S\
\   S\4S jj5       rS\	\   S	\	\	\      4S
 jrS rS r\S 5       rSrU =r$ )Ovis2Processor#   Nc                    > XPl         [        US5      (       a  UR                  OUU l        [        USS5      (       a  UR                  OUR                  U R                  5      U l        [        TU ]  " X4SU0UD6  g)z
image_token (`str`, *optional*, defaults to `"<image>"`):
    Special token used to denote image location.
image_seq_length (`int`, *optional*, defaults to 256):
    The number of image tokens to be used for each image in the input.
image_tokenimage_token_idNchat_template)image_seq_lengthhasattrr    getattrr!   convert_tokens_to_idssuper__init__)selfimage_processor	tokenizerr"   r    r#   kwargs	__class__s          r   r(   Ovis2Processor.__init__%   s{     !14;I}4U4U900[f y"2D99 $$001A1AB 	
 	[=[TZ[r   imagestextr,   returnc                    U R                   " [        4SU R                  R                  0UD6n[	        U[
        5      (       a  U/nO8[	        U[        5      (       d#  [	        US   [
        5      (       d  [        S5      e0 nUbF  U R                  " U40 US   D6nUR                  S5      R                  5       nU R                  X&5      nU R                  " U40 US   D6n[        0 UEUES9$ )ax  
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`.
    - **image_sizes** -- Size of each image that will be used to unpad an image. Returned when `images` is not `None`.
tokenizer_init_kwargs    zAInvalid input text. Please provide a string, or a list of stringsimages_kwargsgridsr   )data)_merge_kwargsr   r+   init_kwargs
isinstancestrlist	TypeErrorr*   poptolist_expand_image_tokensr   )r)   r/   r0   r,   output_kwargsimage_inputsimage_gridstext_inputss           r   __call__Ovis2Processor.__call__=   s    & ** 
"&.."<"<
 
 dC  6DD$''
47C0H0H_``//Y-:XYL&**73::<K,,T?DnnTJ]=-IJ!@K!@<!@AAr   r6   c                    / nSnU H  nSU;   a  X$   nUS   US   pSSU R                   -   S3n	Xx-  S:  aU  [        U5       HF  n
[        U5       H%  nU	SU R                   -   -  n	XS-
  :  d  M   U	S-  n	M'     XS-
  :  d  MA  U	S-  n	MH     U	S	-  n	UR                  SU	S5      nUS-  nSU;   a  M  UR                  U5        M     U$ )
Nr4   <image>   z<IMG_START>z
<IMG_ATOM>z
<IMG_GRID>z	<IMG_COL>z	<IMG_ROW>z	<IMG_END>)r#   rangereplaceappend)r)   r0   r6   processed_text
grid_indexsamplegridrowcolplaceholderrcs               r   r@   #Ovis2Processor._expand_image_tokense   s    
 
Fv%(7DGS +L4;P;P,P+QQ[\9q="3Z!&sA'lT=R=R.R-STK 7{ +{ : ", Qw;';6K ( {*	;Ba
 v%  !!&)# $ r   c                 :    U R                   R                  " U0 UD6$ )z
This method forwards all its arguments to Qwen2TokenizerFast's [`~PreTrainedTokenizer.batch_decode`]. Please
refer to the docstring of this method for more information.
)r+   batch_decoder)   argsr,   s      r   rX   Ovis2Processor.batch_decode   s    
 ~~**D;F;;r   c                 :    U R                   R                  " U0 UD6$ )z
This method forwards all its arguments to Qwen2TokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
the docstring of this method for more information.
)r+   decoderY   s      r   r]   Ovis2Processor.decode   s    
 ~~$$d5f55r   c                     U R                   R                  nU R                  R                  n[        U5      [        U5      -   $ )N)r+   model_input_namesr*   r<   )r)   tokenizer_input_namesimage_processor_input_namess      r   r`    Ovis2Processor.model_input_names   s;     $ @ @&*&:&:&L&L#)*T2M-NNNr   )r#   r    r!   )NNNrH      )NN)r   r   r   r   r(   r
   r   r	   r   r<   r   r   r   rE   intr@   rX   r]   propertyr`   r   __classcell__)r-   s   @r   r   r   #   s     \0  %)Z^%BT!%B ++d9o=EV@WW%B -.	%B
 
%B %BN9o DI6<6 O Or   r   N)feature_extraction_utilsr   image_utilsr   processing_utilsr   r   r   tokenization_utils_baser   r	   utilsr
   r   
get_loggerr   loggerr   r   __all__r   r   r   <module>rp      sf     5 % H H C , 
		H	%+5  nO^ nO nOb 
r   