o
    Zh9                     @   s   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
dG dd deZdgZdS )zProcessor class for Pop2Piano.    N)ListOptionalUnion   )BatchFeature)ProcessorMixin)BatchEncodingPaddingStrategyTruncationStrategy)
TensorType)requires)ZessentiaZlibrosaZpretty_midiZscipyZtorch)backendsc                       s  e Zd ZdZddgZdZdZ fd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dZ	
d$dededefddZedd Z fdd Zed!d" Z  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	tokenizerZPop2PianoFeatureExtractorZPop2PianoTokenizerc                    s   t  || d S N)super__init__)selfr   r   	__class__ a/var/www/auris/lib/python3.10/site-packages/transformers/models/pop2piano/processing_pop2piano.pyr   1   s   zPop2PianoProcessor.__init__N   TFaudiosampling_ratesteps_per_beatresamplenotespadding
truncation
max_lengthpad_to_multiple_ofverbosereturnc              	   K   s   |du r|du r|du rt d|dur%|dur%| jd||||d|}|dur8| jd|||||	|
d|}|du r>|S |du sF|du rH|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.
        Nz{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_idsr   )
ValueErrorr   r   )r   r   r   r   r   r   r   r    r!   r"   r#   kwargsZinputsZencoded_token_idsr   r   r   __call__4   s<   
zPop2PianoProcessor.__call__feature_extractor_outputreturn_midic                 C   s   | j j|||d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%   r)   r*   )r   batch_decode)r   r%   r)   r*   r   r   r   r+   n   s   zPop2PianoProcessor.batch_decodec                 C   s"   | j j}| jj}tt|| S r   )r   model_input_namesr   listdictfromkeys)r   Ztokenizer_input_namesZfeature_extractor_input_namesr   r   r   r,   ~   s   z$Pop2PianoProcessor.model_input_namesc                    s>   t j|rtd| dt j|dd t j|fi |S )NzProvided path (z#) should be a directory, not a fileT)exist_ok)ospathisfiler&   makedirsr   save_pretrained)r   Zsave_directoryr'   r   r   r   r5      s   z"Pop2PianoProcessor.save_pretrainedc                 K   s   | j |fi |}| | S r   )Z_get_arguments_from_pretrained)clsZpretrained_model_name_or_pathr'   argsr   r   r   from_pretrained   s   z"Pop2PianoProcessor.from_pretrained)
NNr   TNFNNNT)T)__name__
__module____qualname____doc__
attributesZfeature_extractor_classZtokenizer_classr   r   npZndarrayr   floatr   intboolr   strr	   r
   r   r   r(   r+   propertyr,   r5   classmethodr8   __classcell__r   r   r   r   r      sh    
	


>

r   )r<   r1   typingr   r   r   numpyr>   Zfeature_extraction_utilsr   Zprocessing_utilsr   Ztokenization_utilsr   r	   r
   utilsr   Zutils.import_utilsr   r   __all__r   r   r   r   <module>   s   
r