
     `ij                         d Z ddlZddlmZ ddlmZmZ ddlmZ ddl	m
Z
 ddlmZmZmZ dd	lmZmZ  G d
 ded          Z G d de          ZdgZdS )z
Processor class for TrOCR.
    N)contextmanager)OptionalUnion   )BatchFeature)
ImageInput)ProcessingKwargsProcessorMixinUnpack)PreTokenizedInput	TextInputc                       e Zd Zi ZdS )TrOCRProcessorKwargsN)__name__
__module____qualname__	_defaults     ~/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/transformers/models/trocr/processing_trocr.pyr   r      s        IIIr   r   F)totalc            
            e Zd ZdZddgZdZdZd fd	Z	 	 	 	 ddee	         d	e
eeee         ee         f         d
ee         defdZed             Zed             Zed             Zed             Z xZS )TrOCRProcessora  
    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AutoTokenizerNc                     d }d|v r/t          j        dt                     |                    d          }||n|}t	                                          ||           | j        | _        d| _        d S )Nfeature_extractorzhThe `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor` instead.F)	warningswarnFutureWarningpopsuper__init__r   current_processor_in_target_context_manager)selfr   r   kwargsr   	__class__s        r   r%   zTrOCRProcessor.__init__4   s     &((M  
 !'

+> ? ?-<-H//N_)444!%!5*/'''r   imagestextr)   returnc                    | j         r | j        |fi |S ||t          d           | j        t          fd| j        j        i|}| | j        |fi |d         }| | j        |fi |d         }||S ||S |d         |d<   |S )a  
        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.
        NzBYou need to specify either an `images` or `text` input to process.tokenizer_init_kwargsimages_kwargstext_kwargs	input_idslabels)r'   r&   
ValueError_merge_kwargsr   r   init_kwargsr   )	r(   r+   r,   audiovideosr)   output_kwargsinputs	encodingss	            r   __call__zTrOCRProcessor.__call__D   s     * 	<)4)&;;F;;;>dlabbb** 
 
"&."<
 
 
 )T)&SSM/4RSSF&tLL}]/KLLI<M^(5F8Mr   c                 &    | j         j        }|dgz   S )Nr3   )r   model_input_names)r(   image_processor_input_namess     r   r>   z TrOCRProcessor.model_input_namesl   s    &*&:&L#*hZ77r   c              #      K   t          j        d           d| _        | j        | _        dV  | j        | _        d| _        dS )z
        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_processorz"TrOCRProcessor.as_target_processorq   sW      
 	9	
 	
 	

 +/'!%!%!5*/'''r   c                 D    t          j        dt                     | j        S )Nzg`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.)r    r!   r"   image_processor_classrA   s    r   feature_extractor_classz&TrOCRProcessor.feature_extractor_class   s'    u	
 	
 	
 ))r   c                 D    t          j        dt                     | j        S )Nz[`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.)r    r!   r"   r   rA   s    r   r   z TrOCRProcessor.feature_extractor   s'    i	
 	
 	
 ##r   )NN)NNNN)r   r   r   __doc__
attributesrD   tokenizer_classr%   r   r   r   r   r   listr   r   r   r<   propertyr>   r   rB   rE   r   __classcell__)r*   s   @r   r   r   !   s<         $[1J0%O0 0 0 0 0 0$ (,^b& &$& I0$y/4HYCZZ[& -.& 
& & & &P 8 8 X8 0 0 ^0 * * X* $ $ X$ $ $ $ $r   r   )rG   r    
contextlibr   typingr   r   image_processing_utilsr   image_utilsr   processing_utilsr	   r
   r   tokenization_utils_baser   r   r   r   __all__r   r   r   <module>rT      s     % % % % % % " " " " " " " " 2 2 2 2 2 2 % % % % % % H H H H H H H H H H C C C C C C C C    +5    n$ n$ n$ n$ n$^ n$ n$ n$b 
r   