+
    œ°³j   ã                   óº   € ^ RI Ht ^ RIHt ^ RIt^ RIt^RIHtH	t	 ^RI
Ht ^RIHtHt ]	P                  ! ]4      t]! ]! RRR7      4       ! R	 R
]4      4       tR# )é    )ÚUserDict)ÚAnyN)Úadd_end_docstringsÚlogging)Úffmpeg_read)ÚPipelineÚbuild_pipeline_init_argsT)Úhas_feature_extractorÚhas_tokenizerc                   óz   a a€ ] tR t^t oRtRtRtRtRtV 3R lt	V3R lV 3R llt
R tRR ltR	 tR
 tRtVtV ;t# )Ú#ZeroShotAudioClassificationPipelinea”  
Zero shot audio classification pipeline using `ClapModel`. This pipeline predicts the class of an audio when you
provide an audio and a set of `candidate_labels`.

<Tip warning={true}>

The default `hypothesis_template` is : `"This is a sound of {}."`. Make sure you update it for your usage.

</Tip>

Example:
```python
>>> from transformers import pipeline
>>> from datasets import load_dataset

>>> dataset = load_dataset("ashraq/esc50")
>>> audio = next(iter(dataset["train"]["audio"]))["array"]
>>> classifier = pipeline(task="zero-shot-audio-classification", model="laion/clap-htsat-unfused")
>>> classifier(audio, candidate_labels=["Sound of a dog", "Sound of vacuum cleaner"])
[{'score': 0.9996, 'label': 'Sound of a dog'}, {'score': 0.0004, 'label': 'Sound of vacuum cleaner'}]
```


Learn more about the basics of using a pipeline in the [pipeline tutorial](../pipeline_tutorial). This audio
classification pipeline can currently be loaded from [`pipeline`] using the following task identifier:
`"zero-shot-audio-classification"`. See the list of available models on
[huggingface.co/models](https://huggingface.co/models?filter=zero-shot-audio-classification).
FTc                ó(   <€ \         SV `  ! R/ VB  R # )N© )ÚsuperÚ__init__)ÚselfÚkwargsÚ	__class__s   &,€Úv/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/pipelines/zero_shot_audio_classification.pyr   Ú,ZeroShotAudioClassificationPipeline.__init__C   s   ø€ Ü‰ÒÑ"˜6Ô"ó    c          	      ó–   <€ V ^8„  d   QhRS[ P                  S[,          S[,          S[,          RS[RS[S[S[S[3,          ,          /# )é   Úaudiosr   Úreturn)ÚnpÚndarrayÚbytesÚstrÚdictr   Úlist)ÚformatÚ__classdict__s   "€r   Ú__annotate__Ú0ZeroShotAudioClassificationPipeline.__annotate__F   sH   ø€ ÷ 2ñ 2™rŸz™z©EÕ1±CÕ7¹$Õ>ð 2É#ð 2ÑRVÑW[Ñ\_ÑadÐ\dÕWeÕRfñ 2r   c                ó&   <€ \         SV `  ! V3/ VB # )ah  
Assign labels to the audio(s) passed as inputs.

Args:
    audios (`str`, `list[str]`, `np.array` or `list[np.array]`):
        The pipeline handles three types of inputs:
        - A string containing a http link pointing to an audio
        - A string containing a local path to an audio
        - An audio loaded in numpy
    candidate_labels (`list[str]`):
        The candidate labels for this audio. They will be formatted using *hypothesis_template*.
    hypothesis_template (`str`, *optional*, defaults to `"This is a sound of {}"`):
        The format used in conjunction with *candidate_labels* to attempt the audio classification by
        replacing the placeholder with the candidate_labels. Pass "{}" if *candidate_labels* are
        already formatted.
Return:
    A list of dictionaries containing one entry per proposed label. Each dictionary contains the
    following keys:
    - **label** (`str`) -- One of the suggested *candidate_labels*.
    - **score** (`float`) -- The score attributed by the model to that label. It is a value between
        0 and 1, computed as the `softmax` of `logits_per_audio`.
)r   Ú__call__)r   r   r   r   s   &&,€r   r'   Ú,ZeroShotAudioClassificationPipeline.__call__F   s   ø€ ô. ‰wÒ Ñ1¨&Ñ1Ð1r   c                ó\   € / pR V9   d   VR ,          VR &   RV9   d   VR,          VR&   V/ / 3# )Úcandidate_labelsÚhypothesis_templater   )r   r   Úpreprocess_paramss   &, r   Ú_sanitize_parametersÚ8ZeroShotAudioClassificationPipeline._sanitize_parameters_   sI   € ØÐØ Ô'Ø4:Ð;MÕ4NÐÐ0Ñ1Ø  FÔ*Ø7=Ð>SÕ7TÐÐ3Ñ4à  " bÐ(Ð(r   c                ól  € \        V\        4      '       d   VP                  R 4      '       g   VP                  R4      '       d$   \        P                  ! VRR7      P
                  pM-\        VR4      ;_uu_ 4       pVP                  4       pRRR4       \        V\        4      '       d    \        WP                  P                  4      p\        V\        P                  4      '       g   \        R4      h\        VP                   4      ^8w  d   \#        R4      hV P                  V.V P                  P                  RR	7      pVP%                  V P&                  4      pW%R
