From 10cd2c993cdcb5ae69aa327efa16df5337c6faad Mon Sep 17 00:00:00 2001 From: JB Date: Sun, 26 Oct 2025 08:03:40 -0700 Subject: [PATCH] feat: Add environment variables for voice cache and Hugging Face directory in Docker setup --- abogen/Dockerfile | 7 +++++-- abogen/voice_cache.py | 8 +++++++- docker-compose.yaml | 3 +++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/abogen/Dockerfile b/abogen/Dockerfile index c4b933e..13fd1d0 100644 --- a/abogen/Dockerfile +++ b/abogen/Dockerfile @@ -47,8 +47,11 @@ VOLUME ["/data"] ENV ABOGEN_UPLOAD_ROOT=/data/uploads \ ABOGEN_OUTPUT_ROOT=/data/outputs \ - ABOGEN_TEMP_DIR=/data/cache + ABOGEN_TEMP_DIR=/data/cache \ + ABOGEN_VOICE_CACHE_DIR=/data/voice-cache \ + HF_HOME=/data/huggingface \ + HUGGINGFACE_HUB_CACHE=/data/huggingface/hub -RUN mkdir -p /data/uploads /data/outputs /data/cache +RUN mkdir -p /data/uploads /data/outputs /data/cache /data/voice-cache /data/huggingface CMD ["abogen"] diff --git a/abogen/voice_cache.py b/abogen/voice_cache.py index 69bd1be..df1662f 100644 --- a/abogen/voice_cache.py +++ b/abogen/voice_cache.py @@ -1,5 +1,6 @@ from __future__ import annotations +import os import threading from typing import Callable, Dict, Iterable, Optional, Set, Tuple @@ -53,6 +54,11 @@ def ensure_voice_assets( if hf_hub_download is None: raise RuntimeError("huggingface_hub is required to cache voices") + effective_cache_dir = cache_dir + if effective_cache_dir is None: + env_cache_dir = os.environ.get("ABOGEN_VOICE_CACHE_DIR", "").strip() + effective_cache_dir = env_cache_dir or None + targets = _normalize_targets(voices) if not targets: return set(), {} @@ -70,7 +76,7 @@ def ensure_voice_assets( downloaded_flag = _ensure_single_voice_asset( voice_id, repo_id=repo_id, - cache_dir=cache_dir, + cache_dir=effective_cache_dir, ) except Exception as exc: # pragma: no cover - network variance errors[voice_id] = str(exc) diff --git a/docker-compose.yaml b/docker-compose.yaml index d572051..057352f 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -23,6 +23,9 @@ services: ABOGEN_OUTPUT_DIR: "/data/outputs" ABOGEN_OUTPUT_ROOT: "/data/outputs" ABOGEN_TEMP_DIR: "/data/cache" + ABOGEN_VOICE_CACHE_DIR: "/data/voice-cache" + HF_HOME: "/data/huggingface" + HUGGINGFACE_HUB_CACHE: "/data/huggingface/hub" HOME: "/tmp/abogen-home" # --- GPU support ----------------------------------------------------- # These settings assume the NVIDIA Container Toolkit is installed.