§
    ‚Štj8'  ã                   ó|  — d dl Zd dlZd dlmc mZ ddlmZ ddl	m
Z
mZ ddlmZmZmZmZ ddlmZmZmZ ddlmZmZ ddlmZ  ej        e¦  «        Z G d	„ d
ed¬¦  «        ZdZd„  ed¦  «        D ¦   «         d„  ed¦  «        D ¦   «         z   Z e ed¬¦  «         G d„ de¦  «        ¦   «         ¦   «         Z!dgZ"dS )é    Né   )ÚBatchFeature)Ú
ImageInputÚmake_nested_list_of_images)ÚMultiModalDataÚProcessingKwargsÚProcessorMixinÚUnpack)Ú
AddedTokenÚPreTokenizedInputÚ	TextInput)Úauto_docstringÚlogging)Úrequiresc                   ó$   — e Zd ZddddœddidœZdS )	ÚPI0ProcessorKwargsÚ
max_lengthé0   Úright)Úpaddingr   Úpadding_sideÚreturn_tensorsÚpt)Útext_kwargsÚcommon_kwargsN)Ú__name__Ú
__module__Ú__qualname__Ú	_defaults© ó    úd/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/transformers/models/pi0/processing_pi0.pyr   r   $   s9   € € € € € ð $ØØ#ð
ð 
ð
 +¨DÐ1ðð €I€I€Ir!   r   F)Útotalz<image>c                 ó   — g | ]	}d |d›d�‘Œ
S )z<locz0>4ú>r    ©Ú.0Úis     r"   ú
<listcomp>r)   0   s"   € Ð5Ð5Ð5 A��q����Ð5Ð5Ð5r!   i   c                 ó   — g | ]	}d |d›d�‘Œ
S )z<segz0>3r%   r    r&   s     r"   r)   r)   0   s"   € Ð8]Ð8]Ð8]ÈQ¸À¸¸¸¸Ð8]Ð8]Ð8]r!   é€   )ÚvisionÚtorch)Úbackendsc                   ó8  ‡ — e Zd Zdˆ fd„	Ze	 	 	 ddeee         z  eee                  z  dz  deez  ee         z  ee         z  dz  dee	j
        z  ej        z  dz  dee	j
        z  ej        z  dz  dee         defd	„¦   «         Zdd
„Zeˆ fd„¦   «         Zˆ xZS )ÚPI0ProcessorNc                 ó>  •— |j         d         |j         d         c| _        | _        |                     dg d¢¦  «        }|                     dg d¢¦  «        }|                     dg d¢¦  «        }|                     d	g d
¢¦  «        }t	          j        |¦  «        | _        t	          j        |¦  «        | _        t	          j        |¦  «        | _        t	          j        |¦  «        | _	        |                     dd¦  «        | _
        |                     dd¦  «        | _        t          |d¦  «        st          d¦  «        ‚|j        | _        t          |d¦  «        s]t          t           dd¬¦  «        }	d|	gi}
