Harshil748 commited on
Commit
b1de92d
Β·
1 Parent(s): ecde958

Fix: Download models from Harshil748/VoiceAPI-Models

Browse files
Files changed (1) hide show
  1. download_models.py +26 -86
download_models.py CHANGED
@@ -1,104 +1,44 @@
1
  #!/usr/bin/env python3
2
  """
3
  Download models from HuggingFace at build time.
4
- Uses SYSPIN's hosted models to avoid storage limits.
5
  """
6
  import os
7
  from pathlib import Path
8
- from huggingface_hub import snapshot_download, hf_hub_download
9
 
10
  MODELS_DIR = Path("models")
11
-
12
- # SYSPIN HuggingFace repos for each language
13
- SYSPIN_REPOS = {
14
- # Bengali
15
- "bn_female": ("SYSPIN/Bengali_Female_TTS", ["bn_female_vits_30hrs.pt", "chars.txt", "jit_infer.py"]),
16
- "bn_male": ("SYSPIN/Bengali_Male_TTS", ["bn_male_vits_30hrs.pt", "chars.txt", "jit_infer.py", "extra.py"]),
17
- # Hindi
18
- "hi_female": ("SYSPIN/Hindi_Female_TTS", ["hi_female_vits_30hrs.pt", "chars.txt", "jit_infer.py", "extra.py"]),
19
- "hi_male": ("SYSPIN/Hindi_Male_TTS", ["hi_male_vits_30hrs.pt", "chars.txt", "jit_infer.py", "extra.py"]),
20
- # Marathi
21
- "mr_female": ("SYSPIN/Marathi_Female_TTS", ["mr_female_vits_30hrs.pt", "chars.txt", "jit_infer.py", "extra.py"]),
22
- "mr_male": ("SYSPIN/Marathi_Male_TTS", ["mr_male_vits_30hrs.pt", "chars.txt", "jit_infer.py", "extra.py"]),
23
- # Telugu
24
- "te_female": ("SYSPIN/Telugu_Female_TTS", ["te_female_vits_30hrs.pt", "chars.txt", "jit_infer.py", "extra.py"]),
25
- "te_male": ("SYSPIN/Telugu_Male_TTS", ["te_male_vits_30hrs.pt", "chars.txt", "jit_infer.py", "extra.py"]),
26
- # Kannada
27
- "kn_female": ("SYSPIN/Kannada_Female_TTS", ["kn_female_vits_30hrs.pt", "chars.txt", "jit_infer.py", "extra.py"]),
28
- "kn_male": ("SYSPIN/Kannada_Male_TTS", ["kn_male_vits_30hrs.pt", "chars.txt", "jit_infer.py", "extra.py"]),
29
- # English
30
- "en_female": ("SYSPIN/English_Female_TTS", ["en_female_vits_30hrs.pt", "chars.txt", "jit_infer.py", "extra.py"]),
31
- "en_male": ("SYSPIN/English_Male_TTS", ["en_male_vits_30hrs.pt", "chars.txt", "jit_infer.py", "extra.py"]),
32
- # Chhattisgarhi
33
- "hne_female": ("SYSPIN/Chhattisgarhi_Female_TTS", ["ch_female_vits_30hrs.pt", "chars.txt", "jit_infer.py", "extra.py"]),
34
- "hne_male": ("SYSPIN/Chhattisgarhi_Male_TTS", ["ch_male_vits_30hrs.pt", "chars.txt", "jit_infer.py", "extra.py"]),
35
- # Maithili
36
- "mai_female": ("SYSPIN/Maithili_Female_TTS", ["mt_female_vits_30hrs.pt", "chars.txt", "jit_infer.py", "extra.py"]),
37
- "mai_male": ("SYSPIN/Maithili_Male_TTS", ["mt_male_vits_30hrs.pt", "chars.txt", "jit_infer.py", "extra.py"]),
38
- # Magahi
39
- "mag_female": ("SYSPIN/Magahi_Female_TTS", ["mg_female_vits_30hrs.pt", "chars.txt", "jit_infer.py", "extra.py"]),
40
- "mag_male": ("SYSPIN/Magahi_Male_TTS", ["mg_male_vits_30hrs.pt", "chars.txt", "jit_infer.py", "extra.py"]),
41
- # Bhojpuri (Coqui TTS format)
42
- "bho_female": ("SYSPIN/Bhojpuri_Female_TTS", ["checkpoint_340000.pth", "config.json"]),
43
- "bho_male": ("SYSPIN/Bhojpuri_Male_TTS", ["checkpoint_200000.pth", "config.json"]),
44
- }
45
-
46
- # Priority voices for demo (download first)
47
- PRIORITY_VOICES = ["hi_female", "bn_female", "en_female", "mr_female", "te_female", "kn_female"]
48
-
49
-
50
- def download_voice(voice_id: str) -> bool:
51
- """Download a single voice model."""
52
- if voice_id not in SYSPIN_REPOS:
53
- print(f"❌ Unknown voice: {voice_id}")
54
- return False
55
-
56
- repo_id, files = SYSPIN_REPOS[voice_id]
57
- voice_dir = MODELS_DIR / voice_id
58
- voice_dir.mkdir(parents=True, exist_ok=True)
59
-
60
- print(f"πŸ“₯ Downloading {voice_id} from {repo_id}...")
61
-
62
- try:
63
- for filename in files:
64
- local_path = voice_dir / filename
65
- if local_path.exists():
66
- print(f" βœ“ {filename} already exists")
67
- continue
68
-
69
- print(f" ⬇️ {filename}...")
70
- hf_hub_download(
71
- repo_id=repo_id,
72
- filename=filename,
73
- local_dir=voice_dir,
74
- local_dir_use_symlinks=False
75
- )
76
- print(f"βœ… {voice_id} downloaded successfully")
77
- return True
78
- except Exception as e:
79
- print(f"❌ Failed to download {voice_id}: {e}")
80
- return False
81
 
