§
    ‚ŠtjŠ  ã                   óð   — d Z ddlmZ ddlmZ ddlmZmZmZm	Z	 ddl
mZmZ ddlmZmZ  ej        e¦  «        ZdZ G d„ d	ed
¬¦  «        Z G d„ ded
¬¦  «        Ze G d„ de¦  «        ¦   «         ZdgZdS )z
Processor class for Janus.
é   )ÚBatchFeature)Ú
ImageInput)ÚProcessingKwargsÚProcessorMixinÚ
TextKwargsÚUnpack)ÚPreTokenizedInputÚ	TextInput)Úauto_docstringÚloggingz¼You 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                   ó   — e Zd ZU dZeed<   dS )ÚJanusTextKwargsas  
    generation_mode (`str`, *optional*, defaults to `"text"`):
        The generation mode indicating which modality to generate. Can be one of `"text"` or `"image"`. When set
        to `"text"`, the processor prepares inputs for text generation. When set to `"image"`, it prepares inputs
        for image generation by appending image start tokens to the prompt.
    Úgeneration_modeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚstrÚ__annotations__© ó    úh/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/transformers/models/janus/processing_janus.pyr   r   "   s*   € € € € € € ðð ð ÐÐÑÐÐr   r   F)Útotalc                   ó0   — e Zd ZU eed<   ddddœddidœZd	S )
ÚJanusProcessorKwargsÚtext_kwargsFÚleftÚtext)ÚpaddingÚpadding_sider   Úreturn_tensorsÚpt)r   Úcommon_kwargsN)r   r   r   r   r   Ú	_defaultsr   r   r   r   r   -   s>   € € € € € € Ø Ð Ð Ñ à#(¸&ÐU[Ð\Ð\Ø*¨DÐ1ðð €I€I€Ir   r   c            
       óÖ   ‡ — e Zd ZeZ	 	 	 ddedz  dedefˆ fd„Ze		 	 dde
ez  ee
         z  ee         z  d	edz  d
ee         defˆ fd„¦   «         Zdededefd„Zd	efd„Z	 dd„Zˆ xZS )ÚJanusProcessorNFé@  Úchat_templateÚuse_default_system_promptÚnum_image_tokensc                 ó´   •— || _         |j        | _        |j        | _        |j        | _        || _        t          ¦   «                              |||¬¦  «         dS )a  
        use_default_system_prompt (`bool`, *optional*, defaults to `False`):
            Use default system prompt for Text Generation.
        num_image_tokens (`int`, *optional*, defaults to `576`):
            The number of placeholder image tokens needed per one image.
        )r(   N)	r*   Úimage_tokenÚ	boi_tokenÚimage_start_tokenÚ	eoi_tokenÚimage_end_tokenr)   ÚsuperÚ__init__)ÚselfÚimage_processorÚ	tokenizerr(   r)   r*   ÚkwargsÚ	__class__s          €r   r2   zJanusProcessor.__init__9   s[   ø€ ð !1ˆÔØ$Ô0ˆÔØ!*Ô!4ˆÔØ(Ô2ˆÔØ)BˆÔ&å‰Œ×Ò˜¨)À=ÐÑQÔQÐQÐQÐQr   r   Úimagesr6   Úreturnc                 ó  •‡ —  ‰ j         t          fd‰ j        j        i|¤Ž}|d                              d¦  «        }‰ j        r|dk    rd„ |D ¦   «         }n|dk    rˆ fd„|D ¦   «         } t          ¦   «         j        d	||dœ|¤Ž}|S )
aA  
        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_kwargsr   r   r   c                 ó$   — g | ]}t           › |› �‘ŒS r   )ÚDEFAULT_SYSTEM_PROMPT)Ú.0Úsamples     r   ú
