Ë
    T^(h2'  ã                   óÜ   — d Z ddlmZmZmZ ddlmZ ddl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  ej&                  e«      Z G d	„ d
ed¬«      Z G d„ ded¬«      Z G d„ de«      ZdgZy)z
Processor class for UDOP.
é    )ÚListÚOptionalÚUnion)Úloggingé   )ÚBatchFeature)Ú
ImageInput)ÚProcessingKwargsÚProcessorMixinÚ
TextKwargsÚUnpack)ÚPreTokenizedInputÚ	TextInputc                   ól   — e Zd ZU eeee   eee      f      ed<   eeee      eeee         f   ed<   y)ÚUdopTextKwargsÚword_labelsÚboxesN)Ú__name__Ú
__module__Ú__qualname__r   r   r   ÚintÚ__annotations__© ó    úf/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/udop/processing_udop.pyr   r       sH   … Ø˜%  S¡	¨4°°S±	©?Ð :Ñ;Ñ<Ó<Ø��d˜3‘i‘ $ t¨D°©I¡Ñ"7Ð7Ñ8Ô8r   r   F)Útotalc            
       ó6   — e Zd ZU eed<   ddddddddddœ	i dœZy)ÚUdopProcessorKwargsÚtext_kwargsTFr   )	Úadd_special_tokensÚpaddingÚ
truncationÚstrideÚreturn_overflowing_tokensÚreturn_special_tokens_maskÚreturn_offsets_mappingÚreturn_lengthÚverbose)r   Úimages_kwargsN)r   r   r   r   r   Ú	_defaultsr   r   r   r   r   %   s6   … ØÓð #'ØØØØ).Ø*/Ø&+Ø"Øñ

ð ñ�Ir   r   c                   ó¦   ‡ — e Zd ZdZddgZdZdZdgZˆ fd„Z	 	 dddd	œd
e	e
   deeeee   ee   f   dee   defd„Zd„ Zd„ Zd„ Zed„ «       Zˆ xZS )ÚUdopProcessoraÕ  
    Constructs a UDOP processor which combines a LayoutLMv3 image processor and a UDOP tokenizer into a single processor.

    [`UdopProcessor`] offers all the functionalities you need to prepare data for the model.

    It first uses [`LayoutLMv3ImageProcessor`] to resize, rescale and normalize document images, and optionally applies OCR
    to get words and normalized bounding boxes. These are then provided to [`UdopTokenizer`] or [`UdopTokenizerFast`],
    which turns the words and bounding boxes into token-level `input_ids`, `attention_mask`, `token_type_ids`, `bbox`.
    Optionally, one can provide integer `word_labels`, which are turned into token-level `labels` for token
    classification tasks (such as FUNSD, CORD).

    Additionally, it also supports passing `text_target` and `text_pair_target` to the tokenizer, which can be used to
    prepare labels for language modeling tasks.

    Args:
        image_processor (`LayoutLMv3ImageProcessor`):
            An instance of [`LayoutLMv3ImageProcessor`]. The image processor is a required input.
        tokenizer (`UdopTokenizer` or `UdopTokenizerFast`):
            An instance of [`UdopTokenizer`] or [`UdopTokenizerFast`]. The tokenizer is a required input.
    Úimage_processorÚ	tokenizerÚLayoutLMv3ImageProcessor)ÚUdopTokenizerÚUdopTokenizerFastÚ	text_pairc                 ó&   •— t         ‰| �  ||«       y )N)ÚsuperÚ__init__)Úselfr-   r.   Ú	__class__s      €r   r5   zUdopProcessor.__init__S   s   ø€ Ü‰Ñ˜¨)Õ4r   N)ÚaudioÚvideosÚimagesÚtextÚkwargsÚreturnc                óT  —  | j                   t        fd| j                  j                  i|¤ | j                  |Ž ¤Ž}|d   j                  dd«      }|d   j                  dd«      }	|d   j                  dd«      }
