
    Z j                         S r 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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)zq
Processor class for InstructBLIP. Largely copy of Blip2Processor with addition of a tokenizer for the Q-Former.
   )BatchFeature)
ImageInput)ProcessingKwargsProcessorMixinUnpack)
AddedTokenPreTokenizedInput	TextInput)auto_docstringloggingc                   0    \ rS rSrSSSSSSSSSSS.	0rSrg)	InstructBlipProcessorKwargs   text_kwargsTF    )	add_special_tokenspaddingstridereturn_overflowing_tokensreturn_special_tokens_maskreturn_offsets_mappingreturn_token_type_idsreturn_lengthverbose N)__name__
__module____qualname____firstlineno__	_defaults__static_attributes__r       ډ/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/transformers/models/instructblip/processing_instructblip.pyr   r      s,    "&).*/&+%*"

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	 5       rS
rU =r$ )InstructBlipProcessor,   Nc                    > [        US5      (       d,  [        SSSS9U l        UR                  U R                  /SS9  OUR                  U l        X@l        [
        TU ]  XU5        g)a  
qformer_tokenizer (`AutoTokenizer`):
    An instance of ['PreTrainedTokenizer`]. The Q-Former tokenizer is a required input.
num_query_tokens (`int`, *optional*):
    "
    Number of tokens used by the Qformer as queries, should be same as in model's config.
image_tokenz<image>FT)
normalizedspecial)special_tokensN)hasattrr   r)   
add_tokensnum_query_tokenssuper__init__)selfimage_processor	tokenizerqformer_tokenizerr/   kwargs	__class__s         r#   r1   InstructBlipProcessor.__init__.   sc     y-00))tTD  $"2"2!3D I(44D 05FGr"   imagestextr6   returnc                    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0 nUGb^  [        U[        5      (       a  U/nO8[        U[        5      (       d#  [        US   [        5      (       d  [        S5      eU R                  " U40 US   D6nUR                  S5      US'   UR                  S	5      US
'   US   R                  S5      b  US   S==   U R                  -  ss'   U R                  " U40 US   D6nUbv  U R                  R                  U R                  -  n	SUS   S'   SUS   S'   SUS   S'   U R                  " U	40 US   D6n
U H  nX    Vs/ s H
  oU   U-   PM     snX'   M!     UR                  U5        Ub'  U R                  " U40 US   D6nUR                  U5        [!        XeS9nU$ s  snf )Nz,You have to specify at least images or text.tokenizer_init_kwargsr   return_tensorsr   zAInvalid input text. Please provide a string, or a list of strings	input_idsqformer_input_idsattention_maskqformer_attention_mask
max_lengthFr   r   
truncationimages_kwargs)tensor_type)
ValueError_merge_kwargsr   r4   init_kwargspop
isinstancestrlistr5   getr/   r)   contentupdater3   r   )r2   r9   r:   r6   output_kwargsr>   encodingqformer_text_encodingtext_encodingimage_tokensimage_text_encodingksampleimage_encodings                 r#   __call__InstructBlipProcessor.__call__?   s%    >dlKLL**'
"&.."<"<
 
 '}599:JDQ$$$vd++JtAw4L4L !dee$($:$:4$`=Q^C_$`!,A,E,Ek,RH()1F1J1JK[1\H-. ]+//=Im,\:d>S>SS: NN4P=3OPM!#//77$:O:OOEJm,-AB:?m,Y7=Bm,\:&*nn\&b]S`Ea&b#&AVcVf'gVfFA(>(GVf'gM$ 'OOM*!11&[M/<Z[NOON+  E (hs   G-c                 p    U R                   R                  nU R                  R                  nSS/nX-   U-   $ )Nr@   rB   )r4   model_input_namesr3   )r2   tokenizer_input_namesimage_processor_input_namesqformer_input_namess       r#   r]   'InstructBlipProcessor.model_input_namess   s?     $ @ @&*&:&:&L&L#24LM$BEXXXr"   )r)   r/   )N)NN)r   r   r   r   r1   r   r   r
   r	   rM   r   r   r   rZ   propertyr]   r!   __classcell__)r7   s   @r#   r&   r&   ,   s    H"  %)Z^1T!1 ++d9o=EV@WW1 45	1
 
1 1f Y Yr"   r&   N)__doc__image_processing_utilsr   image_utilsr   processing_utilsr   r   r   tokenization_utils_baser   r	   r
   utilsr   r   
get_loggerr   loggerr   r&   __all__r   r"   r#   <module>rm      sn    3 % H H O O , 
		H	%"2%   KYN KY KY\ #
#r"   