get_and_load_hubert.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from huggingface_hub import hf_hub_download
  2. import os
  3. def load_hubert_new(config, path="assets/hubert/hubert_base.pt"):
  4. from fairseq import checkpoint_utils
  5. models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
  6. [path],
  7. suffix="",
  8. )
  9. hubert_model = models[0]
  10. hubert_model = hubert_model.to(config.device)
  11. if config.is_half:
  12. hubert_model = hubert_model.half()
  13. else:
  14. hubert_model = hubert_model.float()
  15. return hubert_model.eval()
  16. def get_and_load_hubert_new(config):
  17. hubert_path = hf_hub_download(
  18. repo_id="lj1995/VoiceConversionWebUI", filename="hubert_base.pt"
  19. )
  20. return load_hubert_new(config, hubert_path)
  21. def download_rmvpe():
  22. local_dir = os.environ.get("rmvpe_root", "data/models/rvc/rmvpe")
  23. if not os.path.exists(os.path.join(local_dir, "rmvpe.pt")):
  24. print("Downloading rmvpe")
  25. file = hf_hub_download(
  26. repo_id="lj1995/VoiceConversionWebUI",
  27. filename="rmvpe.pt",
  28. local_dir=local_dir,
  29. local_dir_use_symlinks=False,
  30. )
  31. print(f"RMVPE downloaded to {os.environ.get('rmvpe_root')}")
  32. return file