Ë
    T^(hÒ  ã                   óž   — 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y)z
Processor class for TrOCR.
é    N)Úcontextmanager)ÚListÚUnioné   )ÚBatchFeature)Ú
ImageInput)ÚProcessingKwargsÚProcessorMixinÚUnpack)ÚPreTokenizedInputÚ	TextInputc                   ó   — e Zd Zi Zy)ÚTrOCRProcessorKwargsN)Ú__name__Ú
__module__Ú__qualname__Ú	_defaults© ó    úh/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/trocr/processing_trocr.pyr   r      s   „ Ø�Ir   r   F)Útotalc            
       ó²   ‡ — e Zd ZdZddgZdZdZdˆ fd„	Z	 	 	 	 ddede	e
eee
   ee   f   d	ee   d
efd„Zd„ Z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ÚAutoTokenizerc                 óø   •— d }d|v r+t        j                  dt        «       |j                  d«      }|�|n|}|€t	        d«      ‚|€t	        d«      ‚t
        ‰| �  ||«       | j                  | _        d| _	        y )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&   zTrOCRProcessor.__init__4   s�   ø€ Ø ÐØ &Ñ(Ü�M‰Mðäôð
 !'§
¡
Ð+>Ó ?Ðà-<Ð-H™/ÐN_ˆØÐ"ÜÐHÓIÐIØÐÜÐAÓBÐBä‰Ñ˜¨)Ô4Ø!%×!5Ñ!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.
        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)   r,   r-   ÚaudioÚvideosr*   Úoutput_kwargsÚinputsÚ	encodingss	            r   Ú__call__zTrOCRProcessor.__call__H   sØ   € ð ×*Ò*Ø)�4×)Ñ)¨&Ñ;°FÑ;Ð;àˆ>˜d˜lÜÐaÓbÐbà*˜×*Ñ*Ü ñ
à"&§.¡.×"<Ñ"<ð
ð ñ
ˆð ÐØ)�T×)Ñ)¨&ÑS°MÀ/Ñ4RÑSˆFØÐØ&˜Ÿ™ tÑL¨}¸]Ñ/KÑLˆIàˆ<ØˆMØˆ^ØÐà(¨Ñ5ˆF�8ÑØˆMr   c                 ó:   —  | j                   j                  |i |¤ŽS )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   r>   zTrOCRProcessor.batch_decodep   s    € ð
 +ˆt�~‰~×*Ñ*¨DÐ;°FÑ;Ð;r   c                 ó:   —  | j                   j                  |i |¤ŽS )z¸
        This method forwards all its arguments to TrOCRTokenizer's [`~PreTrainedTokenizer.decode`]. Please refer to the
        docstring of this method for more information.
        )r   Údecoder?   s      r   rB   zTrOCRProcessor.decodew   s    € ð
 %ˆt�~‰~×$Ñ$ dÐ5¨fÑ5Ð5r   c              #   óž   K  — t        j                  d«       d| _        | j                  | _        d–— | j
                  | _        d| _        y­w)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_processor~   sH   è ø€ ô
 	�‰ð9ô	
ð
 +/ˆÔ'Ø!%§¡ˆÔÛØ!%×!5Ñ!5ˆÔØ*/ˆÕ'ùs   ‚AAc                 óN   — 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_classrD   s    r   Úfeature_extractor_classz&TrOCRProcessor.feature_extractor_classŽ   s"   € ä�‰ØuÜô	
ð ×)Ñ)Ð)r   c                 óN   — 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   rD   s    r   r   z TrOCRProcessor.feature_extractor–   s"   € ä�‰ØiÜô	
ð ×#Ñ#Ð#r   )NN)NNNN)r   r   r   Ú__doc__Ú
attributesrG   Útokenizer_classr&   r   r   r   r   r   r   r   r   r<   r>   rB   r   rE   ÚpropertyrH   r   Ú__classcell__)r+   s   @r   r   r   !   sÃ   ø„ ñð $ [Ð1€JØ0ÐØ%€Oõ0ð, "Ø^bØØñ&àð&ð �IÐ0°$°y±/À4ÐHYÑCZÐZÑ[ð&ð Ð-Ñ.ð&ð 
ó&òP<ò6ð ñ0ó ð0ð ñ*ó ð*ð ñ$ó ô$r   r   )rJ   r    Ú
contextlibr   Útypingr   r   Úimage_processing_utilsr   Úimage_utilsr   Úprocessing_utilsr	   r
   r   Útokenization_utils_baser   r   r   r   Ú__all__r   r   r   ú<module>rV      sL   ðñó Ý %ß å 2Ý %ß HÑ Hß CôÐ+°5õ ô{$�^ô {$ð| Ð
�r   