Converso72 commited on
Commit
bbcb36d
·
verified ·
1 Parent(s): 088c91f

Upload predownload.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. predownload.py +34 -0
predownload.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Pre-download XTTS v2.0 model files during Docker build"""
2
+ import os, urllib.request, time, sys
3
+
4
+ MODEL_DIR = os.path.expanduser("~/.local/share/tts/tts_models--multilingual--multi-dataset--xtts_v2")
5
+ os.makedirs(MODEL_DIR, exist_ok=True)
6
+
7
+ FILES = [
8
+ ("https://coqui.gateway.scarf.sh/hf-coqui/XTTS-v2/main/dvae.pth", "dvae.pth"),
9
+ ("https://coqui.gateway.scarf.sh/hf-coqui/XTTS-v2/main/mel_stats.pth", "mel_stats.pth"),
10
+ ("https://coqui.gateway.scarf.sh/hf-coqui/XTTS-v2/main/model.pth", "model.pth"),
11
+ ("https://coqui.gateway.scarf.sh/hf-coqui/XTTS-v2/main/config.json", "config.json"),
12
+ ("https://coqui.gateway.scarf.sh/hf-coqui/XTTS-v2/main/vocab.json", "vocab.json"),
13
+ ]
14
+
15
+ for url, name in FILES:
16
+ dest = os.path.join(MODEL_DIR, name)
17
+ if os.path.exists(dest) and os.path.getsize(dest) > 1000:
18
+ print(f"{name} already cached ({os.path.getsize(dest)/1e6:.0f} MB)")
19
+ continue
20
+ for attempt in range(5):
21
+ try:
22
+ print(f"Downloading {name}... attempt {attempt+1}/5", flush=True)
23
+ urllib.request.urlretrieve(url, dest)
24
+ size = os.path.getsize(dest) / 1e6
25
+ print(f" OK ({size:.0f} MB)")
26
+ break
27
+ except Exception as e:
28
+ print(f" Error: {str(e)[:100]}")
29
+ if attempt < 4:
30
+ time.sleep(5)
31
+ else:
32
+ print(f" All retries exhausted for {name}")
33
+
34
+ print("Pre-download complete!")