<listcomp>z+JanusProcessor.__call__.<locals>.<listcomp>h   s$   € ÐJÐJÐJ¸6Õ,Ð6¨fÐ6Ð6ÐJÐJÐJr   Úimagec                 ó&   •— g | ]}|› ‰j         › �‘ŒS r   )r.   )r>   r?   r3   s     €r   r@   z+JanusProcessor.__call__.<locals>.<listcomp>j   s'   ø€ ÐKÐKÐK¸F�vÐ7˜tÔ5Ð7Ð7ÐKÐKÐKr   )r8   r   r   )Ú_merge_kwargsr   r5   Úinit_kwargsÚpopr)   r1   Ú__call__)r3   r   r8   r6   Úoutput_kwargsr   Úmodel_inputsr7   s   `      €r   rF   zJanusProcessor.__call__P   sÊ   øø€ ð$ +˜Ô*Ý ð
ð 
Ø8<¼Ô8Rð
ØV\ð
ð 
ˆð (¨Ô6×:Ò:Ð;LÑMÔMˆØÔ)ð 	L¨oÀÒ.GÐ.GØJÐJÀTÐJÑJÔJˆDˆDØ Ò'Ð'ØKÐKÐKÐKÀdÐKÑKÔKˆDà'•u‘w”wÔ'ÐR¨v¸DÐRÐRÀMÐRÐRˆØÐr   Úimage_inputsÚ	image_idxc                 óD   — | j         | j        | j        z  z   | j        z   }|S )N)r.   r,   r*   r0   )r3   rI   rJ   Úone_img_tokenss       r   Úreplace_image_tokenz"JanusProcessor.replace_image_tokeno   s)   € ØÔ/°4Ô3CÀdÔF[Ñ3[Ñ\Ð_cÔ_sÑsˆØÐr   c                 ó(   —  | j         j        |fi |¤ŽS )zš
        Forwards all arguments to the image processor's `postprocess` method.
        Refer to the original method's docstring for more details.
        )r4   Úpostprocess)r3   r8   r6   s      r   rO   zJanusProcessor.postprocesss   s"   € ð
 0ˆtÔ#Ô/°ÐAÐA¸&ÐAÐAÐAr   Tc                 óü   — |�|dk    r | j         |fd|i|¤ŽS |dk    r@t          |                     ¦   «         ¦  «        }|                      |d¬¦  «        }|d         S t	          | j        j        › d|› d	�¦  «        ‚)
a  
        Post-process the output of a multimodal model to return the requested modality output.
        If the model cannot generated the requested modality, an error will be raised.

        Args:
            generated_outputs (`torch.Tensor` or `np.ndarray`):
                The output of the model `generate` function. The output is expected to be a tensor of shape `(batch_size, sequence_length)`
                or `(sequence_length,)`.
            skip_special_tokens (`bool`, *optional*, defaults to `True`):
                Whether or not to remove special tokens in the output. Argument passed to the tokenizer's `batch_decode` method.
            generation_mode (`str`, *optional*):
                Generation mode indicated which modality to output and can be one of `["text", "image", "audio"]`.
            **kwargs:
                Additional arguments to be passed to the tokenizer's `batch_decode method`.

        Returns:
            `list[Union[str, PIL.Image.Image]]`: The decoded text or generated image.
        Nr   Úskip_special_tokensrA   zPIL.Image.Image)r!   Úpixel_valuesz# got an unexpected generation_mode=z.. Supported options are only `text` and `image)Úpost_process_image_text_to_textÚlistÚfloatrO   Ú
ValueErrorr7   r   )r3   Úgenerated_outputsrQ   r   r6   r8   s         r   Úpost_process_multimodal_outputz-JanusProcessor.post_process_multimodal_outputz   sÌ   € ð* Ð" o¸Ò&?Ð&?Ø7�4Ô7Ø!ðð Ø7JðØNTðð ð ð  Ò'Ð'Ý $Ð%6×%<Ò%<Ñ%>Ô%>Ñ ?Ô ?ÐØ×%Ò%Ð&7ÐHYÐ%ÑZÔZˆFØ˜.Ô)Ð)õ Ø”>Ô*ð  Oð  OÈð  Oð  Oð  Oñô ð r   )NFr'   )NN)TN)r   r   r   r   Úvalid_processor_kwargsr   ÚboolÚintr2   r   r
   r	   rT   r   r   r   rF   ÚdictrM   rO   rX   Ú__classcell__)r7   s   @r   r&   r&   5   sg  ø€ € € € € à1Ðð %)Ø*/Ø #ðRð Rð ˜T‘zð	Rð
 $(ðRð ðRð Rð Rð Rð Rð Rð. ð [_Ø$(ðð àÐ+Ñ+¨d°9¬oÑ=ÀÐEVÔ@WÑWðð ˜TÑ!ðð Ð-Ô.ð	ð
 
ðð ð ð ð ñ „^ðð<°ð Àð Èð ð ð ð ðB *ð Bð Bð Bð Bð LPð"ð "ð "ð "ð "ð "ð "ð "r   r&   N)r   Úfeature_extraction_utilsr   Úimage_utilsr   Úprocessing_utilsr   r   r   r   Útokenization_utils_baser	   r
   Úutilsr   r   Ú
get_loggerr   Úloggerr=   r   r   r&   Ú__all__r   r   r   ú<module>rf      sX  ððð ð 5Ð 4Ð 4Ð 4Ð 4Ð 4Ø %Ð %Ð %Ð %Ð %Ð %Ø TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TØ CÐ CÐ CÐ CÐ CÐ CÐ CÐ CØ ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,ð 
ˆÔ	˜HÑ	%Ô	%€ðNð ðð ð ð ð �j¨ð ñ ô ð ðð ð ð ð Ð+°5ð ñ ô ð ð ðfð fð fð fð f�^ñ fô fñ „ðfðR Ð
€€€r   