U
    ,-e<                     @   sl   d Z ddlmZmZmZ ddlmZ ddlmZ ddl	m
Z
mZmZmZmZ ddlmZ G dd	 d	eZd
S )z
Processor class for Blip.
    )ListOptionalUnion   )
ImageInput)ProcessorMixin)BatchEncodingPaddingStrategyPreTokenizedInput	TextInputTruncationStrategy)
TensorTypec                       s   e Zd ZdZddgZdZdZ fddZdee	e
eee
 ee f ee	eeef e	eeef ee eee ee eeeeeeee	eef  edddZdd Zdd Zedd Z  ZS )BlipProcessora]  
    Constructs a BLIP processor which wraps a BERT tokenizer and BLIP image processor into a single processor.

    [`BlipProcessor`] offers all the functionalities of [`BlipImageProcessor`] and [`BertTokenizerFast`]. See the
    docstring of [`~BlipProcessor.__call__`] and [`~BlipProcessor.decode`] for more information.

    Args:
        image_processor (`BlipImageProcessor`):
            An instance of [`BlipImageProcessor`]. The image processor is a required input.
        tokenizer (`BertTokenizerFast`):
            An instance of ['BertTokenizerFast`]. The tokenizer is a required input.
    image_processor	tokenizerZBlipImageProcessor)ZBertTokenizerZBertTokenizerFastc                    s    d|_ t || | j| _d S )NF)return_token_type_idssuper__init__r   current_processor)selfr   r   	__class__ i/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/transformers/models/blip/processing_blip.pyr   ,   s    zBlipProcessor.__init__NTFr   )imagestextadd_special_tokenspadding
truncation
max_lengthstridepad_to_multiple_ofreturn_attention_maskreturn_overflowing_tokensreturn_special_tokens_maskreturn_offsets_mappingr   return_lengthverbosereturn_tensorsreturnc                 K   s   |dkr|dkrt d|dkr\| j| _| jf ||||||||	|
||||||d|}|S | j||d}|dk	r| jf ||||||||	|
||||||d|}nd}|dk	r|| |S )a  
        This method uses [`BlipImageProcessor.__call__`] method to prepare image(s) for the model, and
        [`BertTokenizerFast.__call__`] to prepare text for the model.

        Please refer to the docstring of the above two methods for more information.
        Nz*You have to specify either images or text.)r   r   r   r   r   r    r!   r"   r#   r$   r%   r   r&   r'   r(   )r(   )
ValueErrorr   r   r   update)r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r   r&   r'   r(   kwargsZtext_encodingZencoding_image_processorr   r   r   __call__1   sb    
zBlipProcessor.__call__c                 O   s   | j j||S )z
        This method forwards all its arguments to BertTokenizerFast's [`~PreTrainedTokenizer.batch_decode`]. Please
        refer to the docstring of this method for more information.
        )r   batch_decoder   argsr,   r   r   r   r.      s    zBlipProcessor.batch_decodec                 O   s   | j j||S )z
        This method forwards all its arguments to BertTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
        the docstring of this method for more information.
        )r   decoder/   r   r   r   r1      s    zBlipProcessor.decodec                 C   s"   | j j}| jj}tt|| S )N)r   model_input_namesr   listdictfromkeys)r   Ztokenizer_input_namesZimage_processor_input_namesr   r   r   r2      s    zBlipProcessor.model_input_names)NNTFNNr   NNFFFFFTN)__name__
__module____qualname____doc__
attributesZimage_processor_classZtokenizer_classr   r   r   r   r
   r   boolstrr	   r   r   intr   r   r-   r.   r1   propertyr2   __classcell__r   r   r   r   r      sX                   Rr   N)r9   typingr   r   r   Zimage_utilsr   Zprocessing_utilsr   Ztokenization_utils_baser   r	   r
   r   r   utilsr   r   r   r   r   r   <module>   s   