§
    ‚Štj'   ã                   óh   — d Z ddlmZ ddlmZ ddlmZ g d¢Ze G d„ de¦  «        ¦   «         ZdgZ	dS )	z
Processor class for EVOLLA.
é   )ÚBatchFeature)ÚProcessorMixin)Úauto_docstring)Úaa_seqÚfoldseekÚmsac                   óÖ   ‡ — e Zd Zdˆ fd„	Zdd„Z	 ddefd„Ze	 	 	 	 ddee	         e	z  dz  d	eee	                  ee	         z  dz  d
edz  dedz  fd„¦   «         Z
d„ Zd„ Zd„ Zd„ Zˆ xZS )ÚEvollaProcessorNé   é   c                 óÄ   •— |€t          d¦  «        ‚|€t          d¦  «        ‚t          ¦   «                              ||¦  «         d| j        _        || _        || _        dS )a‰  
        protein_tokenizer (`EsmTokenizer`):
            An instance of [`EsmTokenizer`]. The protein tokenizer is a required input.
        protein_max_length (`int`, *optional*, defaults to 1024):
            The maximum length of the sequence to be generated.
        text_max_length (`int`, *optional*, defaults to 512):
            The maximum length of the text to be generated.
        Nz+You need to specify an `protein_tokenizer`.z"You need to specify a `tokenizer`.z<|reserved_special_token_0|>)Ú
ValueErrorÚsuperÚ__init__Ú	tokenizerÚ	pad_tokenÚprotein_max_lengthÚtext_max_length)ÚselfÚprotein_tokenizerr   r   r   ÚkwargsÚ	__class__s         €új/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/transformers/models/evolla/processing_evolla.pyr   zEvollaProcessor.__init__   sj   ø€ ð Ð$ÝÐJÑKÔKÐKØÐÝÐAÑBÔBÐBå‰Œ×ÒÐ*¨IÑ6Ô6Ð6à#AˆŒÔ Ø"4ˆÔØ.ˆÔÐÐó    c                 ó   — g }|D ]n}|                      d¦  «        }|                      d¦  «        }d                     d„ t          ||¦  «        D ¦   «         ¦  «        }|                     |¦  «         Œo|                      |dd|d¬¦  «        }|S )Nr   r   Ú c                 óf   — g | ].\  }}|                      ¦   «         |                     ¦   «         z   ‘Œ/S © )ÚupperÚlower)Ú.0ÚsÚfs      r   ú
<listcomp>z4EvollaProcessor.process_proteins.<locals>.<listcomp>7   s1   € Ð"[Ð"[Ð"[¹T¸QÀ 1§7¢7¡9¤9¨q¯wªw©y¬yÑ#8Ð"[Ð"[Ð"[r   ÚptT)Úreturn_tensorsÚ
truncationÚ
max_lengthÚpadding)ÚgetÚjoinÚzipÚappendr   )	r   Úproteinsr   Úsa_sequencesÚproteinr   r   Úsa_sequenceÚ	sa_tokenss	            r   Úprocess_proteinsz EvollaProcessor.process_proteins2   s©   € ØˆØð 	-ð 	-ˆGØ—[’[ Ñ*Ô*ˆFØ—{’{ :Ñ.Ô.ˆHØŸ'š'Ð"[Ð"[ÅSÈÐQYÑEZÔEZÐ"[Ñ"[Ô"[Ñ\Ô\ˆKØ×Ò Ñ,Ô,Ð,Ð,à×*Ò*Ø¨¸$ÐK]Ðgkð +ñ 
ô 
ˆ	ð Ðr   r   c                 ó®   — g }|D ]4}| j                              |dd¬¦  «        }|                     |¦  «         Œ5|                       |dddd|¬¦  «        }|S )NFT)ÚtokenizeÚadd_generation_promptr%   Úlongest)Úadd_special_tokensr&   r)   r'   r(   )r   Úapply_chat_templater-   )r   Útextsr   ÚpromptsÚmessagesÚpromptÚprompt_inputss          r   Úprocess_textzEvollaProcessor.process_text?   s†   € ð
 ˆØð 	#ð 	#ˆHØ”^×7Ò7ØØØ&*ð 8ñ ô ˆFð
 �NŠN˜6Ñ"Ô"Ð"Ð"àŸšØØ$ØØØØ&ð 'ñ 
ô 
ˆð Ðr   r.   Úmessages_listr   c                 óØ  — |�|€t          d¦  «        ‚|�|n| j        }|�|n| j        }t          |t          ¦  «        r|g}t          |t
          t          f¦  «        r%t          |d         t
          t          f¦  «        s|g}t          |t
          t          f¦  «        r(t          d„ |D ¦   «         ¦  «        st          d¦  «        ‚t          |t
          t          f¦  «        rFt          d„ |D ¦   «         ¦  «        s-t          dd                     t          ¦  «        › d	|› �¦  «        ‚t          |t
          t          f¦  «        r®|D ]ª}t          |t
          t          f¦  «        s t          d
