
    fTh)                         S SK JrJrJr  SSKJr  SSKJr  SSKJ	r	J
r
JrJrJr  SSKJrJr   " S S\S	S
9r " S S\	S	S
9r " S S\
S	S
9r " S S\5      rS/rg)    )ListOptionalUnion   )BatchFeature)
ImageInput)ImagesKwargsProcessingKwargsProcessorMixin
TextKwargsUnpack)PreTokenizedInput	TextInputc                        \ rS rSr% \\S'   Srg)Emu3TextKwargs   return_for_image_generation N)__name__
__module____qualname____firstlineno__bool__annotations____static_attributes__r       `/var/www/auris/envauris/lib/python3.13/site-packages/transformers/models/emu3/processing_emu3.pyr   r      s    !%%r   r   F)totalc                   *    \ rS rSr% \\S'   \\S'   Srg)Emu3ImagesKwargs   ratio
image_arear   N)r   r   r   r   strr   intr   r   r   r   r    r       s    JOr   r    c                   >    \ rS rSr% \\S'   \\S'   SS0SSS.S	.rS
rg)Emu3ProcessorKwargs"   text_kwargsimages_kwargsr   Fz1:1i  )r"   r#   )r)   r*   r   N)	r   r   r   r   r   r   r    	_defaultsr   r   r   r   r'   r'   "   s.    ## *5
  
	Ir   r'   c                      ^  \ rS rSrSrSS/rS/rSrSr SU 4S jjr	    SS	\
\   S
\
\\\\\   \\   4      S\\   S\4S jjrS rS	\4S jrS rS r\S 5       rSrU =r$ )Emu3Processor0   az  
Constructs a Emu3 processor which wraps a Emu3 image processor and a GPT2 tokenizer into a single
processor.

[`Emu3Processor`] offers all the functionalities of [`Emu3ImageProcessor`] and [`GPT2TokenizerFast`].
See the [`~Emu3Processor.__call__`] and [`~Emu3Processor.decode`] for more information.

Args:
    image_processor ([`Emu3ImageProcessor`]):
        The image processor is a required input.
    tokenizer ([`Emu3TokenizerFast`]):
        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.
image_processor	tokenizerchat_template)GPT2TokenizerGPT2TokenizerFastEmu3ImageProcessorc                   > UR                   U l         UR                  U l        UR                  U l        UR                  U l        UR                  U l        UR                  U l        UR                  U l	        SU l
        [        TU ]1  XUS9  g )N   )r1   )image_tokenimage_token_id	boi_tokenimage_start_token	eoi_tokenimage_end_tokenimage_wrapper_tokenfake_token_around_image	eof_token	bos_tokendownsample_ratiosuper__init__)selfr/   r0   r1   kwargs	__class__s        r   rC   Emu3Processor.__init__F   s     %00'66!*!4!4(22'0'D'D$",,",, !=Qr   imagestextrE   returnc                    [        U[        5      (       a  U/nO8[        U[        5      (       d#  [        US   [        5      (       d  [        S5      eU R                  " [
        4SU R                  R                  0UD6nUS   R                  SS5      nUS   R                  SS	5      nUS   R                  S
S	5      n	U(       a  Ub  [        S5      eU(       d  Uc  Uc  [        S5      e0 n
U R                   nU R                   U R                   3nU(       Gd  UGb  U R                  " U40 US   D6n
[        U
R                  5      n/ nU H  nU R                   U;   a  [#        U5      nUu  nnUU R$                  -  nUU R$                  -  nUUS-   -  nU U SU U R&                   SU-   U 3nUR)                  U R                   US5      nU R*                   U 3nU R                   U;   a  M  UR-                  U5        M     U Vs/ s H  oR)                  SU R                   5      PM      nnOpU(       ai  U R/                  XU R$                  5      u  nnU U SU U R&                   3nU Vs/ s H  oR*                   U U 3PM     nnUU//[1        U5      -  U
S'   US   R                  SS	5      nU R                  " U40 US   D6nU R3                  UUS/S9  UR4                  " S0 U
D6  [7        UUS9$ s  snf s  snf )a  
Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the `text`
and `kwargs` arguments to Emu3TokenizerFast's [`~Emu3TokenizerFast.__call__`] if `text` is not `None` to encode
the text. To prepare the image(s), this method forwards the `images` and `kwrags` arguments to
CLIPImageProcessor's [`~CLIPImageProcessor.__call__`] if `images` is not `None`. Please refer to the docstring
of the above two methods for more information.

Args:
    images (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `List[PIL.Image.Image]`, `List[np.ndarray]`, `List[torch.Tensor]`):
        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 (`str`, `List[str]`, `List[List[str]]`):
        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.

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`.
r   zAInvalid input text. Please provide a string, or a list of stringstokenizer_init_kwargsr)   r   Fr*   r"   Nr#   zGYou should not provide `images` when `return_for_image_generation=True`zOYou must provide either text or images when `return_for_image_generation=False`   *z<placeholder>image_sizesreturn_tensorsimage)
modalities)datatensor_typer   )
isinstancer$   list	TypeError_merge_kwargsr'   r0   init_kwargspop
ValueErrorr:   r?   r<   r/   iterrO   r7   nextrA   r>   replacer@   appendcalculate_generate_sizelen_check_special_mm_tokensupdater   )rD   rH   rI   audiovideosrE   output_kwargsr   r"   r#   image_featuresimage_start_tokensimage_end_tokensrO   prompt_stringssample
image_sizeheightwidthimage_seq_lengthimage_placeholderimage_promptrP   rS   s                           r   __call__Emu3Processor.__call__W   sZ   T dC  6DD$''
47C0H0H_``**
"&.."<"<
 

 '4M&B&F&FGdfk&l#o.227DA"?377dK
