
    fTh                         S r SSKrSSKJr  SSKJrJr  SSKJr  SSK	J
r
  SSKJrJrJr  SS	KJrJr   " S
 S\SS9r " S S\5      rS/rg)z
Processor class for TrOCR.
    N)contextmanager)ListUnion   )BatchFeature)
ImageInput)ProcessingKwargsProcessorMixinUnpack)PreTokenizedInput	TextInputc                       \ rS rSr0 rSrg)TrOCRProcessorKwargs    N)__name__
__module____qualname____firstlineno__	_defaults__static_attributes__r       b/var/www/auris/envauris/lib/python3.13/site-packages/transformers/models/trocr/processing_trocr.pyr   r      s    Ir   r   F)totalc            
          ^  \ rS rSrSrSS/rSrSrSU 4S jjr    SS\	S	\
\\\\   \\   4   S
\\   S\4S jjrS rS r\S 5       r\S 5       r\S 5       rSrU =r$ )TrOCRProcessor!   a  
Constructs a TrOCR processor which wraps a vision image processor and a TrOCR tokenizer into a single processor.

[`TrOCRProcessor`] offers all the functionalities of [`ViTImageProcessor`/`DeiTImageProcessor`] and
[`RobertaTokenizer`/`XLMRobertaTokenizer`]. See the [`~TrOCRProcessor.__call__`] and [`~TrOCRProcessor.decode`] for
more information.

Args:
    image_processor ([`ViTImageProcessor`/`DeiTImageProcessor`], *optional*):
        An instance of [`ViTImageProcessor`/`DeiTImageProcessor`]. The image processor is a required input.
    tokenizer ([`RobertaTokenizer`/`XLMRobertaTokenizer`], *optional*):
        An instance of [`RobertaTokenizer`/`XLMRobertaTokenizer`]. The tokenizer is a required input.
image_processor	tokenizerAutoImageProcessorAutoTokenizerc                   > S nSU;   a,  [         R                  " S[        5        UR                  S5      nUb  UOUnUc  [	        S5      eUc  [	        S5      e[
        TU ]  X5        U R                  U l        SU l	        g )Nfeature_extractorzhThe `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor` instead.z)You need to specify an `image_processor`.z"You need to specify a `tokenizer`.F)
warningswarnFutureWarningpop
ValueErrorsuper__init__r   current_processor_in_target_context_manager)selfr   r   kwargsr#   	__class__s        r   r*   TrOCRProcessor.__init__4   s     &(MM
 !'

+> ?-<-H/N_"HIIABB4!%!5!5*/'r   imagestextr.   returnc                 R   U R                   (       a  U R                  " U40 UD6$ Uc  Uc  [        S5      eU R                  " [        4SU R
                  R                  0UD6nUb  U R                  " U40 US   D6nUb  U R
                  " U40 US   D6nUc  W$ Uc  W$ WS   WS'   U$ )ax  
When used in normal mode, this method forwards all its arguments to AutoImageProcessor's
[`~AutoImageProcessor.__call__`] and returns its output. If used in the context
[`~TrOCRProcessor.as_target_processor`] this method forwards all its arguments to TrOCRTokenizer's
[`~TrOCRTokenizer.__call__`]. Please refer to the docstring of the above two methods for more information.
zBYou need to specify either an `images` or `text` input to process.tokenizer_init_kwargsimages_kwargstext_kwargs	input_idslabels)r,   r+   r(   _merge_kwargsr   r   init_kwargsr   )	r-   r1   r2   audiovideosr.   output_kwargsinputs	encodingss	            r   __call__TrOCRProcessor.__call__H   s     **))&;F;;>dlabb** 
"&.."<"<
 
 ))&SM/4RSFtL}]/KLI<M^(5F8Mr   c                 :    U R                   R                  " U0 UD6$ )z
This method forwards all its arguments to TrOCRTokenizer's [`~PreTrainedTokenizer.batch_decode`]. Please refer
to the docstring of this method for more information.
)r   batch_decoder-   argsr.   s      r   rD   TrOCRProcessor.batch_decodep   s    
 ~~**D;F;;r   c                 :    U R                   R                  " U0 UD6$ )z
This method forwards all its arguments to TrOCRTokenizer's [`~PreTrainedTokenizer.decode`]. Please refer to the
docstring of this method for more information.
)r   decoderE   s      r   rI   TrOCRProcessor.decodew   s    
 ~~$$d5f55r   c              #      #    [         R                  " S5        SU l        U R                  U l        Sv   U R
                  U l        SU l        g7f)zq
Temporarily sets the tokenizer for processing the input. Useful for encoding the labels when fine-tuning TrOCR.
z`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your labels by using the argument `text` of the regular `__call__` method (either in the same call as your images inputs, or in a separate call.TNF)r$   r%   r,   r   r+   r   r-   s    r   as_target_processor"TrOCRProcessor.as_target_processor~   sG     
 	9	

 +/'!%!%!5!5*/'s   AAc                 P    [         R                  " S[        5        U R                  $ )Nzg`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.)r$   r%   r&   image_processor_classrL   s    r   feature_extractor_class&TrOCRProcessor.feature_extractor_class   s"    u	
 )))r   c                 P    [         R                  " S[        5        U R                  $ )Nz[`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.)r$   r%   r&   r   rL   s    r   r#    TrOCRProcessor.feature_extractor   s"    i	
 ###r   )r,   r+   )NN)NNNN)r   r   r   r   __doc__
attributesrP   tokenizer_classr*   r   r   r   r   r   r   r   r   rA   rD   rI   r   rM   propertyrQ   r#   r   __classcell__)r/   s   @r   r   r   !   s     $[1J0%O0, "^b&& I0$y/4HYCZZ[& -.& 
&P<6 0 0 * * $ $r   r   )rU   r$   
contextlibr   typingr   r   image_processing_utilsr   image_utilsr   processing_utilsr	   r
   r   tokenization_utils_baser   r   r   r   __all__r   r   r   <module>ra      sL     %  2 % H H C+5 {$^ {$| 
r   