a
    dg                     @   s   d dl mZmZmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ G dd deZdS )    )AnyDictListOptional)Chain)CallbackManagerForChainRun)BaseLanguageModel)PromptTemplate)
ConfigDict)AudioProcessor)CaptionProcessor)CombineProcessor)ImageProcessor)SRTProcessorc                   @   s   e Zd ZU dZeed< eed< dZee	 ed< dZ
eed< dZee ed< d	Zeed
< dZeed< dZeed< dZeed< dZeed< edddZeee dddZeee dddZdeeef ee eeef dddZeedddZdS ) VideoCaptioningChainz!
    Video Captioning Chain.
    llmassemblyai_keyNpromptTverboseuse_logging
frame_skipi- image_delta_threshold   closed_caption_char_limitP   #closed_caption_similarity_thresholdFuse_unclustered_video_modelsZallow)Zarbitrary_types_allowedextra)returnc                 C   s   dgS )Nvideo_file_path selfr!   r!   z/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_experimental/video_captioning/base.py
input_keys-   s    zVideoCaptioningChain.input_keysc                 C   s   dgS )Nsrtr!   r"   r!   r!   r$   output_keys1   s    z VideoCaptioningChain.output_keys)inputsrun_managerr   c                 C   s  d|vrt d|d }d}| jr4|r4|d| nd  t| jd}t| j| jd}t| j	| j
| j| jd}t| j	| j
| jd}t }	| jr|r|d	| d
 | nd  |||}
| jr|r|d| |dd |
D   | d | nd  |||}| jr>|r>|d| |dd |D   | d | nd  |||}| jr|r|d| |dd |D   | d | nd  |||
|}| jr|r|d| |dd |D   | d | nd  |	|}| jr|r|d| nd  d|iS )Nr    z9Missing 'video_file_path' in inputs for video captioning.
zLoading processors...)Zapi_key)r   	threshold)r   r   Zsimilarity_thresholdZuse_unclustered_models)r   r   Z
char_limitzFinished loading processors.z"Generating subtitles from audio...zFinished generating subtitles:c                 s   s   | ]}t |V  qd S Nstr.0objr!   r!   r$   	<genexpr>b       z-VideoCaptioningChain._call.<locals>.<genexpr>z(Generating closed captions from video...z$Finished generating closed captions:c                 s   s   | ]}t |V  qd S r,   r-   r/   r!   r!   r$   r2   m   r3   zRefining closed captions...z"Finished refining closed captions:c                 s   s   | ]}t |V  qd S r,   r-   r/   r!   r!   r$   r2   x   r3   z+Combining subtitles with closed captions...z2Finished combining subtitles with closed captions:c                 s   s   | ]}t |V  qd S r,   r-   r/   r!   r!   r$   r2      r3   zGenerating SRT file...zFinished generating srt file.r&   )
ValueErrorr   Zon_textr   r   r   r   r   r   r   r   r   r   r   r   r   processjoin)r#   r(   r)   r    nlZaudio_processorZimage_processorZcaption_processorZcombine_processorZsrt_processorZaudio_modelsZimage_modelsZvideo_modelsZcaption_modelsZsrt_contentr!   r!   r$   _call5   s   





zVideoCaptioningChain._callc                 C   s   dS )NZvideo_captioning_chainr!   r"   r!   r!   r$   _chain_type   s    z VideoCaptioningChain._chain_type)N)__name__
__module____qualname____doc__r   __annotations__r.   r   r   r	   r   boolr   r   intr   r   r   r   r
   Zmodel_configpropertyr   r%   r'   r   r   r   r8   r9   r!   r!   r!   r$   r      s6   
 

^r   N)typingr   r   r   r   Zlangchain.chains.baser   Zlangchain_core.callbacksr   Zlangchain_core.language_modelsr   Zlangchain_core.promptsr	   Zpydanticr
   Z>langchain_experimental.video_captioning.services.audio_servicer   Z@langchain_experimental.video_captioning.services.caption_servicer   Z@langchain_experimental.video_captioning.services.combine_servicer   Z>langchain_experimental.video_captioning.services.image_servicer   Z<langchain_experimental.video_captioning.services.srt_servicer   r   r!   r!   r!   r$   <module>   s   