TTS2 / Dockerfile
moustafa1-1's picture
Update Dockerfile
0b9e281 verified
# Use an official Python runtime as a parent image
FROM python:3.9-slim-buster
# Set the working directory in the container
WORKDIR /app
# Install build tools and other dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
cmake \
pkg-config \
libblis-dev \
python3-venv \
python3-dev \
wget \
git \
gcc \
g++ \
libffi-dev \
zlib1g-dev
# Create a virtual environment
RUN python3 -m venv venv
# Activate the virtual environment
RUN . /app/venv/bin/activate
# Copy the locally cloned Coqui TTS repository
COPY TTS /app/TTS
# Set the working directory to the TTS directory
WORKDIR /app/TTS
# Set a generic architecture flag
ENV BLIS_ARCH="generic"
# Try to agree to the Coqui TTS license via environment variable
ENV COQUI_TTS_AGREED=1
# Install Coqui TTS requirements
RUN . /app/venv/bin/activate && pip install -r requirements.txt --timeout=300
# Explicitly install the TTS package itself in editable mode
RUN . /app/venv/bin/activate && pip install -e . --timeout=300
# Change working directory back to /app
WORKDIR /app
# Create the model directory (relative to /app)
RUN mkdir -p /app/models/xtts_v2
# Download XTTS v2 model files
RUN wget -O /app/models/xtts_v2/config.json https://huggingface.co/coqui/XTTS-v2/resolve/main/config.json?download=true
RUN wget -O /app/models/xtts_v2/model.pth https://huggingface.co/coqui/XTTS-v2/resolve/main/model.pth?download=true
RUN wget -O /app/models/xtts_v2/vocab.json https://huggingface.co/coqui/XTTS-v2/resolve/main/vocab.json?download=true
RUN wget -O /app/models/xtts_v2/dvae.pth https://huggingface.co/coqui/XTTS-v2/resolve/main/dvae.pth?download=true
RUN wget -O /app/models/xtts_v2/speakers_xtts.pth https://huggingface.co/coqui/XTTS-v2/resolve/main/speakers_xtts.pth?download=true
# Create the audio directory if it doesn't exist
RUN mkdir -p /app/audio
# Copy the speaker reference file from the root directory
COPY speaker_reference.wav /app/audio/speaker_reference.wav
# Copy the web page files
COPY web /app/web
# Copy the application code
COPY local_server_new.py /app/
# Install your other dependencies (fastapi, uvicorn, bangla, etc.)
COPY requirements.txt /app/
RUN . /app/venv/bin/activate && pip install -r /app/requirements.txt --no-cache-dir --timeout=300
# Disable numba caching
ENV NUMBA_DISABLE_CACHE=1
# Clear numba and llvmlite cache (Let's keep this for now, though it might not be needed)
RUN rm -rf /app/venv/lib/python3.9/site-packages/numba/__pycache__ /app/venv/lib/python3.9/site-packages/llvmlite/__pycache__
# Create start.sh script
RUN echo "#!/bin/bash" > start.sh && \
echo "source /app/venv/bin/activate" >> start.sh && \
echo "/app/venv/bin/python -m uvicorn local_server_new:app --host 0.0.0.0 --port 80" >> start.sh && \
chmod +x start.sh
# Expose port
EXPOSE 80
# Run the app using the script
CMD ["./start.sh"]