feat: Add environment variables for voice cache and Hugging Face directory in Docker setup

This commit is contained in:
JB
2025-10-26 08:03:40 -07:00
parent 0259963eb8
commit 10cd2c993c
3 changed files with 15 additions and 3 deletions
+5 -2
View File
@@ -47,8 +47,11 @@ VOLUME ["/data"]
ENV ABOGEN_UPLOAD_ROOT=/data/uploads \ ENV ABOGEN_UPLOAD_ROOT=/data/uploads \
ABOGEN_OUTPUT_ROOT=/data/outputs \ 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"] CMD ["abogen"]
+7 -1
View File
@@ -1,5 +1,6 @@
from __future__ import annotations from __future__ import annotations
import os
import threading import threading
from typing import Callable, Dict, Iterable, Optional, Set, Tuple from typing import Callable, Dict, Iterable, Optional, Set, Tuple
@@ -53,6 +54,11 @@ def ensure_voice_assets(
if hf_hub_download is None: if hf_hub_download is None:
raise RuntimeError("huggingface_hub is required to cache voices") 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) targets = _normalize_targets(voices)
if not targets: if not targets:
return set(), {} return set(), {}
@@ -70,7 +76,7 @@ def ensure_voice_assets(
downloaded_flag = _ensure_single_voice_asset( downloaded_flag = _ensure_single_voice_asset(
voice_id, voice_id,
repo_id=repo_id, repo_id=repo_id,
cache_dir=cache_dir, cache_dir=effective_cache_dir,
) )
except Exception as exc: # pragma: no cover - network variance except Exception as exc: # pragma: no cover - network variance
errors[voice_id] = str(exc) errors[voice_id] = str(exc)
+3
View File
@@ -23,6 +23,9 @@ services:
ABOGEN_OUTPUT_DIR: "/data/outputs" ABOGEN_OUTPUT_DIR: "/data/outputs"
ABOGEN_OUTPUT_ROOT: "/data/outputs" 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"
HOME: "/tmp/abogen-home" HOME: "/tmp/abogen-home"
# --- GPU support ----------------------------------------------------- # --- GPU support -----------------------------------------------------
# These settings assume the NVIDIA Container Toolkit is installed. # These settings assume the NVIDIA Container Toolkit is installed.