o
    ॵi>	                     @   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	   from_pretrainedNotImplementedErrorr   evalr   r   	model_dirr   r   super__init__)selfr   r   kwargs
pipe_model	__class__r   a/home/ubuntu/.local/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%   )torchno_gradr   forward)r   r(   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*   modelscope.metainfor   modelscope.models.multi_modalr   r   modelscope.pipelines.baser	   r
   modelscope.pipelines.builderr   modelscope.pipelines.utilr   modelscope.preprocessorsr   r   r   modelscope.utils.constantr   modelscope.utils.loggerr   loggerregister_moduleauto_speech_recognitionofa_asrr   r   r   r   r$   <module>   s   