o
    h=                     @   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%dede	e
eee
 ee f dede	eeef de	eeef dee dedee dee dededededededee	eef  def"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	tokenizerBlipImageProcessor)BertTokenizerBertTokenizerFastc                    s    d|_ t || | j| _d S )NF)return_token_type_idssuper__init__r   current_processor)selfr   r   	__class__ ^/var/www/html/ai/venv/lib/python3.10/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u r|du rt d|du r.| j| _| jd||||||||	|
||||||d|}|S | j||d}|durR| jd||||||||	|
||||||d|}nd}|du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+   r   )
ValueErrorr   r   r   update)r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r   r)   r*   r+   kwargstext_encodingencoding_image_processorr   r   r   __call__2   sb   
zBlipProcessor.__call__c                 O      | j j|i |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   r4         zBlipProcessor.batch_decodec                 O   r3   )z
        This method forwards all its arguments to BertTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
        the docstring of this method for more information.
        )r   decoder5   r   r   r   r8      r7   zBlipProcessor.decodec                 C   s"   | j j}| jj}tt|| S )N)r   model_input_namesr   listdictfromkeys)r   tokenizer_input_namesimage_processor_input_namesr   r   r   r9      s   zBlipProcessor.model_input_names)NNTFNNr   NNFFFFFTN)__name__
__module____qualname____doc__
attributesimage_processor_classtokenizer_classr   r   r   r   r
   r   boolstrr	   r   r   intr   r   r2   r4   r8   propertyr9   __classcell__r   r   r   r   r      sz    	

Rr   N)rB   typingr   r   r   image_utilsr   processing_utilsr   tokenization_utils_baser   r	   r
   r   r   utilsr   r   r   r   r   r   <module>   s   