
    %	&h                         d dl mZ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 ddlmZmZ ddlmZ dd	lmZ  G d
 de
d      Z G d de      ZdgZy)    )DictListOptionalUnion   )BatchFeature)
ImageInput)ProcessingKwargsProcessorMixinUnpack)PreTokenizedInput	TextInput)
TensorType   )AutoTokenizerc                   6    e Zd Zddidddej                  dZy)AriaProcessorKwargspaddingF  )max_image_sizesplit_image)text_kwargsimages_kwargsreturn_tensorsN)__name__
__module____qualname__r   PYTORCH	_defaults     ~/var/www/pru.catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/transformers/models/aria/processing_aria.pyr   r      s-     u
 " 
 %,,	Ir!   r   F)totalc                        e Zd ZdZddgZddgZdZdZ	 	 	 	 ddee	e
f   dee
   deeeeef   ef      f fdZ	 	 	 dd	eeeee   ee   f   d
ee   dee   defdZd Zd Zed        Z xZS )AriaProcessora  
    AriaProcessor is a processor for the Aria model which wraps the Aria image preprocessor and the LLama slow tokenizer.

    Args:
        image_processor (`AriaImageProcessor`, *optional*):
            The AriaImageProcessor to use for image preprocessing.
        tokenizer (`PreTrainedTokenizerBase`, *optional*):
            An instance of [`PreTrainedTokenizerBase`]. This should correspond with the model's text model. The tokenizer is a required input.
        chat_template (`str`, *optional*):
            A Jinja template which will be used to convert lists of messages in a chat into a tokenizable string.
        size_conversion (`Dict`, *optional*):
            A dictionary indicating size conversions for images.
    image_processor	tokenizerchat_templatesize_conversionAriaImageProcessorr   c                     |ddd}|j                         D ci c]  \  }}t        |      | c}}| _        ||j                  |j                  |_        t
        |   |||       y c c}}w )N      )i  r   )r(   )itemsintr)   	pad_token	unk_tokensuper__init__)selfr&   r'   r(   r)   kv	__class__s          r"   r3   zAriaProcessor.__init__@   sv     "$'c2O6E6K6K6MNdaA	N Y%8%8%@"+"5"5I)=Q  Os   A-textimageskwargsreturnc                     | j                   t        fd| j                  j                  i|}t	        |t
              r|g}n.t	        |t              st	        |d   t
              st        d      | | j                  |fi |d   }| j                  |j                  j                  d      }g }	|j                  d      |z  }
|D ]P  }|j                  | j                  j                  | j                  j                  |
z        }|	j                  |       R ni }|}	 | j                  |	fi |d   }t!        i ||      S )	a  
        Main method to prepare for the model one or several sequences(s) and image(s).

        Args:
            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).
            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.


        Returns:
            [`BatchFeature`]: A [`BatchFeature`] with the following fields:
            - **input_ids** -- List of token ids to be fed to a model. Returned when `text` is not `None`.
            - **attention_mask** -- List of indices specifying which tokens should be attended to by the model (when
            `return_attention_mask=True` or if *"attention_mask"* is in `self.model_input_names` and if `text` is not
            `None`).
            - **pixel_values** -- Pixel values to be fed to a model. Returned when `images` is not `None`.
            - **pixel_mask** -- Pixel mask to be fed to a model. Returned when `images` is not `None`.
        tokenizer_init_kwargsr   zAInvalid input text. Please provide a string, or a list of stringsr   r   	num_cropsr   )data)_merge_kwargsr   r'   init_kwargs
isinstancestrlist
ValueErrorr&   r)   pixel_valuesshapepopreplaceimage_tokenappendr   )r4   r8   r9   audiovideosr:   output_kwargsimage_inputstokens_per_imageprompt_stringsr>   sampletext_inputss                r"   __call__zAriaProcessor.__call__P   s^   < +**
"&.."<"<
 

 dC 6DD$'
47C0H`aa/4//0L
  $33L4M4M4S4STU4VWN$((58HHI .(B(BDNND^D^ajDjk%%f-.
 L!N$dnn
M*

 !@K!@<!@AAr!   c                 :     | j                   j                  |i |S )z
        This method forwards all its arguments to LlamaTokenizerFast's [`~PreTrainedTokenizer.batch_decode`]. Please
        refer to the docstring of this method for more information.
        )r'   batch_decoder4   argsr:   s      r"   rV   zAriaProcessor.batch_decode   s     
 +t~~**D;F;;r!   c                 :     | j                   j                  |i |S )z
        This method forwards all its arguments to LlamaTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
        the docstring of this method for more information.
        )r'   decoderW   s      r"   rZ   zAriaProcessor.decode   s     
 %t~~$$d5f55r!   c                     | j                   j                  }| j                  j                  }|D cg c]
  }|dk7  s	| }}t        t        j                  ||z               S c c}w )Nr>   )r'   model_input_namesr&   rD   dictfromkeys)r4   tokenizer_input_namesimage_processor_input_namesnames       r"   r\   zAriaProcessor.model_input_names   se     $ @ @&*&:&:&L&L# 9T&kW[_jWjt&k#&kDMM"7:U"UVWW 'ls
   
A#A#)NNNN)NNN)r   r   r   __doc__
attributesvalid_kwargsimage_processor_classtokenizer_classr   r   rC   r   r   floatr/   r3   r   r   r   r	   r   r   r   rT   rV   rZ   propertyr\   __classcell__)r7   s   @r"   r%   r%   ,   s    $[1J#%67L0%O /3'+BFR +,R  }	R
 "$uUCZ'8#'=">?R& (,=BI0$y/4HYCZZ[=B $=B ,-=B 
=B~<6 X Xr!   r%   N)typingr   r   r   r   image_processing_utilsr   image_utilsr	   processing_utilsr
   r   r   tokenization_utilsr   r   utilsr   autor   r   r%   __all__r    r!   r"   <module>rr      sL   * / . 2 % H H >   
*% 
yXN yXx 
r!   