Ë
    S^(hÞ(  ã                   óÆ   — d dl mZmZmZ ddlmZ ddlmZ ddlm	Z	m
Z
mZmZmZ ddlmZmZ  G d„ ded	¬
«      Z G d„ de	d	¬
«      Z G d„ de
d	¬
«      Z G d„ de«      ZdgZy)é    )ÚListÚOptionalÚUnioné   )ÚBatchFeature)Ú
ImageInput)ÚImagesKwargsÚProcessingKwargsÚProcessorMixinÚ
TextKwargsÚUnpack)ÚPreTokenizedInputÚ	TextInputc                   ó   — e Zd ZU eed<   y)ÚEmu3TextKwargsÚreturn_for_image_generationN)Ú__name__Ú
__module__Ú__qualname__ÚboolÚ__annotations__© ó    úf/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/emu3/processing_emu3.pyr   r      s   … Ø!%Ô%r   r   F)Útotalc                   ó"   — e Zd ZU eed<   eed<   y)ÚEmu3ImagesKwargsÚratioÚ
image_areaN)r   r   r   Ústrr   Úintr   r   r   r   r      s   … ØƒJØ„Or   r   c                   ó6   — e Zd ZU eed<   eed<   ddidddœdœZy	)
ÚEmu3ProcessorKwargsÚtext_kwargsÚimages_kwargsr   Fz1:1i é )r   r   )r$   r%   N)r   r   r   r   r   r   Ú	_defaultsr   r   r   r#   r#   "   s.   … ØÓØ#Ó#ð *¨5ð
ð Ø ñ
ñ	�Ir   r#   c                   ó¸   ‡ — e Zd ZdZddgZdgZdZdZ	 dˆ fd„	Z	 	 	 	 dde	e
   d	e	eeeee   ee   f      d
ee   defd„Zd„ Zde
fd„Zd„ Zd„ Zed„ «       Zˆ xZS )ÚEmu3Processoraª  
    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                 ó  •— |j                   | _         |j                  | _        |j                  | _        |j
                  | _        |j                  | _        |j                  | _        d| _	        t        ‰| �-  |||¬«       y )Né   )r+   )Úimage_tokenÚ	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)   r*   r+   ÚkwargsÚ	__class__s        €r   r<   zEmu3Processor.__init__F   ss   ø€ ð %×0Ñ0ˆÔØ!*×!4Ñ!4ˆÔØ(×2Ñ2ˆÔØ'0×'DÑ'DˆÔ$Ø"×,Ñ,ˆŒØ"×,Ñ,ˆŒØ !ˆÔÜ‰Ñ˜¨)À=ÐÕQr   ÚimagesÚtextr>   Úreturnc                 óŠ  — t        |t        «      r|g}n.t        |t        «      st        |d   t        «      st        d«      ‚ | j                  t
        fd| j                  j                  i|¤Ž}|d   j                  dd«      }|d   j                  dd	«      }|d   j                  d
d	«      }	|r|�t        d«      ‚|s|€|€t        d«      ‚i }
| j                  › }| j                  › | j                  › �}|�s|�� | j                  |fi |d   ¤Ž}
t        |
j                  «      }g }|D ]¯  }| j                   |v rŽt#        |«      }|\  }}|| j$                  z  }|| j$                  z  }||dz   z  }|› |› d|› | j&                  › d|z  › |› �}|j)                  | j                   |d«      }| j*                  › |› �}| j                   |v rŒŽ|j-                  |«       Œ± |D �cg c]  }|j)                  d| j                   «      ‘Œ  }}nj|rh| j/                  ||	| j$                  «      \  }}|› |› d|› | j&                  › �}|D �cg c]  }| j*                  › |› |› �‘Œ }}||ggt1        |«      z  |
d<    | j                  |fi |d   ¤Ž} |j2                  di |
¤Ž t5        ||d   j                  dd	«      ¬«      S c c}w c c}w )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Úcommon_kwargsÚreturn_tensors)ÚdataÚtensor_typer   )Ú
isinstancer    ÚlistÚ	TypeErrorÚ_merge_kwargsr#   r*   Úinit_kwargsÚpopÚ
ValueErrorr3   r8   r5   r)   ÚiterrG   r1   Únextr:   r7   Úreplacer9   ÚappendÚcalculate_generate_sizeÚlenÚupdater   )r=   r@   rA   ÚaudioÚvideosr>   Úoutput_kwargsr   r   r   Úimage_featuresÚimage_start_tokensÚimage_end_tokensrG   Úprompt_stringsÚsampleÚ
image_sizeÚheightÚwidthÚimage_seq_lengthÚimage_placeholderÚimage_promptrJ   s                          r   Ú__call__zEmu3Processor.__call__V   sC  € ôT �dœCÔ Ø�6‰DÜ˜D¤$Ô'´
¸4À¹7ÄCÔ0HÜÐ_Ó`Ð`à*˜×*Ñ*Üñ
à"&§.¡.×"<Ñ"<ð
ð ñ
ˆð
 '4°MÑ&B×&FÑ&FÐGdÐfkÓ&lÐ#Ø˜oÑ.×2Ñ2°7¸DÓAˆØ" ?Ñ3×7Ñ7¸ÀdÓKˆ