t          |¦  «        › d�¦  «        ‚t          d„ |D ¦   «         ¦  «        st          d¦  «        ‚t          d„ |D ¦   «         ¦  «        st          d„ |D ¦   «         ¦  «        rt          d|› �¦  «        ‚Œ«n t          dt          |¦  «        › d�¦  «        ‚|                      ||¦  «        }|                      ||¦  «        }t          |d         |d         |d         |d         dœ¬¦  «        S )a¯  
        proteins (`Union[List[dict], dict]`):
            A list of dictionaries or a single dictionary containing the following keys:
                - `"aa_seq"` (`str`) -- The amino acid sequence of the protein.
                - `"foldseek"` (`str`) -- The foldseek string of the protein.
        messages_list (`Union[List[List[dict]], List[dict]]`):
            A list of lists of dictionaries or a list of dictionaries containing the following keys:
                - `"role"` (`str`) -- The role of the message.
                - `"content"` (`str`) -- The content of the message.
        protein_max_length (`int`, *optional*, defaults to 1024):
            The maximum length of the sequence to be generated.
        text_max_length (`int`, *optional*, defaults to 512):
            The maximum length of the text.

        Return:
            a dict with following keys:
                - `protein_input_ids` (`torch.Tensor` of shape `(batch_size, sequence_length)`) -- The input IDs for the protein sequence.
                - `protein_attention_mask` (`torch.Tensor` of shape `(batch_size, sequence_length)`) -- The attention mask for the protein sequence.
                - `text_input_ids` (`torch.Tensor` of shape `(batch_size, sequence_length)`) -- The input IDs for the text sequence.
                - `text_attention_mask` (`torch.Tensor` of shape `(batch_size, sequence_length)`) -- The attention mask for the text sequence.
        Nz3You need to specify `messages_list` and `proteins`.é    c              3   ó@   K  — | ]}t          |t          ¦  «        V — Œd S ©N©Ú
