o
    óÜÓh0  ã                   @   s`   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mZ ddlmZ G dd„ deƒZd	S )
z!
Processor class for Pix2Struct.
é    )ÚListÚOptionalÚUnioné   )ÚProcessorMixin)ÚBatchEncodingÚPaddingStrategyÚPreTokenizedInputÚ	TextInputÚTruncationStrategy)Ú
TensorTypec                $       s  e Zd ZdZddgZdZdZ‡ fdd„Z					
							
	
	
	
	
			d&dee	e
ee	 ee
 f dedeeeef deeeef dee dee dedee dee dededededededeeeef  def"dd„Zd d!„ Zd"d#„ Zed$d%„ ƒZ‡  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                    s   d|_ tƒ  ||¡ d S )NF)Úreturn_token_type_idsÚsuperÚ__init__)Úselfr   r   ©Ú	__class__© új/var/www/html/ai/venv/lib/python3.10/site-packages/transformers/models/pix2struct/processing_pix2struct.pyr   -   s   zPix2StructProcessor.__init__NTFé   r   ÚtextÚadd_special_tokensÚpaddingÚ
truncationÚ
max_lengthÚmax_patchesÚstrideÚpad_to_multiple_ofÚreturn_attention_maskÚreturn_overflowing_tokensÚreturn_special_tokens_maskÚreturn_offsets_mappingr   Úreturn_lengthÚverboseÚreturn_tensorsÚreturnc                 K   s(  |du r|du rt dƒ‚|du r2| jjs2| j| _| jd
|||||||	|
|||||||dœ|¤Ž}|S | jjsC| j|f||dœ|¤Ž}n| j|f|||dœ|¤Ž}|dur‡| jjs‡| jd
|||||||	|
|||||||dœ|¤Ž}d|v r{| d¡|d< d|v r†| d¡|d	< nd}|dur’| |¡ |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.)r   r   r   r   r    r"   r#   r$   r%   r&   r'   r   r(   r)   r*   )r*   r!   )r*   r!   Úheader_textÚattention_maskÚdecoder_attention_maskÚ	input_idsÚdecoder_input_idsr   )Ú
ValueErrorr   Úis_vqar   Úcurrent_processorÚpopÚupdate)r   Úimagesr   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r   r(   r)   r*   ÚkwargsÚtext_encodingÚencoding_image_processorr   r   r   Ú__call__1   sˆ   ñðÿÿÿÿÿÿñð€
zPix2StructProcessor.__call__c                 O   ó   | 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©r   Úargsr7   r   r   r   r<   ‘   ó   z Pix2StructProcessor.batch_decodec                 O   r;   )zÁ
        This method forwards all its arguments to Pix2StructTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please
        refer to the docstring of this method for more information.
        )r   Údecoder=   r   r   r   r@   ˜   r?   zPix2StructProcessor.decodec                 C   s"   | j j}| jj}tt || ¡ƒS )N)r   Úmodel_input_namesr   ÚlistÚdictÚfromkeys)r   Útokenizer_input_namesÚimage_processor_input_namesr   r   r   rA   Ÿ   s   z%Pix2StructProcessor.model_input_names)NNTFNNr   r   NNFFFFFTN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
attributesÚimage_processor_classÚtokenizer_classr   r   r
   r	   r   ÚboolÚstrr   r   r   Úintr   r   r:   r<   r@   ÚpropertyrA   Ú__classcell__r   r   r   r   r      s|    îýüûúùø	÷
öõôóòñðïî
ì`r   N)rJ   Útypingr   r   r   Úprocessing_utilsr   Útokenization_utils_baser   r   r	   r
   r   Úutilsr   r   r   r   r   r   Ú<module>   s   