+
    QV-jS+  ã                   óæ   € ^ RI t ^ RIHt ^ RIt^ RIt^RIHtHtH	t	H
t
Ht ^RIHtHt ]! 4       '       d   ^RIHt ]P"                  ! ]4      tR R lt]! ]! RR	7      4       ! R
 R]4      4       tR# )é    N)ÚAny)Úadd_end_docstringsÚis_torch_availableÚis_torchaudio_availableÚis_torchcodec_availableÚlogging)ÚPipelineÚbuild_pipeline_init_args)Ú,MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMESc                óP   € V ^8„  d   QhR\         R\        R\        P                  /# )é   ÚbpayloadÚsampling_rateÚreturn)ÚbytesÚintÚnpÚndarray)Úformats   "Ú|/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/site-packages/transformers/pipelines/audio_classification.pyÚ__annotate__r      s%   € ÷ !ñ !œ%ð !´ð !¼¿
¹
ñ !ó    c                ó–  € T pRpRpRRRRVRVRVR	R
RR.p \         P                  ! V\         P                  \         P                  R7      pTP                  T 4      pT^ ,          p\        P                  ! T\        P                  4      p	T	P                  ^ ,          ^ 8X  d   \	        R4      hT	#   \         d    \	        R4      hi ; i)z7
Helper function to read an audio file through ffmpeg.
Ú1Úf32leÚffmpegz-izpipe:0z-acz-arz-fz-hide_bannerz	-loglevelÚquietzpipe:1)ÚstdinÚstdoutzFffmpeg was not found but is required to load audio files from filenamezMalformed soundfile)
Ú
subprocessÚPopenÚPIPEÚFileNotFoundErrorÚ
ValueErrorÚcommunicater   Ú
frombufferÚfloat32Úshape)
r   r   ÚarÚacÚformat_for_conversionÚffmpeg_commandÚffmpeg_processÚoutput_streamÚ	out_bytesÚaudios
   &&        r   Úffmpeg_readr1      sÙ   € ð ˆ?€BØ	€BØ#ÐàØØØØ
ØØ
ØØØØØØð€Nð cÜ#×)Ò)¨.Ä
ÇÁÔXb×XgÑXgÔhˆð #×.Ñ.¨xÓ8€MØ˜aÕ €Iä�MŠM˜)¤R§Z¡ZÓ0€EØ‡{�{�1…~˜ÔÜÐ.Ó/Ð/Ø€Løô ô cÜÐaÓbÐbðcús   ˜5B1 Â1CT)Úhas_feature_extractorc                   ó~   a a€ ] tR t^Bt 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R ltR tR	 tRR
 ltRtVtV ;t# )ÚAudioClassificationPipelineaÄ  
Audio classification pipeline using any `AutoModelForAudioClassification`. This pipeline predicts the class of a
raw waveform or an audio file. In case of an audio file, ffmpeg should be installed to support multiple audio
formats.

Example:

```python
>>> from transformers import pipeline

>>> classifier = pipeline(model="superb/wav2vec2-base-superb-ks")
>>> classifier("https://huggingface.co/datasets/Narsil/asr_dummy/resolve/main/1.flac")
[{'score': 0.997, 'label': '_unknown_'}, {'score': 0.002, 'label': 'left'}, {'score': 0.0, 'label': 'yes'}, {'score': 0.0, 'label': 'down'}, {'score': 0.0, 'label': 'stop'}]
```

Learn more about the basics of using a pipeline in the [pipeline tutorial](../pipeline_tutorial)


This pipeline can currently be loaded from [`pipeline`] using the following task identifier:
`"audio-classification"`.

