File size: 2,300 Bytes
37211a8
8986c3d
 
 
 
 
 
 
 
d552b93
 
8986c3d
d552b93
 
8986c3d
 
0a81ef3
37211a8
8986c3d
 
 
37211a8
8986c3d
 
 
 
37211a8
8986c3d
 
 
 
 
 
37211a8
8986c3d
 
de67dec
 
 
8986c3d
 
0a81ef3
 
8986c3d
 
 
 
 
 
 
 
 
 
 
 
d552b93
 
675842a
d552b93
 
 
37211a8
 
de67dec
 
37211a8
 
 
 
 
 
8986c3d
 
 
 
 
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
FROM python:3.10-slim

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1 \
    HOST=0.0.0.0 \
    PORT=7860 \
    MODEL_DIR=/app/models/supertonic-2 \
    SUPERTONIC_CACHE_DIR=/app/models/supertonic-2 \
    KITTEN_MODEL_NAME=KittenML/kitten-tts-micro-0.8 \
    KITTEN_CACHE_DIR=/app/models/hf-cache \
    KOKORO_MODEL_DIR=/app/models/kokoro \
    HF_HOME=/app/models/hf-cache \
    HUGGINGFACE_HUB_CACHE=/app/models/hf-cache \
    WORKSPACE_DIR=/tmp/tts-server \
    JOB_DB_PATH=/tmp/tts-server/jobs.db \
    PERSISTENT_OUTPUT_DIR=/store \
    ENABLE_MELO_TTS=true \
    REQUIRE_AUTH=false

RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    ca-certificates \
    curl \
    ffmpeg \
    git \
    libsndfile1 \
    && rm -rf /var/lib/apt/lists/*

RUN useradd -m -u 1000 user

WORKDIR /app

COPY --chown=user:user requirements.txt requirements-melo.txt ./
RUN pip install -r requirements.txt

RUN git clone https://github.com/myshell-ai/MeloTTS.git /tmp/MeloTTS && \
    pip install -e /tmp/MeloTTS

COPY --chown=user:user . /app

RUN mkdir -p /app/models/supertonic-2 /app/models/kokoro /app/models/hf-cache /tmp/tts-server /store && \
    chown -R user:user /tmp/tts-server /store && \
    python -c "from supertonic import TTS; tts = TTS(model_dir='/app/models/supertonic-2', auto_download=True); print(f'Preloaded model at {tts.model_dir}')"

RUN python - <<'PY'
from huggingface_hub import snapshot_download
snapshot_download(
    repo_id='onnx-community/Kokoro-82M-v1.0-ONNX',
    local_dir='/app/models/kokoro',
    allow_patterns=['config.json', 'tokenizer.json', 'tokenizer_config.json', 'onnx/model_q8f16.onnx', 'voices/*.bin'],
)
print('Preloaded Kokoro assets into /app/models/kokoro')
PY

RUN python - <<'PY'
from kittentts import KittenTTS
KittenTTS(model_name='KittenML/kitten-tts-micro-0.8', cache_dir='/app/models/hf-cache')
print('Preloaded Kitten TTS assets into /app/models/hf-cache')
PY

RUN python -m unidic download

RUN python /tmp/MeloTTS/melo/init_downloads.py

RUN python - <<'PY'
from melo.api import TTS
TTS(language='EN', device='cpu', use_hf=True)
print('Verified MeloTTS dependency in the image')
PY

USER user

EXPOSE 7860

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]