uvr5_tab.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import os
  2. # import sys
  3. import gradio as gr
  4. from tts_webui.history_tab.open_folder import open_folder
  5. from tts_webui.rvc_tab.download_uvr5 import download_uvr5
  6. # from tts_webui.rvc_tab.hide_argv import hide_argv
  7. # import rvc_pkg
  8. # rvc_dir = os.path.dirname(rvc_pkg.__file__)
  9. # sys.path.append(rvc_dir)
  10. # with hide_argv():
  11. # from rvc_pkg.infer.modules.uvr5.modules import uvr
  12. # sys.path.remove(rvc_dir)
  13. # os.environ["TEMP"] = os.path.join(now_dir, "temp", "rvc")
  14. # os.makedirs(os.environ["TEMP"], exist_ok=True)
  15. from rvc.modules.uvr5.modules import UVR
  16. from pathlib import Path
  17. now_dir = os.getcwd()
  18. temp_dir = Path(os.path.join(now_dir, "temp", "rvc"))
  19. UVR5_MODEL_LIST = [
  20. "HP2_all_vocals.pth",
  21. "HP3_all_vocals.pth",
  22. "HP5_only_main_vocal.pth",
  23. "VR-DeEchoAggressive.pth",
  24. "VR-DeEchoDeReverb.pth",
  25. "VR-DeEchoNormal.pth",
  26. # "onnx_dereverb_By_FoxJoy/vocals.onnx",
  27. ]
  28. uvr = None
  29. # fix issue with / in ENV \\ from os.path.join for VR-* models
  30. # os.path.join(os.getenv("weight_uvr5_root"), model_name),
  31. def uvr_wrapper(model_name, agg, input_file):
  32. download_uvr5(model_name)
  33. model_name = model_name.replace(".pth", "")
  34. global uvr
  35. if uvr is None:
  36. uvr = UVR()
  37. results = uvr.uvr_wrapper(
  38. audio_path=Path(input_file),
  39. agg=agg,
  40. model_name=model_name,
  41. temp_dir=temp_dir,
  42. )
  43. wav_instrument, wav_vocals, sample_rate, _agg = results[0]
  44. return (sample_rate, wav_instrument), (sample_rate, wav_vocals)
  45. def uvr5_ui():
  46. with gr.Column():
  47. input_file = gr.Audio(label="Input Audio", type="filepath")
  48. with gr.Column():
  49. with gr.Row():
  50. model_radio = gr.Radio(
  51. label="Model",
  52. choices=UVR5_MODEL_LIST, # type: ignore
  53. value=UVR5_MODEL_LIST[0],
  54. )
  55. agg = gr.Slider(
  56. minimum=0,
  57. maximum=20,
  58. step=1,
  59. label="future-proofing",
  60. value=10,
  61. )
  62. with gr.Row():
  63. convert_button = gr.Button("Convert", variant="primary")
  64. open_folder_button = gr.Button(value="Open outputs folder", variant="secondary")
  65. open_folder_button.click(lambda: open_folder("outputs-rvc"))
  66. output_instrument = gr.Audio(label="Instrument")
  67. output_vocals = gr.Audio(label="Vocals")
  68. convert_button.click(
  69. uvr_wrapper,
  70. [model_radio, agg, input_file],
  71. [output_instrument, output_vocals],
  72. api_name="uvr_convert",
  73. )
  74. def uvr5_tab():
  75. # disabled for now
  76. return
  77. # with gr.TabItem("UVR5 (initial demo version)"):
  78. # uvr5_ui()
  79. if __name__ == "__main__":
  80. with gr.Blocks(
  81. title="TTS Generation WebUI (Bark, MusicGen + AudioGen, Tortoise, RVC)",
  82. ) as demo:
  83. uvr5_tab()
  84. demo.launch(
  85. server_port=7866,
  86. enable_queue=True,
  87. )