o
    *jf                     @   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	 d dl
mZ d dlmZmZ d dlmZ d dl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)HiTeAForAllTasks)
OutputKeys)ModelPipeline)	PIPELINES)HiTeAPreprocessor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 )VideoCaptioningPipelineNmodelpreprocessorc                    sP   t  jd||d| | j  |du r$t| jtr&t| jj| _dS dS dS )z
        use `model` and `preprocessor` to create a video captioning pipeline for prediction
        Args:
            model: model id on modelscope hub.
        )r   r   N )	super__init__r   eval
isinstancer   r   Z	model_dirr   )selfr   r   kwargs	__class__r   {/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/modelscope/pipelines/multi_modal/video_captioning_pipeline.pyr      s   	
z VideoCaptioningPipeline.__init__c                    s   t | jtrDddlm} t|d d d}tdd |D |d< i }|d d  D ] t fd	d|D | < q+|||d< |S t	 
|S )
Nr   )BatchEncodingtrain)r   c                 S   s   g | ]}|d  qS )videor   .0dr   r   r   
<listcomp>)   s    z2VideoCaptioningPipeline._batch.<locals>.<listcomp>r    questionc                    s   g | ]}|d    qS )r%   r   r!   kr   r   r$   ,   s    )r   r   r   Z$transformers.tokenization_utils_baser   dicttorchcatkeysr   Z_collate_batch)r   datar   Z
batch_datar%   r   r&   r   _batch%   s   zVideoCaptioningPipeline._batchinputsreturnc                    s@   t   t j|fi |W  d    S 1 sw   Y  d S N)r)   Zno_gradr   forward)r   r.   Zforward_paramsr   r   r   r1   2   s   
$zVideoCaptioningPipeline.forwardc                 C   s   |S r0   r   )r   r.   r   r   r   postprocess7   s   z#VideoCaptioningPipeline.postprocessr0   )__name__
__module____qualname__r   r	   strr   r   r   r-   r   r   r1   r2   __classcell__r   r   r   r   r      s    

*r   )typingr   r   r   r   r)   Zmodelscope.metainfor   Zmodelscope.models.multi_modalr   Zmodelscope.outputsr   Zmodelscope.pipelines.baser	   r
   Zmodelscope.pipelines.builderr   Zmodelscope.preprocessorsr   r   Zmodelscope.utils.constantr   Zmodelscope.utils.loggerr   loggerZregister_moduleZvideo_captioningr   r   r   r   r   <module>   s   