&6+=fgg*t|noo $ 6 67"nn-d.B.B-CD +v/A!11&[M/<Z[N~99:KN&&&0!%k!2J$.MFE#t'<'<<F!T%:%::E'-';$+=*>vhawtOkOkNlm|  @P  nP  mQ  Rb  Qc  )d%#^^D,<,<>OQRSF $/x8F &&&0 %%f-  UccTb&NN?D4D4DETbDcD ) 88DLaLabMFE01&5'$B^B^A_`LLPQD&~~&vh|n=DDQ.4e_,=D	,IN=) '}599:JDQ~~dCmM&BC%%dDgY%G%n%>BB! d Rs   %K=3Lc                     [        [        UR                  S5      5      u  pEXE-  nX&-  S-  n[        [        XW-  U-  5      5      n[        [        XG-  U-  5      5      n	X4$ )N:g      ?)mapr%   splitround)
rD   r"   r#   spatial_factorrn   rm   current_areatarget_ratiotoken_heighttoken_widths
             r   r`   %Emu3Processor.calculate_generate_size   sd    CS!12~"1c95!6!GHI% 4~ EFG((r   c                 <    U R                   R                  " U40 UD6$ N)r/   postprocess)rD   rH   rE   s      r   r   Emu3Processor.postprocess   s    ##//A&AAr   c                 :    U R                   R                  " U0 UD6$ )z
This method forwards all its arguments to Emu3TokenizerFast's [`~PreTrainedTokenizer.batch_decode`]. Please
refer to the docstring of this method for more information.
)r0   batch_decoderD   argsrE   s      r   r   Emu3Processor.batch_decode   s    
 ~~**D;F;;r   c                 :    U R                   R                  " U0 UD6$ )z
This method forwards all its arguments to Emu3TokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
the docstring of this method for more information.
)r0   decoder   s      r   r   Emu3Processor.decode   s    
 ~~$$d5f55r   c                     U R                   R                  nU R                  R                  n[        [        R                  X-   5      5      $ r   )r0   model_input_namesr/   rV   dictfromkeys)rD   tokenizer_input_namesimage_processor_input_namess      r   r   Emu3Processor.model_input_names   s<     $ @ @&*&:&:&L&L#DMM"7"UVWWr   )r@   rA   r?   r>   r<   r:   r7   r8   r   )NNNN)r   r   r   r   __doc__
attributesvalid_kwargstokenizer_classimage_processor_classrC   r   r   r   r   r   r   r   r'   r   rr   r`   r   r   r   propertyr   r   __classcell__)rF   s   @r   r-   r-   0   s      $[1J#$L<O0 	R& (,hldC$dC uY(94	?DQbLccdedC ,-dC 
dCL)B* B<6 X Xr   r-   N)typingr   r   r   image_processing_utilsr   image_utilsr   processing_utilsr	   r
   r   r   r   tokenization_utils_baser   r   r   r    r'   r-   __all__r   r   r   <module>r      sb   " ) ( 2 % b b C&Zu &|5 
*% kXN kX\ 
r   