o
    *j>	                     @   s   d dl mZmZmZmZ d dlZd dlmZ d dlm	Z	m
Z
 d dlmZm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 ZejejejdG dd deZdS )    )AnyDictOptionalUnionN)	Pipelines)MPlugForAllTasksOfaForAllTasks)ModelPipeline)	PIPELINES)batch_process)MPlugPreprocessorOfaPreprocessorPreprocessor)Tasks)
get_logger)module_namec                       s   e Zd Z	ddeeef dee f fddZ fddZ	de
eef d	e
eef f fd
dZde
eef d	e
eef fddZ  ZS )"AutomaticSpeechRecognitionPipelineNmodelpreprocessorc                    s   t |tst |tsJ dt |trt|}n
t |tr!|}nt|j  |du rAt |tr7t|j	}n
t |t
rAt|j	}t jd||d| dS )z
        use `model` and `preprocessor` to create an automatic speech recognition pipeline for prediction
        Args:
            model: model id on modelscope hub.
        z,model must be a single str or OfaForAllTasksN)r   r    )
isinstancestrr	   Zfrom_pretrainedNotImplementedErrorr   evalr   r   Z	model_dirr   r   super__init__)selfr   r   kwargsZ
pipe_model	__class__r   n/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/modelscope/pipelines/multi_modal/asr_pipeline.pyr      s   	





z+AutomaticSpeechRecognitionPipeline.__init__c                    s(   t | jtrt| j|S tt| |S N)r   r   r   r   r   r   _batch)r   datar   r   r!   r#   0   s   z)AutomaticSpeechRecognitionPipeline._batchinputsreturnc                    s@   t   t j|fi |W  d    S 1 sw   Y  d S r"   )torchZno_gradr   forward)r   r%   Zforward_paramsr   r   r!   r(   6   s   
$z*AutomaticSpeechRecognitionPipeline.forwardc                 C   s   |S r"   r   )r   r%   r   r   r!   postprocess;   s   z.AutomaticSpeechRecognitionPipeline.postprocessr"   )__name__
__module____qualname__r   r	   r   r   r   r   r#   r   r   r(   r)   __classcell__r   r   r   r!   r      s    

*r   )typingr   r   r   r   r'   Zmodelscope.metainfor   Zmodelscope.models.multi_modalr   r   Zmodelscope.pipelines.baser	   r
   Zmodelscope.pipelines.builderr   Zmodelscope.pipelines.utilr   Zmodelscope.preprocessorsr   r   r   Zmodelscope.utils.constantr   Zmodelscope.utils.loggerr   loggerZregister_moduleZauto_speech_recognitionZofa_asrr   r   r   r   r!   <module>   s   