o
    3NPi)                     @   s>   d Z ddlZddlmZmZ ddlmZ eG dd dZdS )a  
Configuration for Fast Pipeline v6.0 - Adaptive Compute-Aware

Key improvements:
- Auto-detects system resources (nproc, vCPUs, GPU vRAM)
- Adapts worker counts and batch sizes to available compute
- Optimized for micro-level speaker detection (0.4s events)
    N)	dataclassfield)Optionalc                   @   s  e Zd ZU dZej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< 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< 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< 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$< 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-< d.Z%ee	d/< d0Z&ee	d1< d
Z'ee	d2< d3Z(ee	d4< d5Z)ee	d6< d
Z*ee	d7< d8Z+ee	d9< d:Z,ee	d;< d3Z-ee	d<< d=Z.ee	d>< d?Z/ee	d@< dAZ0ee	dB< dCZ1ee	dD< dEZ2ee	dF< dGZ3ee	dH< d
Z4ee	dI< dJZ5ee	dK< dLZ6ee	dM< dNZ7ee	dO< dPZ8ee	dQ< d
Z9ee	dR< dPZ:ee	dS< dTZ;ee	dU< d)Z<ee	dV< dLZ=ee	dW< dZ>ee	dX< dYZ?ee	dZ< d.Z@ee	d[< dLZAee	d\< dZBee	d]< d)ZCee	d^< d.ZDee	d_< d:ZEee	d`< d
ZFee	da< d
ZGee	db< d.ZHee	dc< ddZIee	de< dfZJee	dg< dhZKee	di< djZLee	dk< dZMee	dl< djZNee	dm< d
ZOee	dn< d
ZPee	do< d
ZQee	dp< dEZRee	dq< dreSfdsdtZTdudv ZUdwS )xConfiga  
    Pipeline configuration with adaptive compute settings.
    
    Flow (per instructions.md):
    1. Download (max parallel workers)
    2. Quick VAD (parallel, get speech outline)
    3. Chunk at silence boundaries (VAD-aware)
    4. OSD (mark overlaps as unusable FIRST)
    5. Frame-level segmentation (17ms resolution for micro-changes)
    6. Embeddings + Conservative clustering
    7. Output metadata JSON only
    HF_TOKEN%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hf_tokeni>  sample_rateg        intro_skip_secondsoutro_skip_secondsTauto_intro_skippreserve_original_audior   original_audio_sample_rate    vad_workersmax_workers   download_workerschunk_workersg     r@chunk_durationg      >@min_chunk_durationg      ?vad_threshold   vad_min_speech_msvad_min_silence_msi   vad_window_size_samples   vad_speech_pad_msg      N@vad_chunk_sizeuse_community_modelg      @segmentation_stepg      @segmentation_durationg?min_segment_durationdetect_overlapgffffff?overlap_threshold皙?overlap_min_durationd   overlap_padding_msoverlap_density_filter      ?overlap_density_max_gapg      @overlap_density_max_durationfilter_by_qualityg      .@
min_snr_dbg333333?min_quality_scoremin_tts_duration   min_speakers
   max_speakers   embedding_batch_sizei q max_embedding_lengthg?cluster_merge_threshold   min_segments_for_mergeenable_chunk_reassignmentg?chunk_reassignment_thresholdg      ?chunk_reassignment_severeg333333?chunk_reassignment_min_speechg      ?chunk_reassignment_min_portionenable_music_detectionmusic_chunk_duration@   music_batch_sizemusic_prob_thresholdnoise_prob_thresholdmusic_ratio_cleang333333?music_ratio_demucsmusic_mean_cleanmusic_mean_demucsnoise_ratio_cleannoise_ratio_demucsnoise_mean_cleannoise_mean_demucsstrict_tts_modemusic_early_exitmusic_early_exit_sample_ratiog?music_early_exit_thresholdzdata/fast_output_v6
output_dirFgenerate_sample_clips   clips_per_speakermax_silence_gapclear_cache_every_n_chunksmonitor_computelog_compute_statsauto_tune_resourcesmax_utilizationcompute_configc                 C   s,   |  D ]\}}t| |rt| || qdS )z
        Apply auto-detected optimal settings from ComputeMonitor.
        
        Called after COMPUTE.get_optimal_config()
        N)itemshasattrsetattr)selfr\   keyvalue rc   P/home/ubuntu/.cursor/worktrees/maya3data__SSH__216.81.248.184_/zxg/src/config.pyapply_adaptive_settings   s
   
zConfig.apply_adaptive_settingsc                 C   s   t j| jdd | jr/zddlm} | j|jjkr|| j |	|  W n	 t
y.   Y nw d| j  k r=dksBJ d J dd| j  k rPdksUJ d J d| jdks^J d	d
S )z/Validate configuration and auto-tune resources.T)exist_okr   )COMPUTEr*   zmerge threshold must be (0, 1]zVAD threshold must be (0, 1]r%   zmin_segment too smallN)osmakedirsrR   rZ   src.computerg   r[   	resourcesset_max_utilizationapply_to_configImportErrorr8   r   r"   )r`   rg   rc   rc   rd   __post_init__   s   &&zConfig.__post_init__N)V__name__
__module____qualname____doc__rh   environgetr   str__annotations__r	   intr
   floatr   r   boolr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r&   r(   r)   r+   r,   r-   r.   r/   r0   r2   r4   r6   r7   r8   r:   r;   r<   r=   r>   r?   r@   rA   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rU   rV   rW   rX   rY   rZ   r[   dictre   ro   rc   rc   rc   rd   r      s   
 		
r   )rs   rh   dataclassesr   r   typingr   r   rc   rc   rc   rd   <module>   s   	