
    Ig                         d Z ddlmZmZmZ ddlmZ ddlmZm	Z	m
Z
mZ ddlmZmZmZ  G d ded	
      Z G d de	d	
      Z G d de
      Zy)z!
Processor class for Pix2Struct.
    )ListOptionalUnion   )BatchFeature)ImagesKwargsProcessingKwargsProcessorMixinUnpack)BatchEncodingPreTokenizedInput	TextInputc                   H    e Zd ZU ee   ed<   eeeee	e   e	e   f      ed<   y)Pix2StructImagesKwargsmax_patchesheader_textN)
__name__
__module____qualname__r   int__annotations__r   r   r   r        q/var/www/html/answerous/venv/lib/python3.12/site-packages/transformers/models/pix2struct/processing_pix2struct.pyr   r      s0    #%	+<d9otTeOf fghhr   r   F)totalc            
       :    e Zd ZU eed<   dddddddddd	ddidZy	)
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   N)r   r   r   r   r   	_defaultsr   r   r   r   r      s=    )) #').*/&+%*"

 4
Ir   r   c            	            e Zd ZdZddgZdZdZ fdZ	 	 	 	 ddee	e
ee	   ee
   f   dee   d	eeef   fd
Zd Zd Zed        Z xZS )Pix2StructProcessora  
    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                 4    d|_         t        | 	  ||       y )NF)r%   super__init__)selfr,   r-   	__class__s      r   r3   zPix2StructProcessor.__init__F   s    */	')4r   textkwargsreturnc                    ||t        d       | j                  t        fd| j                  j                  i|}|@| j
                  j                  s*| j                  | _         | j                  dd|i|d   }|S | j
                  j                  s | j
                  |fi |d   }n+|d   j                  d|        | j
                  |fi |d   }|^| j
                  j                  sH | j                  dd|i|d   }d|v r|j                  d      |d	<   d
|v r|j                  d
      |d<   nd}||j                  |       |S )a  
        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_kwargsr6   r(   r   r   attention_maskdecoder_attention_mask	input_idsdecoder_input_idsr   )
ValueError_merge_kwargsr   r-   init_kwargsr,   is_vqacurrent_processor
setdefaultpopupdate)	r4   imagesr6   audiovideosr7   output_kwargstext_encodingencoding_image_processors	            r   __call__zPix2StructProcessor.__call__J   s}    >dlIJJ***%
"&.."<"<
 
 >$"6"6"="=%)^^D"*DNNUUm8TUM  ##**';t';';F'emTcFd'e$ /*55mTJ';t';';F'emTcFd'e$D$8$8$?$?*DNNUUm8TUM=0:G:K:KL\:]67m+5B5F5F{5S12 M$$++M:''r   c                 :     | j                   j                  |i |S )z
        This method forwards all its arguments to Pix2StructTokenizerFast's [`~PreTrainedTokenizer.batch_decode`].
        Please refer to the docstring of this method for more information.
        )r-   batch_decoder4   argsr7   s      r   rO   z Pix2StructProcessor.batch_decode}   s     
 +t~~**D;F;;r   c                 :     | j                   j                  |i |S )z
        This method forwards all its arguments to Pix2StructTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please
        refer to the docstring of this method for more information.
        )r-   decoderP   s      r   rS   zPix2StructProcessor.decode   s     
 %t~~$$d5f55r   c                     | j                   j                  }| j                  j                  }t        t        j                  ||z               S )N)r-   model_input_namesr,   listdictfromkeys)r4   tokenizer_input_namesimage_processor_input_namess      r   rU   z%Pix2StructProcessor.model_input_names   s?     $ @ @&*&:&:&L&L#DMM"7:U"UVWWr   )NNNN)r   r   r   __doc__
attributesimage_processor_classtokenizer_classr3   r   r   r   r   r   r   r   r   rM   rO   rS   propertyrU   __classcell__)r5   s   @r   r+   r+   3   s     $[1J68O5 ^b1( I0$y/4HYCZZ[1( 231( 
}l*	+1(f<6 X Xr   r+   N)r[   typingr   r   r   feature_extraction_utilsr   processing_utilsr   r	   r
   r   tokenization_utils_baser   r   r   r   r   r+   r   r   r   <module>re      sP    ) ( 4 V V R Ri\ i
 0 (\X. \Xr   