fix: update model directory paths and improve logging in TTS services

This commit is contained in:
remsky 2025-01-14 06:37:03 -07:00
parent 2c305c66ed
commit 8bc8661930
7 changed files with 32 additions and 25 deletions

View file

@ -13,7 +13,7 @@ class Settings(BaseSettings):
output_dir: str = "output" output_dir: str = "output"
output_dir_size_limit_mb: float = 500.0 # Maximum size of output directory in MB output_dir_size_limit_mb: float = 500.0 # Maximum size of output directory in MB
default_voice: str = "af" default_voice: str = "af"
model_dir: str = "/app/api/model_files" # Base directory for model files model_dir: str = "/app/models" # Base directory for model files
pytorch_model_path: str = "kokoro-v0_19.pth" pytorch_model_path: str = "kokoro-v0_19.pth"
onnx_model_path: str = "kokoro-v0_19.onnx" onnx_model_path: str = "kokoro-v0_19.onnx"
voices_dir: str = "voices" voices_dir: str = "voices"

View file

@ -39,6 +39,9 @@ class TTSBaseModel(ABC):
cls._device = "cpu" cls._device = "cpu"
model_path = os.path.join(settings.model_dir, settings.onnx_model_path) model_path = os.path.join(settings.model_dir, settings.onnx_model_path)
logger.info(f"Initializing model on {cls._device}") logger.info(f"Initializing model on {cls._device}")
logger.info(f"Model dir: {settings.model_dir}")
logger.info(f"Model path: {model_path}")
logger.info(f"Files in model dir: {os.listdir(settings.model_dir)}")
# Initialize model first # Initialize model first
model = cls.initialize(settings.model_dir, model_path=model_path) model = cls.initialize(settings.model_dir, model_path=model_path)

View file

@ -3,7 +3,7 @@ import time
import numpy as np import numpy as np
import torch import torch
from builds.models import build_model from ..builds.models import build_model
from loguru import logger from loguru import logger
from ..core.config import settings from ..core.config import settings

View file

@ -16,17 +16,21 @@ COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
RUN useradd -m -u 1000 appuser RUN useradd -m -u 1000 appuser
# Create directories and set ownership # Create directories and set ownership
RUN mkdir -p /app/api/model_files && \ RUN mkdir -p /app/models && \
mkdir -p /app/api/src/voices && \ mkdir -p /app/api/src/voices && \
chown -R appuser:appuser /app chown -R appuser:appuser /app
USER appuser USER appuser
# Download and extract models # Download and extract models
WORKDIR /app/api/model_files WORKDIR /app/models
RUN curl -L -o model.tar.gz https://github.com/remsky/Kokoro-FastAPI/releases/download/v0.0.1/kokoro-82m-onnx.tar.gz && \ RUN set -x && \
curl -L -o model.tar.gz https://github.com/remsky/Kokoro-FastAPI/releases/download/v0.0.1/kokoro-82m-onnx.tar.gz && \
echo "Downloaded model.tar.gz:" && ls -lh model.tar.gz && \
tar xzf model.tar.gz && \ tar xzf model.tar.gz && \
rm model.tar.gz echo "Contents after extraction:" && ls -lhR && \
rm model.tar.gz && \
echo "Final contents:" && ls -lhR
# Download and extract voice models # Download and extract voice models
WORKDIR /app/api/src/voices WORKDIR /app/api/src/voices
@ -54,7 +58,7 @@ RUN --mount=type=cache,target=/root/.cache/uv \
# Set environment variables # Set environment variables
ENV PYTHONUNBUFFERED=1 ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/app:/app/Kokoro-82M ENV PYTHONPATH=/app:/app/models
ENV PATH="/app/.venv/bin:$PATH" ENV PATH="/app/.venv/bin:$PATH"
ENV UV_LINK_MODE=copy ENV UV_LINK_MODE=copy

View file