isinstanceÚdict©r!   Úps     r   ú	<genexpr>z+EvollaProcessor.__call__.<locals>.<genexpr>ƒ   s-   è è € Ð:aÐ:aÐST½:ÀaÍÑ;NÔ;NÐ:aÐ:aÐ:aÐ:aÐ:aÐ:ar   zUThe proteins should be a list of dictionaries, but not all elements are dictionaries.c              3   ól   K  — | ]/}t          d „ |                     ¦   «         D ¦   «         ¦  «        V — Œ0dS )c              3   ó(   K  — | ]}|t           v V — Œd S rD   )ÚPROTEIN_VALID_KEYS)r!   Úks     r   rJ   z5EvollaProcessor.__call__.<locals>.<genexpr>.<genexpr>†   s(   è è € Ð:Ð:¨A�Õ'Ð'Ð:Ð:Ð:Ð:Ð:Ð:r   N)ÚallÚkeysrH   s     r   rJ   z+EvollaProcessor.__call__.<locals>.<genexpr>…   sR   è è € ð ;
ð ;
Ø?@�CÐ:Ð:°·²±´Ð:Ñ:Ô:Ñ:Ô:ð;
ð ;
ð ;
ð ;
ð ;
ð ;
r   z2There should be a list of dictionaries with keys: z, z for each protein.But got: z;Each messages in messages_list should be a list instead of ú.c              3   ó@   K  — | ]}t          |t          ¦  «        V — Œd S rD   rE   ©r!   Úms     r   rJ   z+EvollaProcessor.__call__.<locals>.<genexpr>’   s,   è è € ÐAÐA°1�: a­Ñ.Ô.ÐAÐAÐAÐAÐAÐAr   zfEach message in messages_list should be a list of dictionaries, but not all elements are dictionaries.c              3   ó`   K  — | ])}t          |                     ¦   «         ¦  «        d k    V — Œ*dS )é   N)ÚlenrP   rS   s     r   rJ   z+EvollaProcessor.__call__.<locals>.<genexpr>–   s5   è è € Ð<Ð<¨a•s˜1Ÿ6š6™8œ8‘}”}¨Ò)Ð<Ð<Ð<Ð<Ð<Ð<r   c              3   ód   K  — | ]+}t          |                     ¦   «         ¦  «        d dhk    V — Œ,dS )ÚroleÚcontentN)ÚsetrP   rS   s     r   rJ   z+EvollaProcessor.__call__.<locals>.<genexpr>–   sS   è è € ð Dð DØ=>•C˜Ÿš™œ‘M”M f¨iÐ%8Ò8ðDð Dð Dð Dð Dð Dr   zlEach message in messages_list should be a list of dictionaries with two keys: 'role' and 'content'.But got: zFThe messages_list should be a list of lists of dictionaries, but it's Ú	input_idsÚattention_mask)Úprotein_input_idsÚprotein_attention_maskr\   r]   )Údata)r   r   r   rF   rG   ÚlistÚtuplerO   r+   rM   Ú	TypeErrorÚtypeÚanyr3   r?   r   )	r   r.   r@   r   r   r   r<   r2   Útext_tokenss	            r   Ú__call__zEvollaProcessor.__call__W   s  € ð> Ð˜}Ð4ÝÐRÑSÔSÐSà3EÐ3QÐ/Ð/ÐW[ÔWnÐØ-<Ð-H˜/˜/ÈdÔNbˆõ �h¥Ñ%Ô%ð 	"Ø �zˆHå�m¥d­E ]Ñ3Ô3ð 	,½JÀ}ÐUVÔGWÕZ^Õ`eÐYfÑ<gÔ<gð 	,Ø*˜OˆMå�h¥¥u Ñ.Ô.ð 	vµsÐ:aÐ:aÐX`Ð:aÑ:aÔ:aÑ7aÔ7að 	vÝÐtÑuÔuÐuÝ�h¥¥u Ñ.Ô.ð 	µsð ;
ð ;
ØDLð;
ñ ;
ô ;
ñ 8
ô 8
ð 	õ ð'Ø—9’9Õ/Ñ0Ô0ð'ð 'à$ð'ð 'ñô ð õ �m¥d­E ]Ñ3Ô3ð 	Ø)ð ð �Ý! (­Tµ5¨MÑ:Ô:ð uÝ#Ð$sÕbfÐgoÑbpÔbpÐ$sÐ$sÐ$sÑtÔtÐtÝÐAÐA¸ÐAÑAÔAÑAÔAð Ý$ð Añô ð õ Ð<Ð<°8Ð<Ñ<Ô<Ñ<Ô<ð Åð Dð DØBJðDñ Dô Dñ Aô Að õ %ð/Ø$,ð/ð /ñô ð ððõ ØoÕY]Ð^kÑYlÔYlÐoÐoÐoñô ð ð ×)Ò)¨(Ð4FÑGÔGˆ	à×'Ò'¨°ÑGÔGˆåà%.¨{Ô%;Ø*3Ð4DÔ*EØ(¨Ô5Ø"-Ð.>Ô"?ð	ð ð
ñ 
ô 
ð 	
r   c                 ó&   —  | j         j        |i |¤ŽS rD   )r   Úbatch_decode©r   Úargsr   s      r   ri   zEvollaProcessor.batch_decode®   s   € Ø*ˆtŒ~Ô*¨DÐ;°FÐ;Ð;Ð;r   c                 ó&   —  | j         j        |i |¤ŽS rD   )r   Údecoderj   s      r   rm   zEvollaProcessor.decode±   s   € Ø$ˆtŒ~Ô$ dÐ5¨fÐ5Ð5Ð5r   c                 ó&   —  | j         j        |i |¤ŽS rD   )r   ri   rj   s      r   Úprotein_batch_decodez$EvollaProcessor.protein_batch_decode´   s   € Ø2ˆtÔ%Ô2°DÐC¸FÐCÐCÐCr   c                 ó&   —  | j         j        |i |¤ŽS rD   )r   rm   rj   s      r   Úprotein_decodezEvollaProcessor.protein_decode·   s   € Ø,ˆtÔ%Ô,¨dÐ=°fÐ=Ð=Ð=r   )Nr   r   )r   )r   )NNNN)Ú__name__Ú
__module__Ú__qualname__r   r3   Úintr?   r   ra   rG   rg   ri   rm   ro   rq   Ú__classcell__)r   s   @r   r
   r
      sH  ø€ € € € € ð/ð /ð /ð /ð /ð /ð(ð ð ð ð   #ðð ð ðð ð ð ð0 ð .2Ø>BØ)-Ø&*ðT
ð T
à�t”*˜tÑ# dÑ*ðT
ð ˜D œJÔ'¨$¨t¬*Ñ4°tÑ;ðT
ð   $™Jð	T
ð
 ˜t™ðT
ð T
ð T
ñ „^ðT
ðl<ð <ð <ð6ð 6ð 6ðDð Dð Dð>ð >ð >ð >ð >ð >ð >r   r
   N)
Ú__doc__Úfeature_extraction_utilsr   Úprocessing_utilsr   Úutilsr   rM   r
   Ú__all__r   r   r   ú<module>r|      s°   ððð ð 5Ð 4Ð 4Ð 4Ð 4Ð 4ðð ð ð ð ð ð $Ð #Ð #Ð #Ð #Ð #ð 3Ð2Ð2Ð ð ð[>ð [>ð [>ð [>ð [>�nñ [>ô [>ñ „ð[>ð| Ð
€€€r   