
    fTh                         S r SSKJrJrJr  SSKJr  SSKJrJ	r	J
r
Jr  SSKJrJrJr  SSKJr   " S S	\S
S9r " S S\	S
S9r\R(                  " \5      r " S S\
5      rS/rg)z!
Processor class for Pix2Struct.
    )ListOptionalUnion   )BatchFeature)ImagesKwargsProcessingKwargsProcessorMixinUnpack)BatchEncodingPreTokenizedInput	TextInput)loggingc                   P    \ rS rSr% \\   \S'   \\\\	\
\   \
\	   4      \S'   Srg)Pix2StructImagesKwargs   max_patchesheader_text N)__name__
__module____qualname____firstlineno__r   int__annotations__r   r   r   r   __static_attributes__r       l/var/www/auris/envauris/lib/python3.13/site-packages/transformers/models/pix2struct/processing_pix2struct.pyr   r      s0    #%	+<d9otTeOf fghhr   r   F)totalc            
       B    \ rS rSr% \\S'   SSSSSSSSSS.	SS0S	.rS
rg)Pix2StructProcessorKwargs    images_kwargsTFr   )	add_special_tokenspaddingstridereturn_overflowing_tokensreturn_special_tokens_maskreturn_offsets_mappingreturn_token_type_idsreturn_lengthverboser   i   )text_kwargsr#   r   N)r   r   r   r   r   r   	_defaultsr   r   r   r   r!   r!       s=    )) #').*/&+%*"

 4
Ir   r!   c            	          ^  \ rS rSrSrSS/rSrSrU 4S jr    SS\	\
\\\
   \\   4   S	\\   S
\	\\4   4S jjrS rS r\S 5       rSrU =r$ )Pix2StructProcessor7   a  
Constructs a PIX2STRUCT processor which wraps a BERT tokenizer and PIX2STRUCT image processor into a single
processor.

[`Pix2StructProcessor`] offers all the functionalities of [`Pix2StructImageProcessor`] and [`T5TokenizerFast`]. See
the docstring of [`~Pix2StructProcessor.__call__`] and [`~Pix2StructProcessor.decode`] for more information.

Args:
    image_processor (`Pix2StructImageProcessor`):
        An instance of [`Pix2StructImageProcessor`]. The image processor is a required input.
    tokenizer (Union[`T5TokenizerFast`, `T5Tokenizer`]):
        An instance of ['T5TokenizerFast`] or ['T5Tokenizer`]. The tokenizer is a required input.
image_processor	tokenizerPix2StructImageProcessor)T5TokenizerT5TokenizerFastc                 2   > SUl         [        TU ]	  X5        g )NF)r*   super__init__)selfr2   r3   	__class__s      r   r9   Pix2StructProcessor.__init__J   s    */	'4r   textkwargs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UcR  U R                  R                  (       d7  Ub  UOSUS   S'   U R                  U l        U R                  " SSU0US   D6nU$ U R                  R                  (       d  U R                  " U40 US   D6n	O+US   R                  S	U5        U R                  " U40 US   D6n	Ubt  U R                  R                  (       dY  Ub  UOS
US   S'   U R                  " SSU0US   D6nSU;   a  UR                  S5      US'   SU;   a  UR                  S5      US'   OSnUb  U	R                  U5        U	$ )z
This method uses [`Pix2StructImageProcessor.preprocess`] method to prepare image(s) for the model, and
[`T5TokenizerFast.__call__`] to prepare text for the model.

Please refer to the docstring of the above two methods for more information.
Nz*You have to specify either images or text.tokenizer_init_kwargsr-   r$   Tr=   r#   r   Fattention_maskdecoder_attention_mask	input_idsdecoder_input_idsr   )
ValueError_merge_kwargsr!   r3   init_kwargspopr2   is_vqacurrent_processor
setdefaultupdate)
r:   imagesr=   audiovideosr>   output_kwargsr$   text_encodingencoding_image_processors
             r   __call__Pix2StructProcessor.__call__N   s    >dlIJJ**%
"&.."<"<
 

 +=9==>RTXY>$"6"6"="=&8&D"$ -()=> &*^^D" NNUUm8TUM  ##**'+';';F'emTcFd'e$ /*55mTJ'+';';F'emTcFd'e$D$8$8$?$?&8&D"% -()=> !NNUUm8TUM=0:G:K:KL\:]67m+5B5F5F{5S12 M$$++M:''r   c                 :    U R                   R                  " U0 UD6$ )z
This method forwards all its arguments to Pix2StructTokenizerFast's [`~PreTrainedTokenizer.batch_decode`].
Please refer to the docstring of this method for more information.
)r3   batch_decoder:   argsr>   s      r   rW    Pix2StructProcessor.batch_decode   s    
 ~~**D;F;;r   c                 :    U R                   R                  " U0 UD6$ )z
This method forwards all its arguments to Pix2StructTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please
refer to the docstring of this method for more information.
)r3   decoderX   s      r   r\   Pix2StructProcessor.decode   s    
 ~~$$d5f55r   c                     U R                   R                  nU R                  R                  n[        [        R                  X-   5      5      $ )N)r3   model_input_namesr2   listdictfromkeys)r:   tokenizer_input_namesimage_processor_input_namess      r   r_   %Pix2StructProcessor.model_input_names   s<     $ @ @&*&:&:&L&L#DMM"7"UVWWr   )rK   )NNNN)r   r   r   r   __doc__
attributesimage_processor_classtokenizer_classr9   r   r   r   r   r   r!   r   r   rT   rW   r\   propertyr_   r   __classcell__)r;   s   @r   r0   r0   7   s     $[1J68O5 ^b8( I0$y/4HYCZZ[8( 238( 
}l*	+8(t<6 X Xr   r0   N)rf   typingr   r   r   feature_extraction_utilsr   processing_utilsr   r	   r
   r   tokenization_utils_baser   r   r   utilsr   r   r!   
get_loggerr   loggerr0   __all__r   r   r   <module>rt      sp    ) ( 4 V V R R i\ i
 0 ( 
		H	%cX. cXL !
!r   