See the list of available models on
[huggingface.co/models](https://huggingface.co/models?filter=audio-classification).
FTc                óš   <€ R V9   d   VR ,          f   RVR &   MR V9  d   ^VR &   \         SV `  ! V/ VB  V P                  \        4       R# )Útop_kN)ÚsuperÚ__init__Úcheck_model_typer   )ÚselfÚargsÚkwargsÚ	__class__s   &*,€r   r8   Ú$AudioClassificationPipeline.__init__c   sO   ø€ à�fÔ ¨¥Ò!8Ø"ˆF�7ŠOØ˜FÔ"ØˆF�7‰OÜ‰Ò˜$Ð) &Ò)à×ÑÔJÖKr   c          	      ó–   <€ V ^8„  d   QhRS[ P                  S[,          S[,          S[,          RS[RS[S[S[S[3,          ,          /# )r   Úinputsr<   r   )r   r   r   ÚstrÚdictr   Úlist)r   Ú__classdict__s   "€r   r   Ú(AudioClassificationPipeline.__annotate__m   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 # )aÁ  
Classify the sequence(s) given as inputs. See the [`AutomaticSpeechRecognitionPipeline`] documentation for more
information.

Args:
    inputs (`np.ndarray` or `bytes` or `str` or `dict`):
        The inputs is either :
            - `str` that is the filename of the audio file, the file will be read at the correct sampling rate
              to get the waveform using *ffmpeg*. This requires *ffmpeg* to be installed on the system.
            - `bytes` it is supposed to be the content of an audio file and is interpreted by *ffmpeg* in the
              same way.
            - (`np.ndarray` of shape (n, ) of type `np.float32` or `np.float64`)
                Raw audio at the correct sampling rate (no further check will be done)
            - `dict` form can be used to pass raw audio sampled at arbitrary `sampling_rate` and let this
              pipeline do the resampling. The dict must be either be in the format `{"sampling_rate": int,
              "raw": np.array}`, or `{"sampling_rate": int, "array": np.array}`, where the key `"raw"` or
              `"array"` is used to denote the raw audio waveform.
    top_k (`int`, *optional*, defaults to None):
        The number of top labels that will be returned by the pipeline. If the provided number is `None` or
        higher than the number of labels available in the model configuration, it will default to the number of
        labels.
    function_to_apply (`str`, *optional*, defaults to "softmax"):
        The function to apply to the model output. By default, the pipeline will apply the softmax function to
        the output of the model. Valid options: ["softmax", "sigmoid", "none"]. Note that passing Python's
        built-in `None` will default to "softmax", so you need to pass the string "none" to disable any
        post-processing.

Return:
    A list of `dict` with the following keys:

    - **label** (`str`) -- The label predicted.
    - **score** (`float`) -- The corresponding probability.
)r7   Ú__call__)r:   r@   r<   r=   s   &&,€r   rG   Ú$AudioClassificationPipeline.__call__m   s   ø€ ôD ‰wÒ Ñ1¨&Ñ1Ð1r   c                ó8  € / pVf%   V P                   P                  P                  VR&   MHWP                   P                  P                  8”  d!   V P                   P                  P                  pWR&   Ve   VR9  d   \        RV R24      hW$R&   MRVR&   / / V3# )Nr6   Úsoftmaxz'Invalid value for `function_to_apply`: z2. Valid options are ['softmax', 'sigmoid', 'none']Úfunction_to_apply)rJ   ÚsigmoidÚnone)ÚmodelÚconfigÚ
num_labelsr$   )r:   r6   rK   r<   Úpostprocess_paramss   &&&, r   Ú_sanitize_parametersÚ0AudioClassificationPipeline._sanitize_parameters‘   sµ   € ØÐð Š=Ø*.¯*©*×*;Ñ*;×*FÑ*FÐ˜wÒ'à—z‘z×(Ñ(×3Ñ3Ô3ØŸ
™
×)Ñ)×4Ñ4�Ø*/˜wÑ'àÒ(Ø Ð(FÔFÜ Ø=Ð>OÐ=Pð QGð Góð ð 7HÐ2Ò3à6?ÐÐ2Ñ3Ø�2Ð)Ð)Ð)r   c                óâ  € \        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\        4       '       d>   ^ RIp\        WP                  4      '       d   VP                  4       P!                  4       p\#        4       '       dZ   ^ RIp^ RIp\        WP&                  P(                  4      '       d-   VP+                  4       pVP,                  pRVRVP.                  /p\        V\0        4      '       Ed$   VP3                  4       pRV9   d   RV9   g   RV9   g   \5        R	4      hVP7                  RR4      pVf%   VP7                  R
R4       VP7                  RR4      pVP7                  R4      pTpW€P                  P                  8w  d�   ^ RIp\9        4       '       d   ^ RIHp	 M\?        R4      hT	PA                  \        V\B        PD                  4      '       d   VPG                  V4      MTVV P                  P                  4      P!                  4       p\        V\B        PD                  4      '       g   \I        R4      h\K        VPL                  4      ^8w  d   \5        R4      hV P                  WP                  P                  RR7      p
V PN                  e   V
PQ                  V PN                  R7      p
V
#   + '       g   i     ELÙ; i)zhttp://zhttps://T)Úfollow_redirectsÚrbNÚarrayr   ÚrawzôWhen passing a dictionary to AudioClassificationPipeline, the dict needs to contain a "raw" key containing the numpy array or torch tensor representing the audio and a "sampling_rate" key, containing the sampling_rate associated with that arrayÚpath)Ú
functionalz›torchaudio is required to resample audio samples in AudioClassificationPipeline. The torchaudio package can be installed through: `pip install torchaudio`.z2We expect a numpy ndarray or torch tensor as inputzFWe expect a single channel audio input for AudioClassificationPipelineÚpt)r   Úreturn_tensors)Údtype))Ú
isinstancerA   Ú
startswithÚhttpxÚgetÚcontentÚopenÚreadr   r1   Úfeature_extractorr   r   ÚtorchÚTensorÚcpuÚnumpyr   Ú
torchcodecÚdecodersÚAudioDecoderÚget_all_samplesÚdataÚsample_raterB   Úcopyr$   Úpopr   Ú
torchaudiorZ   ÚImportErrorÚresampler   r   Ú
from_numpyÚ	TypeErrorÚlenr(   r]   Úto)r:   r@   Úfrf   rj   Ú_audio_samplesÚ_arrayÚ_inputsÚin_sampling_rateÚFÚ	processeds   &&         r   Ú
preprocessÚ&AudioClassificationPipeline.preprocess§   s³  € Ü�fœc×"Ò"Ø× Ñ  ×+Ò+¨v×/@Ñ/@À×/LÒ/Lô Ÿš 6¸DÔA×IÑI‘ä˜& $×'Ô'¨1ØŸV™V›X�F÷ (ô �fœe×$Ò$Ü  ×)?Ñ)?×)MÑ)MÓNˆFä×ÒÛä˜&§,¡,×/Ò/ØŸ™›×+Ñ+Ó-�ä"×$Ò$ÛÛä˜&×"5Ñ"5×"BÑ"B×CÒCØ!'×!7Ñ!7Ó!9�Ø'×,Ñ,�Ø! 6¨?¸N×<VÑ<VÐW�ä�fœd×#Ó#Ø—[‘[“]ˆFð $ vÔ-°5¸F´?ÀgÐQWÔFWÜ ðNóð ð —j‘j ¨Ó-ˆGØŠà—
‘
˜6 4Ô(Ø Ÿ*™* W¨dÓ3�Ø%Ÿz™z¨/Ó:ÐØˆFØ×#9Ñ#9×#GÑ#GÔGÛä*×,Ò,Þ:ä%ðeóð ð
 Ÿ™Ü0:¸6Ä2Ç:Á:×0NÒ0N�E×$Ñ$ VÔ,ÐTZØ$Ø×*Ñ*×8Ñ8ó÷ ‘%“'ð	 ô ˜&¤"§*¡*×-Ò-ÜÐPÓQÐQÜˆv�|‰|Ó Ô!ÜÐeÓfÐfà×*Ñ*Ø×"8Ñ"8×"FÑ"FÐW[ð +ó 
ˆ	ð �:‰:Ò!Ø!Ÿ™¨4¯:©:˜Ó6ˆIØÐ÷E (×'Ð'ús   Á<MÍM.	c                ó*   € V P                   ! R/ VB pV# )N© )rN   )r:   Úmodel_inputsÚmodel_outputss   && r   Ú_forwardÚ$AudioClassificationPipeline._forwardò   s   € ØŸ
š
Ñ2 \Ñ2ˆØÐr   c           	     óÒ  € VR 8X  d$   VP                   ^ ,          P                  R4      pM<VR8X  d#   VP                   ^ ,          P                  4       pMVP                   ^ ,          pVP                  V4      w  rVVP	                  4       pVP	                  4       p\        WV4       UUu. uF0  w  rxRVRV P                  P                  P                  V,          /NK2  	  p	ppV	# u uppi )rJ   rL   ÚscoreÚlabeléÿÿÿÿ)	ÚlogitsrJ   rL   ÚtopkÚtolistÚziprN   rO   Úid2label)
r:   r…   r6   rK   ÚprobsÚscoresÚidsr‰   Ú_idÚlabelss
   &&&&      r   ÚpostprocessÚ'AudioClassificationPipeline.postprocessö   sÅ   € Ø 	Ô)Ø!×(Ñ(¨Õ+×3Ñ3°BÓ7‰EØ )Ô+Ø!×(Ñ(¨Õ+×3Ñ3Ó5‰Eà!×(Ñ(¨Õ+ˆEØ—j‘j Ó'‰ˆà—‘“ˆØ�j‰j‹lˆä_bÐciÔ_oÔpÑ_oÑQ[ÐQV�7˜E 7¨D¯J©J×,=Ñ,=×,FÑ,FÀsÕ,KÓLÑ_oˆÑpàˆùó qs   Â(6C#rƒ   )NN)é   rJ   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú_load_processorÚ_load_image_processorÚ_load_feature_extractorÚ_load_tokenizerr8   rG   rR   r€   r†   r–   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r=   rD   s   @@r   r4   r4   B   sN   ù‡ € ñð2 €OØ!ÐØ"ÐØ€OõL÷"2ó "2ôH*ò,IòV÷ô r   r4   )r    Útypingr   r`   ri   r   Úutilsr   r   r   r   r   Úbaser	   r
   Úmodels.auto.modeling_autor   Ú
get_loggerr™   Úloggerr1   r4   rƒ   r   r   Ú<module>r«      sj   ðó Ý ã Û ç uÕ uß 4ñ ×ÒÝXà	×	Ò	˜HÓ	%€õ!ñH Ñ,À4ÔHÓIôA (ó Aó JòAr   