MFA-python / Dockerfile
YTShortMakerArchx's picture
Create Dockerfile
c729f04 verified
Raw History Blame Contribute Delete
2.12 kB
FROM condaforge/mambaforge:latest
ENV DEBIAN_FRONTEND=noninteractive \
TZ=Etc/UTC \
MFA_ROOT_DIR=/mfa \
PATH=/env/bin:$PATH
# ── System deps ───────────────────────────────────────────────────────────────
RUN apt-get update && apt-get install -y --no-install-recommends \
tzdata ffmpeg libsndfile1 \
&& rm -rf /var/lib/apt/lists/*
# ── Conda env + Python deps ───────────────────────────────────────────────────
RUN mkdir -p /mfa && \
mamba create -p /env -c conda-forge -y \
montreal-forced-aligner \
python=3.11 && \
/env/bin/pip install --no-cache-dir \
fastapi==0.115.0 \
"uvicorn[standard]==0.30.6" \
pydantic>=2.0 \
praatio>=6.0 \
numpy && \
conda clean -afy
# ── Download models once β€” baked into image ───────────────────────────────────
RUN /env/bin/mfa model download acoustic english_mfa && \
/env/bin/mfa model download dictionary english_mfa
# ── Pre-extract acoustic model zip so MFA never unzips at runtime ─────────────
# Write the script to a file first β€” avoids Dockerfile parser misreading
# "from montreal_forced_aligner..." as a FROM instruction.
COPY preextract.py /tmp/preextract.py
RUN /env/bin/python /tmp/preextract.py || echo "Pre-extraction failed (non-fatal)"
# ── HF Spaces requires UID 1000 ───────────────────────────────────────────────
RUN useradd -ms /bin/bash -u 1000 mfauser && \
chown -R 1000:1000 /mfa /env
# NOTE: /dev/shm is a runtime tmpfs β€” app.py creates /dev/shm/mfa_work at startup.
USER 1000
WORKDIR /app
COPY --chown=1000:1000 app.py /app/app.py
EXPOSE 7860
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]