82
 
83
  def download_all_models():
84
- """Download all models - priority voices first."""
85
  print("πŸš€ Starting model downloads...")
86
- print(f" Models directory: {MODELS_DIR.absolute()}")
 
87
 
88
  MODELS_DIR.mkdir(exist_ok=True)
89
 
90
- # Download priority voices first
91
- print("\nπŸ“Œ Downloading priority voices...")
92
- for voice_id in PRIORITY_VOICES:
93
- download_voice(voice_id)
94
-
95
- # Download remaining voices
96
- print("\nπŸ“¦ Downloading remaining voices...")
97
- remaining = [v for v in SYSPIN_REPOS.keys() if v not in PRIORITY_VOICES]
98
- for voice_id in remaining:
99
- download_voice(voice_id)
100
-
101
- print("\n✨ Model download complete!")
 
 
 
 
 
 
 
 
102
 
103
 
104
  if __name__ == "__main__":
 
1
  #!/usr/bin/env python3
2
  """
3
  Download models from HuggingFace at build time.
4
+ Downloads from Harshil748/VoiceAPI-Models repo.
5
  """
6
  import os
7
  from pathlib import Path
8
+ from huggingface_hub import snapshot_download
9
 
10
  MODELS_DIR = Path("models")
11
+ MODEL_REPO = "Harshil748/VoiceAPI-Models"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
 
14
  def download_all_models():
15
+ """Download all models from HuggingFace."""
16
  print("πŸš€ Starting model downloads...")
17
+ print(f" Source: {MODEL_REPO}")
18
+ print(f" Target: {MODELS_DIR.absolute()}")
19
 
20
  MODELS_DIR.mkdir(exist_ok=True)
21
 
22
+ try:
23
+ print("\nοΏ½οΏ½ Downloading all models...")
24
+ snapshot_download(
25
+ repo_id=MODEL_REPO,
26
+ local_dir=MODELS_DIR,
27
+ local_dir_use_symlinks=False,
28
+ ignore_patterns=["*.md", ".gitattributes"],
29
+ )
30
+ print("βœ… All models downloaded successfully!")
31
+
32
+ # List downloaded voices
33
+ print("\nπŸ“¦ Downloaded voices:")
34
+ for voice in sorted(MODELS_DIR.iterdir()):
35
+ if voice.is_dir():
36
+ files = list(voice.glob("*"))
37
+ print(f" βœ“ {voice.name}: {len(files)} files")
38
+
39
+ except Exception as e:
40
+ print(f"❌ Failed to download models: {e}")
41
+ raise
42
 
43
 
44
  if __name__ == "__main__":