Download model files from Hugging Face repository. Args: repo_id: Hugging Face repository ID cache_dir: Directory to cache downloaded files Returns: KittenTTS_1_Onnx: Instantiated model ready for use
(repo_id="KittenML/kitten-tts-nano-0.1", cache_dir=None)
| 56 | |
| 57 | |
| 58 | def download_from_huggingface(repo_id="KittenML/kitten-tts-nano-0.1", cache_dir=None): |
| 59 | """Download model files from Hugging Face repository. |
| 60 | |
| 61 | Args: |
| 62 | repo_id: Hugging Face repository ID |
| 63 | cache_dir: Directory to cache downloaded files |
| 64 | |
| 65 | Returns: |
| 66 | KittenTTS_1_Onnx: Instantiated model ready for use |
| 67 | """ |
| 68 | # Download config file first |
| 69 | config_path = hf_hub_download( |
| 70 | repo_id=repo_id, |
| 71 | filename="config.json", |
| 72 | cache_dir=cache_dir |
| 73 | ) |
| 74 | |
| 75 | # Load config |
| 76 | with open(config_path, 'r') as f: |
| 77 | config = json.load(f) |
| 78 | |
| 79 | if config.get("type") not in ["ONNX1", "ONNX2"]: |
| 80 | raise ValueError("Unsupported model type.") |
| 81 | |
| 82 | # Download model and voices files based on config |
| 83 | model_path = hf_hub_download( |
| 84 | repo_id=repo_id, |
| 85 | filename=config["model_file"], |
| 86 | cache_dir=cache_dir |
| 87 | ) |
| 88 | |
| 89 | voices_path = hf_hub_download( |
| 90 | repo_id=repo_id, |
| 91 | filename=config["voices"], |
| 92 | cache_dir=cache_dir |
| 93 | ) |
| 94 | |
| 95 | # Instantiate and return model |
| 96 | model = KittenTTS_1_Onnx(model_path=model_path, voices_path=voices_path, speed_priors=config.get("speed_priors", {}) , voice_aliases=config.get("voice_aliases", {})) |
| 97 | |
| 98 | return model |
| 99 | |
| 100 | |
| 101 | def get_model(repo_id="KittenML/kitten-tts-nano-0.1", cache_dir=None): |
no test coverage detected