|                     |
¦  «         |                     t           ¦  «        | _        t           | _        n|j        | _        |j        | _        |                     t,          ¦  «         d|_        d|_        t3          ¦   «                              |||¬¦  «         d S )NÚheightÚwidthÚ
state_mean)gù g³ês¥¿grŠŽäò¢?g•Ô	h"lê?g‡§WÊ2D@g\ AñcÌá¿gZd;ßOÅ¿gB>èÙ¬úœ?g“©‚QI�¿Ú	state_std)gt$—ÿ�~»?gL¦
F%uÂ?g.ÿ!ýöuÐ?g/n£¼Ö?gëâ6Àó?g¶óýÔxéÖ?gÌ]KÈ=‹?gF%uš‹?Úactions_mean)gÂ&S£’?gâX·Ñ ®?gW[±¿ìž¬¿gHPüs×r?gàœ¥½Ág?gÒ Þ	Š¿gHPüs·¿Úactions_std)g®GázÒ?g`åÐ"ÛùÖ?gÁ9#J{ƒ×?gvOjM£?g>yX¨5Í«?g46<½R¶?gèj+ö—Ýï?Úmax_state_dimé    Ú
chunk_sizeé2   Úimage_seq_lengthz;Image processor is missing an `image_seq_length` attribute.Úimage_tokenFT)Ú
normalizedÚspecialÚadditional_special_tokens)Úchat_template)Úsizer2   r3   Úgetr-   Útensorr4   r5   r6   r7   r8   r:   ÚhasattrÚ
ValueErrorr<   r   ÚIMAGE_TOKENÚadd_special_tokensÚconvert_tokens_to_idsÚimage_token_idr=   Ú
add_tokensÚEXTRA_TOKENSÚadd_bos_tokenÚadd_eos_tokenÚsuperÚ__init__)ÚselfÚimage_processorÚ	tokenizerrA   Úkwargsr4   r5   r6   r7   r=   Útokens_to_addÚ	__class__s              €r"   rP   zPI0Processor.__init__6   sñ  ø€ Ø"1Ô"6°xÔ"@À/ÔBVÐW^ÔB_ÐˆŒ�T”ZØ—Z’Z Ð.rÐ.rÐ.rÑsÔsˆ
Ø—J’J˜{Ð,lÐ,lÐ,lÑmÔmˆ	Ø—z’z .Ð2mÐ2mÐ2mÑnÔnˆØ—j’j Ð0hÐ0hÐ0hÑiÔiˆåœ, zÑ2Ô2ˆŒÝœ iÑ0Ô0ˆŒÝ!œL¨Ñ6Ô6ˆÔÝ œ<¨Ñ4Ô4ˆÔØ#ŸZšZ¨¸Ñ<Ô<ˆÔØ Ÿ*š* \°2Ñ6Ô6ˆŒÝ�Ð(:Ñ;Ô;ð 	\ÝÐZÑ[Ô[Ð[à /Ô @ˆÔå�y -Ñ0Ô0ð 	5Ý$¥[¸UÈDÐQÑQÔQˆKØ8¸;¸-ÐHˆMØ×(Ò(¨Ñ7Ô7Ð7Ø"+×"AÒ"AÅ+Ñ"NÔ"NˆDÔÝ*ˆDÔÐà"+Ô":ˆDÔØ(Ô4ˆDÔà×Ò�\Ñ*Ô*Ð*Ø"'ˆ	ÔØ"'ˆ	Ôå‰Œ×Ò˜¨)À=ÐÑQÔQÐQÐQÐQr!   ÚimagesÚtextÚactionsÚstaterT   Úreturnc                 óª  —  | j         t          fd| j        j        i|¤Ž}|€t                               d¦  «         d}t          |t          ¦  «        r|g}t          |¦  «        }t          |¦  «        t          |¦  «        k    r0t          dt          |¦  «        › dt          |¦  «        › d�¦  «        ‚|d                              d	d¦  «        }|d
                              d	d¦  «         g }	t          ||¦  «        D ]J\  }
}| j        | j        z  t          |¦  «        z  › | j        j        › |
› d�}
|	                     |
¦  «         ŒK | j        |	fi |d         ¤Ž}t#          d„ |D ¦   «         ¦  «        }t%          j        t          |¦  «        |ft$          j        ¬¦  «        }t%          j        t          |¦  «        |d| j        | j        ¦  «        }t/          |¦  «        D ]B\  }} | j        |fd	di|d
         ¤Ž}t          |¦  «        }d||d|…f<   |d         ||d|…f<   ŒCi |¥||dœ¥}|�‹t%          j        |¦  «        | j        z
  | j        dz   z  }|j        d         | j        k     r*t=          j        |d| j        |j        d         z
  f¦  «        }|                      d| j!        | j        ¦  «        |d<   |�…t%          j        |¦  «        | j"        z
  | j#        dz   z  }|j        d         | j        k     r*t=          j        |d| j        |j        d         z
  f¦  «        }|                      d| j        ¦  «        |d<   tI          ||¬¦  «        S )aC  
        actions (`list | np.ndarray | torch.Tensor`, *optional*):
            Actions to be predicted by the model. If provided, padding, mean and std normalization will be applied.
        state (`list | np.ndarray | torch.Tensor`, *optional*):
            Robotic states to be predicted by the model. If provided, padding, mean and std normalization will be applied.

        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`. If `suffix`
              is provided, the `input_ids` will also contain the suffix input ids.
            - **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_attention_mask** -- Pixel values padding mask to be fed to a model. Returned when `images` is not `None`.
            - **state** -- Robot state compatible with model if `state` is not None
            - **actions** -- Label-actions compatible with training if `actions` is not None
        Útokenizer_init_kwargsNzPYou are using PI0 without a text prefix. The processor will use an empty prompt.Ú z	Received z image samples for z\ prompts. Each prompt should be associated with one sample (with one or more camera images).r   r   Úimages_kwargsú
