
    fTh2'                         S r SSKJrJrJr  SSKJr  SSK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  \R&                  " \5      r " S	 S
\SS9r " S S\SS9r " S S\5      rS/rg)z
Processor class for UDOP.
    )ListOptionalUnion)logging   )BatchFeature)
ImageInput)ProcessingKwargsProcessorMixin
TextKwargsUnpack)PreTokenizedInput	TextInputc                   t    \ rS rSr% \\\\   \\\      4      \S'   \\\\      \\\\         4   \S'   Sr	g)UdopTextKwargs    word_labelsboxes N)
__name__
__module____qualname____firstlineno__r   r   r   int__annotations____static_attributes__r       `/var/www/auris/envauris/lib/python3.13/site-packages/transformers/models/udop/processing_udop.pyr   r       sH    %S	4S	? :;<<d3i$tDI"7788r   r   F)totalc            
       >    \ rS rSr% \\S'   SSSSSSSSSS.	0 S.rSrg	)
UdopProcessorKwargs%   text_kwargsTFr   )	add_special_tokenspadding
truncationstridereturn_overflowing_tokensreturn_special_tokens_maskreturn_offsets_mappingreturn_lengthverbose)r#   images_kwargsr   N)r   r   r   r   r   r   	_defaultsr   r   r   r   r!   r!   %   s6     #').*/&+"

 Ir   r!   c                      ^  \ rS rSrSrSS/rSrSrS/rU 4S jr	  SS	S	S
.S\
\   S\\\\\   \\   4   S\\   S\4S jjjrS rS rS r\S 5       rSrU =r$ )UdopProcessor7   a  
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U ]  X5        g )N)super__init__)selfr2   r3   	__class__s      r   r:   UdopProcessor.__init__S   s    4r   N)audiovideosimagestextkwargsreturnc                   U R                   " [        4SU R                  R                  0UDU R                  " U6 D6nUS   R                  SS5      nUS   R                  SS5      n	US   R                  SS5      n
US   R                  SS5      nUS   R                  S	S5      nUS   R                  S
S5      nU R                  R                  (       a  Ub  [        S5      eU R                  R                  (       a  U	b  [        S5      eU(       a  U(       d  [        S5      eUb  U R                  " S0 US   D6$ U R                  " SSU0US   D6nUR                  SS5      nUR                  SS5      nUS   R                  S
S5        US   R                  SS5        XS   S'   Ub  UOUUS   S'   XS   S'   Ub=  U R                  R                  (       a"  U
c  [        U[        5      (       a  U/nXS   S'   U R                  " SSUb  UOU0US   D6nUSL a  U R                  US   US   5      US'   UR                  U5        U$ )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   r7   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_targetrA   Tpixel_valuesoverflow_to_sample_mappingr   )_merge_kwargsr!   r3   init_kwargs'prepare_and_validate_optional_call_argspopgetr2   	apply_ocr
ValueError
isinstancestrget_overflowing_imagesupdate)r;   r@   rA   r>   r?   argsrB   output_kwargsr   r   r7   r(   r*   rF   featuresfeatures_wordsfeatures_boxesencoded_inputss                     r   __call__UdopProcessor.__call__V   s   8 **
"&.."<"<
 
 ::DA	
 m,00$?#M266}dK!-044[$G	$1-$@$D$DE`bg$h!!.}!=!A!ABZ\a!b#M266}dK))u/@v  )){/Fs  %-Cjkk">> .  ++\6\]?=[\H%\\'48N%\\'48N-(,,]DA-(,,-?F8A-(5=B=NETbM-(1:E-(7 D$8$8$B$ByGXdC(( 6D<Jm,[9!^^ !-T>.N )D0+/+F+F^,n=Y.Z,( OON+Or   c                     / nU H  nUR                  X   5        M     [        U5      [        U5      :w  a#  [        S[        U5       S[        U5       35      eU$ )Nz`Expected length of images to be the same as the length of `overflow_to_sample_mapping`, but got z and )appendlenrQ   )r;   r@   rJ   images_with_overflow
sample_idxs        r   rT   $UdopProcessor.get_overflowing_images   sr    !4J ''(:; 5 #$,F(GG,-.eC8R4S3TV 
 $#r   c                 :    U R                   R                  " U0 UD6$ )z
This method forwards all its arguments to PreTrainedTokenizer's [`~PreTrainedTokenizer.batch_decode`]. Please
refer to the docstring of this method for more information.
)r3   batch_decoder;   rV   rB   s      r   re   UdopProcessor.batch_decode   s    
 ~~**D;F;;r   c                 :    U R                   R                  " U0 UD6$ )z
This method forwards all its arguments to PreTrainedTokenizer's [`~PreTrainedTokenizer.decode`]. Please refer
to the docstring of this method for more information.
)r3   decoderf   s      r   ri   UdopProcessor.decode   s    
 ~~$$d5f55r   c                 
    / SQ$ )N)rI   	input_idsbboxattention_maskr   )r;   s    r   model_input_namesUdopProcessor.model_input_names   s    FFr   r   )NN)r   r   r   r   __doc__
attributesimage_processor_classtokenizer_classoptional_call_argsr:   r   r	   r   r   r   r   r   r!   r   r\   rT   re   ri   propertyro   r   __classcell__)r<   s   @r   r0   r0   7   s    * $[1J6<O%5
 (,^b\ \$\ I0$y/4HYCZZ[\ ,-\ 
\~$<6 G Gr   r0   N)rq   typingr   r   r   transformersr   image_processing_utilsr   image_utilsr	   processing_utilsr
   r   r   r   tokenization_utils_baser   r   
get_loggerr   loggerr   r!   r0   __all__r   r   r   <module>r      sn    ) (   2 % T T C 
		H	%9Zu 9
*% $^GN ^GB 
r   