
    fTh-!                         S r SSK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  SSKJrJr  SSKJr  \R$                  " \5      rS	r " S
 S\SS9r " S S\	SS9r " S S\
5      rS/rg)z
Processor class for Janus.
    )ListUnion   )BatchFeature)
ImageInput)ProcessingKwargsProcessorMixin
TextKwargsUnpack)PreTokenizedInput	TextInput)loggingzYou are a helpful language and vision assistant. You are able to understand the visual content that the user provides, and assist the user with a variety of tasks using natural language.

c                        \ rS rSr% \\S'   Srg)JanusTextKwargs(   generation_mode N)__name__
__module____qualname____firstlineno__str__annotations____static_attributes__r       b/var/www/auris/envauris/lib/python3.13/site-packages/transformers/models/janus/processing_janus.pyr   r   (   s    r   r   F)totalc                   4    \ rS rSr% \\S'   SSS.SS0S.rS	rg
)JanusProcessorKwargs,   text_kwargsFtext)paddingr   return_tensorspt)r!   common_kwargsr   N)r   r   r   r   r   r   	_defaultsr   r   r   r   r   r   ,   s      #(VD*D1Ir   r   c            	          ^  \ rS rSrSrSS/rSS/rSrSrSU 4S	 jjr	    SS
\
\\\\   \\   4   S\S\\   S\4S jjrS rS rS\4S jr\S 5       rSrU =r$ )JanusProcessor4   a  
Constructs a Janus processor which wraps a Janus Image Processor and a Llama tokenizer into a single processor.

[`JanusProcessor`] offers all the functionalities of [`JanusImageProcessor`] and [`LlamaTokenizerFast`]. See the
[`~JanusProcessor.__call__`] and [`~JanusProcessor.decode`] for more information.

Args:
    image_processor ([`JanusImageProcessor`]):
        The image processor is a required input.
    tokenizer ([`LlamaTokenizerFast`]):
        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.
    use_default_system_prompt (`str`, *optional*, defaults to `False`):
        Use default system prompt for Text Generation.
image_processor	tokenizerchat_templateuse_default_system_promptJanusImageProcessorLlamaTokenizerFastc                    > SU l         UR                  U l        UR                  U l        UR                  U l        X@l        [        TU ]!  XUS9  g )Ni@  )r-   )	num_image_tokensimage_token	boi_tokenimage_start_token	eoi_tokenimage_end_tokenr.   super__init__)selfr+   r,   r-   r.   kwargs	__class__s         r   r9   JanusProcessor.__init__K   sM     #$00!*!4!4(22)B&=Qr   r"   imagesr;   returnc                     U R                   " [        4SU R                  R                  0UD6nUc  Uc  [	        S5      eUbV  [        U[        5      (       a  U/nO=[        U[        [        45      (       a  [        S U 5       5      (       d  [	        S5      eUS   R                  S5      n/ nU R                  U R                  U R                  -  -   U R                  -   n	U Hd  n
U
R                  U R                  U	5      n
U R                   (       a  US:X  a	  ["        U
-   n
US:X  a  XR                  -  n
UR%                  U
5        Mf     U R                  " U40 US   D6nUb#  US:w  a  U R&                  " SS	U0US
   D6S   US'   [)        US9$ )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 LlamaTokenizerFast's [`~LlamaTokenizerFast.__call__`] if `text` is not `None` to encode
the text. To prepare the image(s), this method forwards the `images` and `kwrags` arguments to
JanusImageProcessor's [`~JanusImageProcessor.__call__`] if `images` is not `None`. Please refer to the doctsring
of the above two methods for more information.

Args:
    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).
    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.
    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`.
tokenizer_init_kwargsz'You must specify either text or images.c              3   B   #    U  H  n[        U[        5      v   M     g 7fN)
isinstancer   ).0ts     r   	<genexpr>*JanusProcessor.__call__.<locals>.<genexpr>   s     =_Z^UVjC>P>PZ^s   zAInvalid input text. Please provide a string, or a list of stringsr!   r   r"   imager>   images_kwargspixel_values)datar   )_merge_kwargsr   r,   init_kwargs
ValueErrorrD   r   listtupleallpopr5   r3   r2   r7   replacer.   DEFAULT_SYSTEM_PROMPTappendr+   r   )r:   r"   r>   videosaudior;   output_kwargsr   prompt_stringsone_img_tokenspromptrL   s               r   __call__JanusProcessor.__call__T   s   P ** 
8<8R8R
V\
 <FNFGG$$$v e}55#=_Z^=_:_:_ !dee'6::;LM //43C3CdF[F[3[\_c_s_ssF^^D$4$4nEF--/V2K.7')000!!&)  ~~nMm0LM /W"<#'#7#7#hv#hWfIg#h$D  &&r   c                 :    U R                   R                  " U0 UD6$ )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r:   argsr;   s      r   r`   JanusProcessor.batch_decode   s    
 ~~**D;F;;r   c                 :    U R                   R                  " U0 UD6$ )z
This method forwards all its arguments to LlamaTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
the docstring of this method for more information.
)r,   decodera   s      r   re   JanusProcessor.decode   s    
 ~~$$d5f55r   c                 <    U R                   R                  " U40 UD6$ )z
Forwards all arguments to the image processor's `postprocess` method.
Refer to the original method's docstring for more details.
)r+   postprocess)r:   r>   r;   s      r   rh   JanusProcessor.postprocess   s     
 ##//A&AAr   c                     U R                   R                  nU R                  R                  n[        [        R                  X-   5      5      $ rC   )r,   model_input_namesr+   rP   dictfromkeys)r:   tokenizer_input_namesimage_processor_input_namess      r   rk    JanusProcessor.model_input_names   s<     $ @ @&*&:&:&L&L#DMM"7"UVWWr   )r7   r5   r3   r2   r.   )NF)NNNN)r   r   r   r   __doc__
attributesvalid_kwargsimage_processor_classtokenizer_classr9   r   r   r   r   r   r   r   r   r]   r`   re   rh   propertyrk   r   __classcell__)r<   s   @r   r)   r)   4   s    " $[1J#%@AL1*OR _c!J'I0$y/4HYCZZ[J' J' -.J' 
J'X<6B* B X Xr   r)   N)rq   typingr   r   feature_extraction_utilsr   image_utilsr   processing_utilsr   r	   r
   r   tokenization_utils_baser   r   utilsr   
get_loggerr   loggerrU   r   r   r)   __all__r   r   r   <module>r      sz     4 % T T  
		H	%N j +5 EX^ EXP 
r   