Ë
    T^(h»  ã                   óÔ   — 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 ddlmZ  G d„ d	ed
¬«      Z G d„ de	d
¬«      Z ej(                  e«      Z G d„ de
«      ZdgZy)z!
Processor class for Pix2Struct.
é    )ÚListÚOptionalÚUnioné   )ÚBatchFeature)ÚImagesKwargsÚProcessingKwargsÚProcessorMixinÚUnpack)ÚBatchEncodingÚPreTokenizedInputÚ	TextInput)Úloggingc                   ó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   © ó    úr/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/pix2struct/processing_pix2struct.pyr   r      s0   … Ø˜#‘ÓØ˜% 	Ð+<¸dÀ9¹oÈtÐTeÑOfÐ 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   r4   zPix2StructProcessor.__init__J   s   ø€ Ø*/ˆ	Ô'Ü‰Ñ˜¨)Õ4r   ÚtextÚkwargsÚreturnc                 óö  — |€|€t        d«      ‚ | j                  t        fd| j                  j                  i|¤Ž}|d   j                  dd«      }|€L| j                  j                  s6|�|nd|d   d<   | j                  | _         | j                  dd|i|d   ¤Ž}|S | j                  j                  s | j                  |fi |d   ¤Ž}	n+|d   j                  d	|«        | j                  |fi |d   ¤Ž}	|�j| j                  j                  sT|�|nd
|d   d<    | 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_kwargsr)   r    Tr7   r   r   FÚattention_maskÚdecoder_attention_maskÚ	input_idsÚdecoder_input_idsr   )Ú
ValueErrorÚ_merge_kwargsr   r.   Úinit_kwargsÚpopr-   Úis_vqaÚcurrent_processorÚ
setdefaultÚupdate)
r5   Úimagesr7   ÚaudioÚvideosr8   Úoutput_kwargsr    Útext_encodingÚencoding_image_processors
             r   Ú__call__zPix2StructProcessor.__call__N   sÑ  € ð ˆ>˜d˜lÜÐIÓJÐJà*˜×*Ñ*Ü%ñ
à"&§.¡.×"<Ñ"<ð
ð ñ
ˆð
 +¨=Ñ9×=Ñ=Ð>RÐTXÓYÐàˆ> $×"6Ñ"6×"=Ò"=à&8Ð&DÑ"È$ð ˜-Ñ(Ð)=Ñ>ð &*§^¡^ˆDÔ"Ø*˜DŸN™NÑU°ÐU¸ÀmÑ8TÑUˆMØ Ð à×#Ñ#×*Ò*à'; t×';Ñ';¸FÑ'eÀmÐTcÑFdÑ'eÑ$ð ˜/Ñ*×5Ñ5°mÀTÔJØ'; t×';Ñ';¸FÑ'eÀmÐTcÑFdÑ'eÐ$àÐ D×$8Ñ$8×$?Ò$?à&8Ð&DÑ"È%ð ˜-Ñ(Ð)=Ñ>ð +˜DŸN™NÑU°ÐU¸ÀmÑ8TÑUˆMà =Ñ0Ø:G×:KÑ:KÐL\Ó:]�Ð6Ñ7Ø˜mÑ+Ø5B×5FÑ5FÀ{Ó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©r5   Úargsr8   s      r   rP   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.   ÚdecoderQ   s      r   rT   zPix2StructProcessor.decode�   s    € ð
 %ˆt�~‰~×$Ñ$ dÐ5¨fÑ5Ð5r   c                 óœ   — | j                   j                  }| j                  j                  }t        t        j                  ||z   «      «      S )N)r.   Úmodel_input_namesr-   ÚlistÚdictÚfromkeys)r5   Útokenizer_input_namesÚimage_processor_input_namess      r   rV   z%Pix2StructProcessor.model_input_names–   s?   € à $§¡× @Ñ @ÐØ&*×&:Ñ&:×&LÑ&LÐ#Ü”D—M‘MÐ"7Ð:UÑ"UÓVÓWÐWr   )NNNN)r   r   r   Ú__doc__Ú
attributesÚimage_processor_classÚtokenizer_classr4   r   r   r   r   r   r   r   r   rN   rP   rT   ÚpropertyrV   Ú__classcell__)r6   s   @r   r,   r,   7   sŸ   ø„ ñð $ [Ð1€JØ6ÐØ8€Oô5ð Ø^bØØñ8(ð �IÐ0°$°y±/À4ÐHYÑCZÐZÑ[ð8(ð Ð2Ñ3ð8(ð 
ˆ}˜lÐ*Ñ	+ó8(òt<ò6ð ñXó ôXr   r,   N)r\   Útypingr   r   r   Úfeature_extraction_utilsr   Úprocessing_utilsr   r	   r
   r   Útokenization_utils_baser   r   r   Úutilsr   r   r   Ú
get_loggerr   Úloggerr,   Ú__all__r   r   r   ú<module>rj      sr   ðñ÷ )Ñ (å 4ß VÓ Vß RÑ RÝ ôi˜\°õ iô
Ð 0¸õ ð( 
ˆ×	Ñ	˜HÓ	%€ôcX˜.ô cXðL !Ð
!�r   