Ë
    T^(hE  ã                   óT   — d Z ddlmZmZ ddlZddlmZ ddlm	Z	  G d„ de«      Z
dgZy)	z)
Text/audio processor class for MusicGen
é    )ÚListÚOptionalNé   )ÚProcessorMixin)Úto_numpyc                   óp   ‡ — e Zd ZdZdZdZˆ fd„Zdd„Zd„ Zd„ Z	d„ Z
dd	ed
eej                     fd„Zˆ xZS )ÚMusicgenProcessoral  
    Constructs a MusicGen processor which wraps an EnCodec feature extractor and a T5 tokenizer into a single processor
    class.

    [`MusicgenProcessor`] offers all the functionalities of [`EncodecFeatureExtractor`] and [`TTokenizer`]. See
    [`~MusicgenProcessor.__call__`] and [`~MusicgenProcessor.decode`] for more information.

    Args:
        feature_extractor (`EncodecFeatureExtractor`):
            An instance of [`EncodecFeatureExtractor`]. The feature extractor is a required input.
        tokenizer (`T5Tokenizer`):
            An instance of [`T5Tokenizer`]. The tokenizer is a required input.
    ÚEncodecFeatureExtractor)ÚT5TokenizerÚT5TokenizerFastc                 óV   •— t         ‰| �  ||«       | j                  | _        d| _        y )NF)ÚsuperÚ__init__Úfeature_extractorÚcurrent_processorÚ_in_target_context_manager)Úselfr   Ú	tokenizerÚ	__class__s      €ún/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/musicgen/processing_musicgen.pyr   zMusicgenProcessor.__init__-   s)   ø€ Ü‰ÑÐ*¨IÔ6Ø!%×!7Ñ!7ˆÔØ*/ˆÕ'ó    c                 ó>   — | j                   j                  |||¬«      S )N)ÚtaskÚlanguageÚno_timestamps)r   Úget_decoder_prompt_ids)r   r   r   r   s       r   r   z(MusicgenProcessor.get_decoder_prompt_ids2   s   € Ø�~‰~×4Ñ4¸$ÈÐanÐ4ÓoÐor   c                 ó’  — | j                   r | j                  |i |¤ŽS |j                  dd«      }|j                  dd«      }|j                  dd«      }t        |«      dkD  r
|d   }|dd }|€|€t	        d«      ‚|� | j
                  |fi |¤Ž}|� | j                  |g|¢­d|i|¤Ž}|€S |€S d   d<   d	|v r|d	   |d	<   |S )
a  
        Forwards the `audio` argument to EncodecFeatureExtractor's [`~EncodecFeatureExtractor.__call__`] and the `text`
        argument to [`~T5Tokenizer.__call__`]. Please refer to the docstring of the above two methods for more
        information.
        ÚaudioNÚsampling_rateÚtextr   é   zAYou need to specify either an `audio` or `text` input to process.Úinput_valuesÚpadding_mask)r   r   ÚpopÚlenÚ
ValueErrorr   r   )r   ÚargsÚkwargsr   r   r    ÚinputsÚaudio_inputss           r   Ú__call__zMusicgenProcessor.__call__5   s  € ð ×*Ò*Ø)�4×)Ñ)¨4Ð:°6Ñ:Ð:à—
‘
˜7 DÓ)ˆØŸ
™
 ?°DÓ9ˆØ�z‰z˜& $Ó'ˆÜˆt‹9�qŠ=Ø˜‘GˆEØ˜˜�8ˆDàˆ=˜T˜\ÜÐ`ÓaÐaàÐØ#�T—^‘^ DÑ3¨FÑ3ˆFàÐØ1˜4×1Ñ1°%Ðf¸$ÒfÈmÐfÐ_eÑfˆLàˆ=ØˆMàˆ\ØÐð &2°.Ñ%AˆF�>Ñ"Ø Ñ-Ø)5°nÑ)E��~Ñ&ØˆMr   c                 óÜ   — |j                  dd«      }|j                  dd«      }t        |«      dkD  r
|d   }|dd }|�| j                  ||¬«      S  | j                  j                  |i |¤ŽS )ai  
        This method is used to decode either batches of audio outputs from the MusicGen model, or batches of token ids
        from the tokenizer. In the case of decoding token ids, this method forwards all its arguments to T5Tokenizer's
        [`~PreTrainedTokenizer.batch_decode`]. Please refer to the docstring of this method for more information.
        r   Nr#   r   r!   )r#   )r$   r%   Ú_decode_audior   Úbatch_decode)r   r'   r(   Úaudio_valuesr#   s        r   r.   zMusicgenProcessor.batch_decode[   s{   € ð —z‘z '¨4Ó0ˆØ—z‘z .°$Ó7ˆäˆt‹9�qŠ=Ø ™7ˆLØ˜˜�8ˆDàÐ#Ø×%Ñ% lÀÐ%ÓNÐNà.�4—>‘>×.Ñ.°Ð?¸Ñ?Ð?r   c                 ó:   —  | j                   j                  |i |¤ŽS )zµ
        This method forwards all its arguments to T5Tokenizer's [`~PreTrainedTokenizer.decode`]. Please refer to the
        docstring of this method for more information.
        )r   Údecode)r   r'   r(   s      r   r1   zMusicgenProcessor.decodem   s    € ð
 %ˆt�~‰~×$Ñ$ dÐ5¨fÑ5Ð5r   r#   Úreturnc                 óÞ  — t        |«      }|j                  \  }}}|€t        |«      S t        |«      }||j                  d   z
  }d| j                  j                  z
  }t        j                  |dd|ffd|¬«      }|j                  «       }t        |«      D ]S  }t        j                  ||   «      ||   ddd…f   | j                  j                  k7     }	|	j                  |d«      ||<   ŒU |S )zn
        This method strips any padding from the audio values to return a list of numpy audio arrays.
        Néÿÿÿÿr!   )r   r   r   Úconstant)Úconstant_values)r   ÚshapeÚlistr   Úpadding_valueÚnpÚpadÚtolistÚrangeÚasarrayÚreshape)
r   r/   r#   ÚbszÚchannelsÚseq_lenÚ
differencer9   ÚiÚsliced_audios
             r   r-   zMusicgenProcessor._decode_audiot   s  € ô   Ó-ˆØ!-×!3Ñ!3ÑˆˆX�wàÐÜ˜Ó%Ð%ä Ó-ˆð ˜|×1Ñ1°"Ñ5Ñ5ˆ
Ø˜D×2Ñ2×@Ñ@Ñ@ˆÜ—v‘v˜l¨V°a¸°_Ð,EÀzÐcpÔqˆà#×*Ñ*Ó,ˆÜ�s“ò 	AˆAÜŸ:™: l°1¡oÓ6Ø˜Q‘ ¢a Ñ(¨D×,BÑ,B×,PÑ,PÑPñˆLð +×2Ñ2°8¸RÓ@ˆL˜ŠOð		Að Ðr   )NNT)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úfeature_extractor_classÚtokenizer_classr   r   r+   r.   r1   r   r   r:   Úndarrayr-   Ú__classcell__)r   s   @r   r	   r	      sP   ø„ ñð 8ÐØ8€Oô0ó
pò$òL@ò$6ñ¸ð ÈDÐQS×Q[ÑQ[ÑL\÷ r   r	   )rI   Útypingr   r   Únumpyr:   Úprocessing_utilsr   Úutilsr   r	   Ú__all__© r   r   ú<module>rT      s1   ðñ÷ "ã å .Ý ôr˜ô rðj Ð
�r   