Spaces:
Sleeping
Sleeping
Simplify setup_models.py - MMS auto-downloads on first use
Browse filesFacebook MMS doesn't need pre-download:
- Will download (~200MB) on first Hindi synthesis request
- No TOS prompts (unlike XTTS)
- Auto-cached for subsequent requests
- Much simpler and cleaner
- backend/setup_models.py +7 -44
backend/setup_models.py
CHANGED
|
@@ -1,60 +1,23 @@
|
|
| 1 |
#!/usr/bin/env python
|
| 2 |
-
"""
|
| 3 |
|
| 4 |
-
import os
|
| 5 |
import sys
|
| 6 |
from pathlib import Path
|
| 7 |
|
| 8 |
def setup_models():
|
| 9 |
-
"""Ensure
|
| 10 |
|
| 11 |
print("[Setup] Checking model requirements...")
|
| 12 |
|
| 13 |
-
# Ensure backend/models directory exists
|
| 14 |
models_dir = Path(__file__).parent.parent / "models"
|
| 15 |
models_dir.mkdir(parents=True, exist_ok=True)
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
print(f"[Setup] β XTTS model already present: {tts_model_dir}")
|
| 21 |
-
return True
|
| 22 |
-
|
| 23 |
-
print("[Setup] Downloading XTTS-v2 model (1.8GB, first time only)...")
|
| 24 |
-
print("[Setup] This may take 5-10 minutes on first deployment...")
|
| 25 |
-
|
| 26 |
-
try:
|
| 27 |
-
from TTS.api import TTS
|
| 28 |
-
import io
|
| 29 |
-
|
| 30 |
-
os.environ['TTS_HOME'] = str(models_dir)
|
| 31 |
-
|
| 32 |
-
# Suppress interactive prompts
|
| 33 |
-
old_stdin = sys.stdin
|
| 34 |
-
sys.stdin = io.StringIO("y\n")
|
| 35 |
-
|
| 36 |
-
try:
|
| 37 |
-
tts = TTS(
|
| 38 |
-
model_name="tts_models/multilingual/multi-dataset/xtts_v2",
|
| 39 |
-
gpu=False
|
| 40 |
-
)
|
| 41 |
-
print("[Setup] β XTTS model downloaded successfully")
|
| 42 |
-
|
| 43 |
-
# Verify model exists
|
| 44 |
-
if (tts_model_dir / "model.pth").exists():
|
| 45 |
-
print(f"[Setup] β Model verified at: {tts_model_dir}")
|
| 46 |
-
return True
|
| 47 |
-
else:
|
| 48 |
-
print(f"[Setup] β Model not found at expected location: {tts_model_dir}")
|
| 49 |
-
return False
|
| 50 |
-
|
| 51 |
-
finally:
|
| 52 |
-
sys.stdin = old_stdin
|
| 53 |
-
|
| 54 |
-
except Exception as e:
|
| 55 |
-
print(f"[Setup] β Failed to download XTTS model: {e}")
|
| 56 |
-
print("[Setup] Hindi synthesis will not be available")
|
| 57 |
-
return False
|
| 58 |
|
| 59 |
if __name__ == "__main__":
|
| 60 |
success = setup_models()
|
|
|
|
| 1 |
#!/usr/bin/env python
|
| 2 |
+
"""Setup models on startup - Facebook MMS auto-downloads on first use."""
|
| 3 |
|
|
|
|
| 4 |
import sys
|
| 5 |
from pathlib import Path
|
| 6 |
|
| 7 |
def setup_models():
|
| 8 |
+
"""Ensure models can be loaded (MMS will auto-download on first request)."""
|
| 9 |
|
| 10 |
print("[Setup] Checking model requirements...")
|
| 11 |
|
| 12 |
+
# Ensure backend/models directory exists for caching
|
| 13 |
models_dir = Path(__file__).parent.parent / "models"
|
| 14 |
models_dir.mkdir(parents=True, exist_ok=True)
|
| 15 |
|
| 16 |
+
print("[Setup] β Models directory ready")
|
| 17 |
+
print("[Setup] Hindi: Facebook MMS will download on first request (~200MB)")
|
| 18 |
+
print("[Setup] English: Local models loaded from backend/models/default/")
|
| 19 |
|
| 20 |
+
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
if __name__ == "__main__":
|
| 23 |
success = setup_models()
|