
    qi                     f    d Z ddlmZ ddlmZmZmZmZmZ ddl	m
Z
mZ e G d de             ZdgZy)z!
Processor class for LayoutLMv3.
   )ProcessorMixin)BatchEncodingPaddingStrategyPreTokenizedInput	TextInputTruncationStrategy)
TensorTypeauto_docstringc            (       n    e Zd Zd fd	Ze	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeez  ee   z  ee   z  deee   z  dz  deee      eeee         z  dz  dee   eee      z  dz  de	de	e
z  ez  d	e	e
z  ez  d
edz  dededz  de	dz  de	dz  de	de	de	de	de	de
ez  dz  def&d       Zd Zed        Z xZS )LayoutLMv3ProcessorNc                 &    t         |   ||       y )N)super__init__)selfimage_processor	tokenizerkwargs	__class__s       f/opt/pipecat/venv/lib/python3.12/site-packages/transformers/models/layoutlmv3/processing_layoutlmv3.pyr   zLayoutLMv3Processor.__init__   s    )4    text	text_pairboxesword_labelsadd_special_tokenspadding
truncation
max_lengthstridepad_to_multiple_ofreturn_token_type_idsreturn_attention_maskreturn_overflowing_tokensreturn_special_tokens_maskreturn_offsets_mappingreturn_lengthverbosereturn_tensorsreturnc                 .   | j                   j                  r|t        d      | j                   j                  r|t        d      | j                  ||      }|0| j                   j                  r|t        |t              r|g}|d   } | j
                  di d||n|d   d||nd d||n|d   d|d	|d
|d|d|	d|
d|d|d|d|d|d|d|d|d||}|j                  d      }|du r| j                  ||d         }||d<   |S )NzdYou 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.)imagesr(   wordsr   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   pixel_valuesToverflow_to_sample_mapping )r   	apply_ocr
ValueError
isinstancestrr   popget_overflowing_images)r   r+   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r   featuresencoded_inputss                          r   __call__zLayoutLMv3Processor.__call__   s   0 ))u/@v  )){/Fs 
 ''vn'U  4 4 > >9CT$$v )I' 
)x/@
#,#8id
 !,%(72C
 $	

  2
 
 "
 "
 
  2
 #8
 #8
 '@
 (B
 $:
  (!
" #
$ *'
. n-$,00Hd9efF)/~&r   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lenr1   )r   r+   r.   images_with_overflow
sample_idxs        r   r5   z*LayoutLMv3Processor.get_overflowing_imagese   sy    !4 	<J ''z(:;	< #$,F(GG,-.eC8R4S3TV 
 $#r   c                 
    g dS )N)	input_idsbboxattention_maskr-   r/   )r   s    r   model_input_namesz%LayoutLMv3Processor.model_input_namess   s    FFr   )NN)NNNNTFNN    NNNFFFFTN)__name__
__module____qualname__r   r
   r   r   listintboolr3   r   r   r	   r   r8   r5   propertyrB   __classcell__)r   s   @r   r   r      s   5  [_HL@D:>#'056:!%)--1-1*/+0',#26)F ++d9o=EV@WWF %t,='>>E	F
 DId49o!66=F #Yd3i047F !F o-F 3J!33F $JF F  $JF  $d{F  $d{F $(F  %)!F" !%#F$ %F& 'F( j(4/)F, 
-F FP$ G Gr   r   N)__doc__processing_utilsr   tokenization_utils_baser   r   r   r   r   utilsr	   r
   r   __all__r/   r   r   <module>rQ      sD    / w w / ]G. ]G ]G@ !
!r   