Download download_models.py from Revrse/sub200: direct link, hf CLI and curl.
- Browser
- Download file 1.72 kB
-
https://huggingface.co/spaces/Revrse/sub200/resolve/main/download_models.py
- Command line
-
hf download hf://spaces/Revrse/sub200/download_models.py
-
curl -L -o download_models.py https://huggingface.co/spaces/Revrse/sub200/resolve/main/download_models.py
1.72 kB
| #!/usr/bin/env python3 | |
| """ | |
| Download Piper TTS models if not present | |
| This script can be run during Docker build or at startup | |
| """ | |
| import os | |
| import urllib.request | |
| import json | |
| def download_piper_model(): | |
| """Download Piper model if not present""" | |
| models_dir = "models" | |
| os.makedirs(models_dir, exist_ok=True) | |
| model_name = "en_US-lessac-low" | |
| model_file = f"{model_name}.onnx" | |
| config_file = f"{model_name}.onnx.json" | |
| model_path = os.path.join(models_dir, model_file) | |
| config_path = os.path.join(models_dir, config_file) | |
| # Check if model already exists | |
| if os.path.exists(model_path) and os.path.exists(config_path): | |
| print(f"Model {model_name} already exists, skipping download") | |
| return | |
| print(f"Downloading Piper model: {model_name}") | |
| # Hugging Face model repository | |
| base_url = "https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_US" | |
| try: | |
| # Download model file | |
| if not os.path.exists(model_path): | |
| print(f"Downloading {model_file}...") | |
| url = f"{base_url}/{model_file}" | |
| urllib.request.urlretrieve(url, model_path) | |
| print(f"Downloaded {model_file}") | |
| # Download config file | |
| if not os.path.exists(config_path): | |
| print(f"Downloading {config_file}...") | |
| url = f"{base_url}/{config_file}" | |
| urllib.request.urlretrieve(url, config_path) | |
| print(f"Downloaded {config_file}") | |
| except Exception as e: | |
| print(f"Error downloading model: {e}") | |
| print("Model download failed, but app will continue with other engines") | |
| if __name__ == "__main__": | |
| download_piper_model() | |