c              3   ó4   K  — | ]}t          |¦  «        V — Œd S ©N)Úlen)r'   Úsample_imagess     r"   ú	<genexpr>z(PI0Processor.__call__.<locals>.<genexpr>“   s*   è è € ÐUÐU°]�c -Ñ0Ô0ÐUÐUÐUÐUÐUÐUr!   )Údtyper   r   TÚpixel_values)rg   Úpixel_attention_maskg:Œ0âŽyE>éÿÿÿÿr   rY   rZ   )ÚdataÚtensor_type)%Ú_merge_kwargsr   rS   Úinit_kwargsÚloggerÚwarning_onceÚ
isinstanceÚstrr   rc   rF   ÚpopÚzipr=   r<   Ú	bos_tokenÚappendÚmaxr-   ÚzerosÚboolr2   r3   Ú	enumeraterR   rD   r6   r7   Úshaper8   ÚFÚpadÚviewr:   r4   r5   r   )rQ   rW   rX   rY   rZ   rT   Úoutput_kwargsÚbatched_imagesr   Úprompt_stringsÚsampleÚ
image_listÚtext_inputsÚmax_num_camerasrh   Úpadded_pixel_valuesÚbatchrd   Ú	processedÚnum_camerasÚreturn_datas                        r"   Ú__call__zPI0Processor.__call__X   sÏ  € ð8 +˜Ô*Ýð
ð 
Ø6:´nÔ6Pð
ØTZð
ð 
ˆð ˆ<Ý×ÒÐ rÑsÔsÐsØˆDå�d�CÑ Ô ð 	Ø�6ˆDå3°FÑ;Ô;ˆÝˆ~ÑÔ¥# d¡)¤)Ò+Ð+Ýðe�C Ñ/Ô/ð eð eÅCÈÁIÄIð eð eð eñô ð ð
 ' }Ô5×9Ò9Ð:JÈDÑQÔQˆØ�oÔ&×*Ò*Ð+;¸TÑBÔBÐBàˆÝ"% d¨NÑ";Ô";ð 	*ð 	*ÑˆF�JàÔ# dÔ&;Ñ;½cÀ*¹o¼oÑMÐsÈtÌ~ÔOgÐsÐioÐsÐsÐsð ð ×!Ò! &Ñ)Ô)Ð)Ð)à$�d”n ^ÐTÐT°}À]Ô7SÐTÐTˆõ ÐUÐUÀnÐUÑUÔUÑUÔUˆÝ$œ{­C°Ñ,?Ô,?ÀÐ+QÕY^ÔYcÐdÑdÔdÐÝ#œk­#¨nÑ*=Ô*=¸ÐPQÐSWÔS^Ð`dÔ`jÑkÔkÐå$-¨nÑ$=Ô$=ð 	Qð 	QÑ ˆE�=Ø,˜Ô,¨]ÐrÐrÈ4ÐrÐS`ÐapÔSqÐrÐrˆIå˜mÑ,Ô,ˆKØ8<Ð  ¨¨¨Ð!4Ñ5Ø7@ÀÔ7PÐ  |¨ |Ð 3Ñ4Ð4ð
