a
    h                     @   sv   d Z ddlmZmZ ddlmZ ddlmZmZm	Z	 ddl
mZmZmZ G dd ded	d
ZG dd deZdgZdS )z
Processor class for Blip.
    )OptionalUnion   )
ImageInput)ProcessingKwargsProcessorMixinUnpack)BatchEncodingPreTokenizedInput	TextInputc                
   @   s*   e Zd Zdddddddddd	i dZdS )BlipProcessorKwargsTFr   )	Zadd_special_tokenspaddingZstrideZreturn_overflowing_tokensZreturn_special_tokens_maskZreturn_offsets_mappingreturn_token_type_idsZreturn_lengthverbose)text_kwargsimages_kwargsN)__name__
__module____qualname__	_defaults r   r   d/var/www/html/assistant/venv/lib/python3.9/site-packages/transformers/models/blip/processing_blip.pyr      s   r   F)totalc                       sj   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d	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)ZBlipImageProcessorZBlipImageProcessorFast)ZBertTokenizerZBertTokenizerFastc                    s    d|_ t || | j| _d S )NF)r   super__init__r   Zcurrent_processor)selfr   r   kwargs	__class__r   r   r   =   s    zBlipProcessor.__init__N)imagestextr   returnc           	      K   s   |du r|du rt dd}| jtfd| jji|}|durT| j|fi |d }|dur| j|fi |d }|dur|| |S |S )ae  
        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.
        Args:
            images (`ImageInput`):
                The image or batch of images to be prepared. Each image can be a PIL image, NumPy array or PyTorch
                tensor. Both channels-first and channels-last formats are supported.
            text (`TextInput`, `PreTokenizedInput`, `list[TextInput]`, `list[PreTokenizedInput]`):
                The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings
                (pretokenized string). If the sequences are provided as list of strings (pretokenized), you must set
                `is_split_into_words=True` (to lift the ambiguity with a batch of sequences).
            return_tensors (`str` or [`~utils.TensorType`], *optional*):
                If set, will return tensors of a particular framework. Acceptable values are:
                    - `'tf'`: Return TensorFlow `tf.constant` objects.
                    - `'pt'`: Return PyTorch `torch.Tensor` objects.
                    - `'np'`: Return NumPy `np.ndarray` objects.
                    - `'jax'`: Return JAX `jnp.ndarray` objects.
        Nz*You have to specify either images or text.Ztokenizer_init_kwargsr   r   )
ValueErrorZ_merge_kwargsr   r   Zinit_kwargsr   update)	r   r"   r#   ZaudioZvideosr   Ztext_encodingZoutput_kwargsZencoding_image_processorr   r   r   __call__B   s$    
zBlipProcessor.__call__c                 C   s&   | j j}| jj}dd |D }|| S )Nc                 S   s   g | ]}|d kr|qS )Ztoken_type_idsr   ).0namer   r   r   
<listcomp>y       z3BlipProcessor.model_input_names.<locals>.<listcomp>)r   model_input_namesr   )r   Ztokenizer_input_namesZimage_processor_input_namesr   r   r   r,   u   s    zBlipProcessor.model_input_names)NNNN)r   r   r   __doc__
attributesZimage_processor_classZtokenizer_classr   r   r   r   strlistr   r
   r   r   r	   r'   propertyr,   __classcell__r   r   r    r   r   +   s"       3r   N)r-   typingr   r   Zimage_utilsr   Zprocessing_utilsr   r   r   Ztokenization_utils_baser	   r
   r   r   r   __all__r   r   r   r   <module>   s   R