Sammydynamo commited on
Commit
7ffc5b5
·
1 Parent(s): c6fda30

Fix Dockerfile: use standalone download script

Browse files
Files changed (2) hide show
  1. Dockerfile +2 -19
  2. download_models.py +37 -0
Dockerfile CHANGED
@@ -9,27 +9,10 @@ COPY requirements.txt .
9
  RUN pip install --no-cache-dir -r requirements.txt
10
 
11
  COPY app.py .
 
12
 
13
  # Pre-download commonly used TTS models so first requests are fast.
14
- # Individual failures are non-fatal.
15
- RUN python -c "\
16
- from transformers import VitsModel, AutoTokenizer; \
17
- models = [ \
18
- 'facebook/mms-tts-yor', 'facebook/mms-tts-swh', 'facebook/mms-tts-hau', \
19
- 'facebook/mms-tts-pcm', 'facebook/mms-tts-aka', 'facebook/mms-tts-lug', \
20
- 'facebook/mms-tts-amh', 'facebook/mms-tts-som', 'facebook/mms-tts-sna', \
21
- 'khof312/mms-tts-lin', 'facebook/mms-tts-ara', \
22
- ]; \
23
- ok = 0; \
24
- for m in models: \
25
- try: \
26
- VitsModel.from_pretrained(m); AutoTokenizer.from_pretrained(m); \
27
- print(f' OK {m}'); ok += 1 \
28
- except Exception as e: \
29
- print(f' SKIP {m}: {e}') \
30
- ; \
31
- print(f'{ok}/{len(models)} models cached') \
32
- "
33
 
34
  EXPOSE 7860
35
 
 
9
  RUN pip install --no-cache-dir -r requirements.txt
10
 
11
  COPY app.py .
12
+ COPY download_models.py .
13
 
14
  # Pre-download commonly used TTS models so first requests are fast.
15
+ RUN python download_models.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  EXPOSE 7860
18
 
download_models.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Pre-download MMS-TTS VITS models at Docker build time.
2
+
3
+ This runs during `docker build` so that models are baked into the image.
4
+ At runtime, from_pretrained() loads from the local cache (fast) instead
5
+ of downloading from HuggingFace (slow cold-start).
6
+
7
+ Individual failures are non-fatal — the build continues with whatever
8
+ models succeed.
9
+ """
10
+
11
+ from transformers import VitsModel, AutoTokenizer
12
+
13
+ MODELS = [
14
+ "facebook/mms-tts-yor", # Yorùbá
15
+ "facebook/mms-tts-swh", # Swahili
16
+ "facebook/mms-tts-hau", # Hausa
17
+ "facebook/mms-tts-pcm", # Pidgin
18
+ "facebook/mms-tts-aka", # Twi (Akan)
19
+ "facebook/mms-tts-lug", # Luganda
20
+ "facebook/mms-tts-amh", # Amharic
21
+ "facebook/mms-tts-som", # Somali
22
+ "facebook/mms-tts-sna", # Shona
23
+ "khof312/mms-tts-lin", # Lingala
24
+ "facebook/mms-tts-ara", # Arabic
25
+ ]
26
+
27
+ ok = 0
28
+ for m in MODELS:
29
+ try:
30
+ VitsModel.from_pretrained(m)
31
+ AutoTokenizer.from_pretrained(m)
32
+ print(f" OK {m}")
33
+ ok += 1
34
+ except Exception as e:
35
+ print(f" SKIP {m}: {e}")
36
+
37
+ print(f"{ok}/{len(MODELS)} models cached")