Øð
à/Ø$8ð
ð 
ð 
ˆð ÐÝ”| GÑ,Ô,¨tÔ/@Ñ@ÀTÔEUÐX]ÑE]Ñ^ˆGØŒ}˜RÔ  4Ô#5Ò5Ð5Ýœ% ¨!¨TÔ-?À'Ä-ÐPRÔBSÑ-SÐ)TÑUÔU�Ø%,§\¢\°"°d´oÀtÔGYÑ%ZÔ%ZˆK˜	Ñ"àÐÝ”\ %Ñ(Ô(¨4¬?Ñ:¸t¼~ÐPUÑ?UÑVˆEØŒ{˜2Œ Ô!3Ò3Ð3Ýœ˜e a¨Ô);¸e¼kÈ"¼oÑ)MÐ%NÑOÔO�Ø#(§:¢:¨b°$Ô2DÑ#EÔ#EˆK˜Ñ å ¸.ÐIÑIÔIÐIr!   c                 ó¨   — i }|�C| j         gt          |¦  «        z  }dgt          |¦  «        z  }|                     ||dœ¦  «         t          di |¤ŽS )a¸  
        Computes the number of placeholder tokens needed for multimodal inputs with the given sizes.

        Args:
            image_sizes (list[list[str]], *optional*):
                The input sizes formatted as (height, width) per each image.
        Returns:
            `MultiModalData`: A `MultiModalData` object holding number of tokens per each of the provided
            input modalities, along with other useful data.
        Né   )Únum_image_tokensÚnum_image_patchesr    )r<   rc   Úupdater   )rQ   Úimage_sizesrT   Úvision_datar�   rŽ   s         r"   Ú_get_num_multimodal_tokensz'PI0Processor._get_num_multimodal_tokens²   so   € ð ˆØÐ"Ø $Ô 5Ð6½¸[Ñ9IÔ9IÑIÐØ!" ¥c¨+Ñ&6Ô&6Ñ 6ÐØ×ÒÐ4DÐ[lÐmÐmÑnÔnÐnÝÐ,Ð, Ð,Ð,Ð,r!   c                 ó2   •— t          ¦   «         j        dgz   S )Nrh   )rO   Úmodel_input_names)rQ   rV   s    €r"   r”   zPI0Processor.model_input_namesÄ   s   ø€ å‰wŒwÔ(Ð,BÐ+CÑCÐCr!   )NNNrb   )r   r   r   rP   r   r   Úlistr   r   ÚnpÚndarrayr-   ÚTensorr
   r   r   rŠ   r’   Úpropertyr”   Ú__classcell__)rV   s   @r"   r0   r0   3   ss  ø€ € € € € ð Rð  Rð  Rð  Rð  Rð  RðD ð bfØ;?Ø9=ðWJð WJà˜T *Ô-Ñ-°°T¸*Ô5EÔ0FÑFÈÑMðWJð Ð+Ñ+¨d°9¬oÑ=ÀÐEVÔ@WÑWÐZ^Ñ^ðWJð ˜œ
Ñ" U¤\Ñ1°DÑ8ð	WJð
 �b”jÑ  5¤<Ñ/°$Ñ6ðWJð Ð+Ô,ðWJð 
ðWJð WJð WJñ „^ðWJðr-ð -ð -ð -ð$ ðDð Dð Dð Dñ „XðDð Dð Dð Dð Dr!   r0   )#Únumpyr–   r-   Útorch.nn.functionalÚnnÚ
functionalr{   Úfeature_extraction_utilsr   Úimage_utilsr   r   Úprocessing_utilsr   r   r	   r
   Útokenization_utils_baser   r   r   Úutilsr   r   Úutils.import_utilsr   Ú
get_loggerr   rn   r   rG   ÚrangerL   r0   Ú__all__r    r!   r"   ú<module>r¨      sÄ  ðð* Ð Ð Ð Ø €€€Ø Ð Ð Ð Ð Ð Ð Ð Ð à 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø AÐ AÐ AÐ AÐ AÐ AÐ AÐ AØ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XØ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OØ ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø *Ð *Ð *Ð *Ð *Ð *ð 
ˆÔ	˜HÑ	%Ô	%€ðð ð ð ð Ð)°ð ñ ô ð ð €Ø5Ð5¨¨¨t©¬Ð5Ñ5Ô5Ð8]Ð8]ÐRWÐRWÐX[ÑR\ÔR\Ð8]Ñ8]Ô8]Ñ]€ð Ø	€Ð&Ð'Ñ'Ô'ðQDð QDð QDð QDð QD�>ñ QDô QDñ (Ô'ñ „ðQDðh Ð
€€€r!   