TTS / Dockerfile
MAS-AI-0000's picture
Create Dockerfile
f0d0200 verified
# Use official Python base (slim to keep image small)
FROM python:3.12-slim
# ---- system deps (for pydub/ffmpeg + soundfile) ----
RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg \
libsndfile1 \
git \
&& rm -rf /var/lib/apt/lists/*
# Create and switch to a non-root user
RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"
# Working directory inside the container
WORKDIR /app
# Copy requirements first (better cache)
COPY --chown=user ./requirements.txt requirements.txt
# Upgrade pip and install deps
RUN python -m pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt
# Optional: pre-download NLTK resource used by the app
# (avoids downloading at runtime in a locked-down environment)
RUN python - <<'PY'
import nltk
try:
nltk.download("punkt_tab")
except Exception as e:
print("NLTK download warning:", e)
PY
# Copy app code
COPY --chown=user . /app
# Expose the default Spaces port
EXPOSE 7860
# Run FastAPI server (Spaces sets $PORT, default to 7860)
CMD ["bash", "-lc", "uvicorn app:app --host 0.0.0.0 --port ${PORT:-7860}"]