|d   j                  dd«      }|d   j                  d	d«      }|d   j                  d
d«      }| j                  j                  r|�t        d«      ‚| j                  j                  r|	�t        d«      ‚|r|st        d«      ‚|� | j                  di |d   ¤ŽS  | j                  dd|i|d   ¤Ž}|j                  dd«      }|j                  dd«      }|d   j                  d
d«       |d   j                  dd«       |
|d   d<   |�|n||d   d<   |	|d   d<   |�3| j                  j                  r|
€t        |t        «      r|g}||d   d<    | j                  dd|�|n|i|d   ¤Ž}|du r| j                  |d   |d   «      |d<   |j                  |«       |S )a~  
        This method first forwards the `images` argument to [`~UdopImageProcessor.__call__`]. In case
        [`UdopImageProcessor`] was initialized with `apply_ocr` set to `True`, it passes the obtained words and
        bounding boxes along with the additional arguments to [`~UdopTokenizer.__call__`] and returns the output,
        together with the prepared `pixel_values`. In case [`UdopImageProcessor`] was initialized with `apply_ocr` set
        to `False`, it passes the words (`text`/``text_pair`) and `boxes` specified by the user along with the
        additional arguments to [`~UdopTokenizer.__call__`] and returns the output, together with the prepared
        `pixel_values`.

        Alternatively, one can pass `text_target` and `text_pair_target` to prepare the targets of UDOP.

        Please refer to the docstring of the above two methods for more information.
        Útokenizer_init_kwargsr   r   Nr   r2   r$   Fr&   Útext_targetzdYou cannot provide bounding boxes if you initialized the image processor with apply_ocr set to True.zaYou cannot provide word labels if you initialized the image processor with apply_ocr set to True.zKYou cannot return overflowing tokens without returning the offsets mapping.r:   r)   ÚwordsÚtext_pair_targetr;   TÚpixel_valuesÚoverflow_to_sample_mappingr   )Ú_merge_kwargsr   r.   Úinit_kwargsÚ'prepare_and_validate_optional_call_argsÚpopÚgetr-   Ú	apply_ocrÚ
ValueErrorÚ
isinstanceÚstrÚget_overflowing_imagesÚupdate)r6   r:   r;   r8   r9   Úargsr<   Úoutput_kwargsr   r   r2   r$   r&   r@   ÚfeaturesÚfeatures_wordsÚfeatures_boxesÚencoded_inputss                     r   Ú__call__zUdopProcessor.__call__V   s¬  € ð8 +˜×*Ñ*Üñ
à"&§.¡.×"<Ñ"<ð
ð ð
ð ;ˆd×:Ñ:¸DÐAñ	
ˆð ˜mÑ,×0Ñ0°¸$Ó?ˆØ# MÑ2×6Ñ6°}ÀdÓKˆØ! -Ñ0×4Ñ4°[À$ÓGˆ	Ø$1°-Ñ$@×$DÑ$DÐE`ÐbgÓ$hÐ!Ø!.¨}Ñ!=×!AÑ!AÐBZÐ\aÓ!bÐØ# MÑ2×6Ñ6°}ÀdÓKˆà×Ñ×)Ò)¨uÐ/@ÜØvóð ð ×Ñ×)Ò)¨{Ð/FÜØsóð ñ %Ñ-CÜÐjÓkÐkàÐ"à!�4—>‘>ñ Ø Ñ.ñð ð ,�t×+Ñ+Ñ\°6Ð\¸]È?Ñ=[Ñ\ˆHØ%Ÿ\™\¨'°4Ó8ˆNØ%Ÿ\™\¨'°4Ó8ˆNà˜-Ñ(×,Ñ,¨]¸DÔAØ˜-Ñ(×,Ñ,Ð-?ÀÔFØ8AˆM˜-Ñ(¨Ñ5Ø=BÐ=N±EÐTbˆM˜-Ñ(¨Ñ1Ø:EˆM˜-Ñ(¨Ñ7ð Ð D×$8Ñ$8×$BÒ$BÀyÐGXÜ˜d¤CÔ(Ø ˜6�DØ<J�˜mÑ,¨[Ñ9à+˜TŸ^™^ñ Ø!Ð-‘T°>ðà Ñ.ñˆNð )¨DÑ0Ø+/×+FÑ+FØ˜^Ñ,¨nÐ=YÑ.Zó,�˜Ñ(ð �O‰O˜NÔ+àˆOr   c                 ó´   — g }|D ]  }|j                  ||   «       Œ t        |«      t        |«      k7  r#t        dt        |«      › dt        |«      › �«      ‚|S )Nz`Expected length of images to be the same as the length of `overflow_to_sample_mapping`, but got z and )ÚappendÚlenrK   )r6   r:   rD   Úimages_with_overflowÚ
sample_idxs        r   rN   z$UdopProcessor.get_overflowing_imagesµ   sy   € à!ÐØ4ò 	<ˆJØ ×'Ñ'¨¨zÑ(:Õ;ð	<ô Ð#Ó$¬Ð,FÓ(GÒGÜðÜÐ,Ó-Ð.¨e´CÐ8RÓ4SÐ3TðVóð ð
 $Ð#r   c                 ó:   —  | j                   j                  |i |¤ŽS )zÃ
        This method forwards all its arguments to PreTrainedTokenizer's [`~PreTrainedTokenizer.batch_decode`]. Please
        refer to the docstring of this method for more information.
        )r.   Úbatch_decode©r6   rP   r<   s      r   r]   zUdopProcessor.batch_decodeÄ   s    € ð
 +ˆt�~‰~×*Ñ*¨DÐ;°FÑ;Ð;r   c                 ó:   —  | j                   j                  |i |¤ŽS )z½
        This method forwards all its arguments to PreTrainedTokenizer's [`~PreTrainedTokenizer.decode`]. Please refer
        to the docstring of this method for more information.
        )r.   Údecoder^   s      r   r`   zUdopProcessor.decodeÌ   s    € ð
 %ˆt�~‰~×$Ñ$ dÐ5¨fÑ5Ð5r   c                 ó
   — g d¢S )N)rC   Ú	input_idsÚbboxÚattention_maskr   )r6   s    r   Úmodel_input_nameszUdopProcessor.model_input_namesÓ   s   € âFÐFr   )NN)r   r   r   Ú__doc__Ú
attributesÚimage_processor_classÚtokenizer_classÚoptional_call_argsr5   r   r	   r   r   r   r   r   r   r   rV   rN   r]   r`   Úpropertyre   Ú__classcell__)r7   s   @r   r,   r,   7   s¼   ø„ ñð* $ [Ð1€JØ6ÐØ<€Oà%˜Ðô5ð
 (,Ø^bð\ð Øò\à˜Ñ$ð\ð �IÐ0°$°y±/À4ÐHYÑCZÐZÑ[ð\ð Ð,Ñ-ð\ð 
ó\ò~$ò<ò6ð ñGó ôGr   r,   N)rf   Útypingr   r   r   Útransformersr   Úimage_processing_utilsr   Úimage_utilsr	   Úprocessing_utilsr
   r   r   r   Útokenization_utils_baser   r   Ú
get_loggerr   Úloggerr   r   r,   Ú__all__r   r   r   ú<module>rv      sp   ðñ÷ )Ñ (å  å 2Ý %ß TÓ Tß Cð 
ˆ×	Ñ	˜HÓ	%€ô9�Z uõ 9ô
Ð*°%õ ô$^G�Nô ^GðB Ð
�r   