"""GPU and CUDA library setup for the audio processor."""

import os
from pathlib import Path


def ensure_cuda_libs():
    """Ensure CUDA 12 libraries are on LD_LIBRARY_PATH.

    The system has CUDA 13.2 but faster-whisper's ctranslate2 needs CUDA 12.
    Ollama ships CUDA 12 libs at /usr/local/lib/ollama/cuda_v12/.
    """
    cuda12_path = "/usr/local/lib/ollama/cuda_v12"
    if Path(cuda12_path).exists():
        current = os.environ.get("LD_LIBRARY_PATH", "")
        if cuda12_path not in current:
            os.environ["LD_LIBRARY_PATH"] = f"{cuda12_path}:{current}" if current else cuda12_path
