
    Uh9                         d Z ddlZddlmZmZmZ ddlZddlm	Z	 ddl
mZ ddlmZmZmZ ddlmZ dd	lmZ  ed
       G d de             ZdgZy)zProcessor class for Pop2Piano.    N)ListOptionalUnion   )BatchFeature)ProcessorMixin)BatchEncodingPaddingStrategyTruncationStrategy)
TensorType)requires)essentialibrosapretty_midiscipytorch)backendsc                   R    e Zd ZdZddgZdZdZ fdZ	 	 	 	 	 	 	 	 	 	 ddee	j                  ee   ee	j                     f   deeeee   f      d	ed
ee   deeef   deeeef   deeeef   dee   dee   dedeeef   fdZ	 ddededefdZed        Z fdZed        Z xZS )Pop2PianoProcessora  
    Constructs an Pop2Piano processor which wraps a Pop2Piano Feature Extractor and Pop2Piano Tokenizer into a single
    processor.

    [`Pop2PianoProcessor`] offers all the functionalities of [`Pop2PianoFeatureExtractor`] and [`Pop2PianoTokenizer`].
    See the docstring of [`~Pop2PianoProcessor.__call__`] and [`~Pop2PianoProcessor.decode`] for more information.

    Args:
        feature_extractor (`Pop2PianoFeatureExtractor`):
            An instance of [`Pop2PianoFeatureExtractor`]. The feature extractor is a required input.
        tokenizer (`Pop2PianoTokenizer`):
            An instance of ['Pop2PianoTokenizer`]. The tokenizer is a required input.
    feature_extractor	tokenizerPop2PianoFeatureExtractorPop2PianoTokenizerc                 &    t         |   ||       y N)super__init__)selfr   r   	__class__s      /var/www/catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/transformers/models/pop2piano/processing_pop2piano.pyr   zPop2PianoProcessor.__init__1   s    *I6    audiosampling_ratesteps_per_beatresamplenotespadding
truncation
max_lengthpad_to_multiple_ofverbosereturnc           
          |||t        d      || | j                  d||||d|}| | j                  d|||||	|
d|}|S ||S d   d<   |S )a"  
        This method uses [`Pop2PianoFeatureExtractor.__call__`] method to prepare log-mel-spectrograms for the model,
        and [`Pop2PianoTokenizer.__call__`] to prepare token_ids from notes.

        Please refer to the docstring of the above two methods for more information.
        z{You have to specify at least audios and sampling_rate in order to use feature extractor or notes to use the tokenizer part.)r"   r#   r$   r%   )r&   r'   r(   r)   r*   r+   	token_ids )
ValueErrorr   r   )r   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   kwargsinputsencoded_token_idss                 r    __call__zPop2PianoProcessor.__call__4   s    . Mm3%-3 
 !:+T++ +-!	
 F  . !%%#5! ! =M]m3$$ #4K"@F;Mr!   feature_extractor_outputreturn_midic                 >    | j                   j                  |||      S )z
        This method uses [`Pop2PianoTokenizer.batch_decode`] method to convert model generated token_ids to midi_notes.

        Please refer to the docstring of the above two methods for more information.
        )r.   r5   r6   )r   batch_decode)r   r.   r5   r6   s       r    r8   zPop2PianoProcessor.batch_decoden   s)     ~~**:R`k + 
 	
r!   c                     | j                   j                  }| j                  j                  }t        t        j                  ||z               S r   )r   model_input_namesr   listdictfromkeys)r   tokenizer_input_namesfeature_extractor_input_namess      r    r:   z$Pop2PianoProcessor.model_input_names~   s?     $ @ @(,(>(>(P(P%DMM"7:W"WXYYr!   c                     t         j                  j                  |      rt        d| d      t        j                  |d       t        |   |fi |S )NzProvided path (z#) should be a directory, not a fileT)exist_ok)ospathisfiler0   makedirsr   save_pretrained)r   save_directoryr1   r   s      r    rF   z"Pop2PianoProcessor.save_pretrained   sL    77>>.)~.>>abcc
NT2w&~@@@r!   c                 2     | j                   |fi |} | | S r   )_get_arguments_from_pretrained)clspretrained_model_name_or_pathr1   argss       r    from_pretrainedz"Pop2PianoProcessor.from_pretrained   s%    1s112OZSYZDzr!   )
NN   TNFNNNT)T)__name__
__module____qualname____doc__
attributesfeature_extractor_classtokenizer_classr   r   npndarrayr   floatr   intboolr   strr
   r   r   r	   r4   r8   propertyr:   rF   classmethodrM   __classcell__)r   s   @r    r   r      sx    &{3J9*O7
 CG9=#')-5:;?$(,08RZZed2::.>>?8  c49n 568 	8
 4.8 T:%&8 tS/128 $%7788 SM8 %SM8 8 
|]*	+8| !	
 #/
 	

 

  Z Z
A  r!   r   )rR   rB   typingr   r   r   numpyrV   feature_extraction_utilsr   processing_utilsr   tokenization_utilsr	   r
   r   utilsr   utils.import_utilsr   r   __all__r/   r!   r    <module>rg      sX    % 	 ( (  4 . T T  * 
KLo o Mod  
 r!   