á&¨6Ð+=ÜÐfÓgÐgá*¨t¨|ÀÀÜÐnÓoÐoàˆØ $× 6Ñ 6Ð7ÐØ"Ÿn™nÐ-¨d×.BÑ.BÐ-CÐDÐò +¨vÑ/AØ1˜T×1Ñ1°&Ñ[¸MÈ/Ñ<ZÑ[ˆNÜ˜~×9Ñ9Ó:ˆKàˆNØò .�Ø×&Ñ&¨&Ñ0Ü!% kÓ!2�JØ$.‘M�F˜EØ# t×'<Ñ'<Ñ<�FØ! T×%:Ñ%:Ñ:�EØ'-°¸±Ñ';Ð$à+=Ð*>¸v¸hÀaÈÀwÈt×OkÑOkÐNlÐm|ð  @Pñ  nPð  mQð  Rbð  Qcð  )dÐ%Ø#Ÿ^™^¨D×,<Ñ,<Ð>OÐQRÓS�FØ $§¡Ð/°¨xÐ8�Fð ×&Ñ&¨&Ò0ð ×%Ñ% fÕ-ð.ð UcÖcÈ&�F—N‘N ?°D×4DÑ4DÕEÐcˆDÑcñ )Ø ×8Ñ8¸À
ÈD×LaÑLaÓb‰MˆF�EØ0Ð1°&°¸¸5¸'À$×B^ÑB^ÐA_Ð`ˆLØLPÖQÀ&�t—~‘~Ð& v h¨|¨nÒ=ÐQˆDÐQØ.4°e¨_Ð,=ÄÀDÃ	Ñ,IˆN˜=Ñ)ð ˆt�~‰~˜dÑC m°MÑ&BÑCˆØˆ�‰Ñ%�nÒ%ä °=ÀÑ3Q×3UÑ3UÐVfÐhlÓ3mÔnÐnùò dùò Rs   Ç##J;ÉK c                 óÐ   — t        t        |j                  d«      «      \  }}||z  }||z  dz  }t        t        ||z  |z  «      «      }t        t        ||z  |z  «      «      }	||	fS )Nú:g      à?)Úmapr!   ÚsplitÚround)
r=   r   r   Úspatial_factorrd   rc   Úcurrent_areaÚtarget_ratioÚtoken_heightÚtoken_widths
             r   rW   z%Emu3Processor.calculate_generate_size¹   sp   € ÜœC §¡¨SÓ!1Ó2‰ˆˆvØ˜v‘~ˆØ" \Ñ1°cÑ9ˆäœ5 ¨,Ñ!6¸Ñ!GÓHÓIˆÜœ% ¨Ñ 4°~Ñ EÓFÓGˆØ˜[Ð(Ð(r   c                 ó<   —  | j                   j                  |fi |¤ŽS ©N)r)   Úpostprocess)r=   r@   r>   s      r   ru   zEmu3Processor.postprocessÂ   s    € Ø/ˆt×#Ñ#×/Ñ/°ÑA¸&ÑAÐAr   c                 ó:   —  | j                   j                  |i |¤ŽS )zÁ
        This method forwards all its arguments to Emu3TokenizerFast's [`~PreTrainedTokenizer.batch_decode`]. Please
        refer to the docstring of this method for more information.
        )r*   Úbatch_decode©r=   Úargsr>   s      r   rw   zEmu3Processor.batch_decodeÅ   s    € ð
 +ˆt�~‰~×*Ñ*¨DÐ;°FÑ;Ð;r   c                 ó:   —  | j                   j                  |i |¤ŽS )z»
        This method forwards all its arguments to Emu3TokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
        the docstring of this method for more information.
        )r*   Údecoderx   s      r   r{   zEmu3Processor.decodeÌ   s    € ð
 %ˆt�~‰~×$Ñ$ dÐ5¨fÑ5Ð5r   c                 óœ   — | j                   j                  }| j                  j                  }t        t        j                  ||z   «      «      S rt   )r*   Úmodel_input_namesr)   rM   ÚdictÚfromkeys)r=   Útokenizer_input_namesÚimage_processor_input_namess      r   r}   zEmu3Processor.model_input_namesÓ   s?   € à $§¡× @Ñ @ÐØ&*×&:Ñ&:×&LÑ&LÐ#Ü”D—M‘MÐ"7Ð:UÑ"UÓVÓWÐWr   rt   )NNNN)r   r   r   Ú__doc__Ú
attributesÚvalid_kwargsÚtokenizer_classÚimage_processor_classr<   r   r   r   r   r   r   r   r#   r   rh   rW   ru   rw   r{   Úpropertyr}   Ú__classcell__)r?   s   @r   r(   r(   0   sÒ   ø„ ñð  $ [Ð1€JØ#Ð$€LØ<€OØ0Ðð õ	Rð$ (,ØhlØØñaoà˜Ñ$ðaoð �u˜YÐ(9¸4À	¹?ÈDÐQbÑLcÐcÑdÑeðaoð Ð,Ñ-ðaoð 
óaoòF)ð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ô&�Z uõ &ô�|¨5õ ô
Ð*°%õ ôgX�Nô gXðT Ð
�r   