File size: 2,120 Bytes
c729f04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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"]