&   V Uu. uF  qcP)                  V4      NK  	  ppV P+                  VRRR7      pV.VR&   V#   + '       g   i     EL; iu upi )zhttp://zhttps://T)Úfollow_redirectsÚrbNz"We expect a numpy ndarray as inputzNWe expect a single channel audio input for ZeroShotAudioClassificationPipelineÚpt)Úsampling_rateÚreturn_tensorsr*   )r4   ÚpaddingÚtext_inputs)Ú
isinstancer   Ú
startswithÚhttpxÚgetÚcontentÚopenÚreadr   r   Úfeature_extractorr3   r   r   Ú	TypeErrorÚlenÚshapeÚ
ValueErrorÚtoÚdtyper"   Ú	tokenizer)	r   Úaudior*   r+   ÚfÚinputsÚxÚ	sequencesr6   s	   &&&&     r   Ú
preprocessÚ.ZeroShotAudioClassificationPipeline.preprocessh   sc  € Ü�eœS×!Ò!Ø×Ñ 	×*Ò*¨e×.>Ñ.>¸z×.JÒ.Jô Ÿ	š	 %¸$Ô?×GÑG‘ä˜% ×&Ô&¨!ØŸF™F›H�E÷ 'ô �eœU×#Ò#Ü ×'=Ñ'=×'KÑ'KÓLˆEä˜%¤§¡×,Ò,ÜÐ@ÓAÐAÜˆu�{‰{Ó˜qÔ ÜÐmÓnÐnà×'Ñ'ØˆG 4×#9Ñ#9×#GÑ#GÐX\ð (ó 
ˆð —‘˜4Ÿ:™:Ó&ˆØ%5Ð!Ñ"Ù<LÓMÑ<L°q×/Ñ/°Ö2Ñ<Lˆ	ÐMØ—n‘n Y¸tÈT�nÓRˆØ!, ˆˆ}ÑØˆ÷' '×&Ð&üò  Ns   Á<FÅ&F1ÆF.	c                ó   € VP                  R 4      pVP                  R4      p\        V^ ,          \        4      '       d   V^ ,          pMV^ ,          ^ ,          pV P                  ! R/ VBVB pR VRVP                  /pV# )r*   r6   Úlogitsr   )Úpopr7   r   ÚmodelÚlogits_per_audio)r   Úmodel_inputsr*   r6   ÚoutputsÚmodel_outputss   &&    r   Ú_forwardÚ,ZeroShotAudioClassificationPipeline._forward„   s†   € Ø'×+Ñ+Ð,>Ó?ÐØ"×&Ñ& }Ó5ˆÜ�k !•n¤h×/Ò/Ø% a�.‰Kð & a�.¨Õ+ˆKà—*’*Ñ;˜{Ð;¨lÑ;ˆð Ð 0Ø�g×.Ñ.ð
ˆð Ðr   c                óô   € VP                  R 4      pVR,          ^ ,          pVP                  ^ R7      pVP                  4       p\        \	        WR4      R R7       UUu. uF  w  rgRVRV/NK  	  pppV# u uppi )r*   rN   )Údimc                 ó   € V ^ ,          ) # )r   r   )rI   s   &r   Ú<lambda>ÚAZeroShotAudioClassificationPipeline.postprocess.<locals>.<lambda>ž   s   € Ð_`ÐabÕ_cÑ^cr   )ÚkeyÚscoreÚlabel)rO   ÚsoftmaxÚtolistÚsortedÚzip)	r   rT   r*   rN   ÚprobsÚscoresr]   Úcandidate_labelÚresults	   &&       r   ÚpostprocessÚ/ZeroShotAudioClassificationPipeline.postprocess•   s…   € Ø(×,Ñ,Ð-?Ó@ÐØ˜xÕ(¨Õ+ˆà—‘ 1�Ó%ˆØ—‘“ˆô +1´°VÓ1NÑTcÕ*dô
á*dÑ&�ð �e˜W oÓ6Ù*dð 	ñ 
ð ˆùó	
s   ÁA4r   )NzThis is a sound of {}.)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú_load_processorÚ_load_image_processorÚ_load_feature_extractorÚ_load_tokenizerr   r'   r-   rK   rU   rg   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r   r#   s   @@r   r   r      sJ   ù‡ € ñð: €OØ!ÐØ"ÐØ€Oõ#÷2ó 2ò2)ôò8÷"ò r   r   )Úcollectionsr   Útypingr   r9   Únumpyr   Úutilsr   r   Úaudio_classificationr   Úbaser   r	   Ú
get_loggerri   Úloggerr   r   r   r   Ú<module>r}      s_   ðõ !Ý ã Û ÷õ .ß 4ð 
×	Ò	˜HÓ	%€ñ Ñ,À4ÐW[Ô\Ó]ô@¨(ó @ó ^ò@r   