@ -1,17 +1,17 @@
name: kokoro-tts name: kokoro-tts
services: services:
kokoro-tts: kokoro-tts:
image: ghcr.io/remsky/kokoro-fastapi-cpu:latest image: ghcr.io/remsky/kokoro-fastapi-cpu:v0.1.0
# Uncomment below (and comment out above) to build from source instead of using the released image
# build: # build:
# context: ../.. # context: ../..
# dockerfile: docker/cpu/Dockerfile # dockerfile: docker/cpu/Dockerfile
volumes: volumes:
- ../../api/src:/app/api/src - ../../api/src:/app/api/src
- ../../api/src/voices:/app/api/src/voices
ports: ports:
- "8880:8880" - "8880:8880"
environment: environment:
- PYTHONPATH=/app:/app/Kokoro-82M - PYTHONPATH=/app:/app/models
# ONNX Optimization Settings for vectorized operations # ONNX Optimization Settings for vectorized operations
- ONNX_NUM_THREADS=8 # Maximize core usage for vectorized ops - ONNX_NUM_THREADS=8 # Maximize core usage for vectorized ops
- ONNX_INTER_OP_THREADS=4 # Higher inter-op for parallel matrix operations - ONNX_INTER_OP_THREADS=4 # Higher inter-op for parallel matrix operations
@ -22,10 +22,10 @@ services:
# Gradio UI service [Comment out everything below if you don't need it] # Gradio UI service [Comment out everything below if you don't need it]
gradio-ui: gradio-ui:
image: ghcr.io/remsky/kokoro-fastapi:latest-ui image: ghcr.io/remsky/kokoro-fastapi-ui:v0.1.0
# Uncomment below (and comment out above) to build from source instead of using the released image # Uncomment below (and comment out above) to build from source instead of using the released image
# build: build:
# context: ../../ui context: ../../ui
ports: ports:
- "7860:7860" - "7860:7860"
volumes: volumes:
@ -34,4 +34,4 @@ services:
environment: environment:
- GRADIO_WATCH=True # Enable hot reloading - GRADIO_WATCH=True # Enable hot reloading
- PYTHONUNBUFFERED=1 # Ensure Python output is not buffered - PYTHONUNBUFFERED=1 # Ensure Python output is not buffered
- DISABLE_LOCAL_SAVING=false # Set to 'true' to disable local saving and hide file view - DISABLE_LOCAL_SAVING=false # Set to 'true' to disable local saving and hide file view

View file

@ -18,14 +18,14 @@ COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
RUN useradd -m -u 1000 appuser RUN useradd -m -u 1000 appuser
# Create directories and set ownership # Create directories and set ownership
RUN mkdir -p /app/api/model_files && \ RUN mkdir -p /app/models && \
mkdir -p /app/api/src/voices && \ mkdir -p /app/api/src/voices && \
chown -R appuser:appuser /app chown -R appuser:appuser /app
USER appuser USER appuser
# Download and extract models # Download and extract models
WORKDIR /app/api/model_files WORKDIR /app/models
RUN curl -L -o model.tar.gz https://github.com/remsky/Kokoro-FastAPI/releases/download/v0.0.1/kokoro-82m-pytorch.tar.gz && \ RUN curl -L -o model.tar.gz https://github.com/remsky/Kokoro-FastAPI/releases/download/v0.0.1/kokoro-82m-pytorch.tar.gz && \
tar xzf model.tar.gz && \ tar xzf model.tar.gz && \
rm model.tar.gz rm model.tar.gz
@ -56,7 +56,7 @@ RUN --mount=type=cache,target=/root/.cache/uv \
# Set environment variables # Set environment variables
ENV PYTHONUNBUFFERED=1 ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/app:/app/Kokoro-82M ENV PYTHONPATH=/app:/app/models
ENV PATH="/app/.venv/bin:$PATH" ENV PATH="/app/.venv/bin:$PATH"
ENV UV_LINK_MODE=copy ENV UV_LINK_MODE=copy

View file

@ -1,17 +1,17 @@
name: kokoro-tts name: kokoro-tts
services: services:
kokoro-tts: kokoro-tts:
image: ghcr.io/remsky/kokoro-fastapi-gpu:latest # image: ghcr.io/remsky/kokoro-fastapi-gpu:latest
# Uncomment below (and comment out above) to build from source instead of using the released image build:
# build: context: ../..
# context: ../.. dockerfile: docker/gpu/Dockerfile
# dockerfile: docker/gpu/Dockerfile
volumes: volumes:
- ../../api/src:/app/api/src # Mount src for development - ../../api/src:/app/api/src # Mount src for development
- ../../api/src/voices:/app/api/src/voices # Mount voices for persistence
ports: ports:
- "8880:8880" - "8880:8880"
environment: environment:
- PYTHONPATH=/app:/app/Kokoro-82M - PYTHONPATH=/app:/app/models
deploy: deploy:
resources: resources:
reservations: reservations: