{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "dC6MxtLlx7vN"
      },
      "source": [
        "# Colab inference for ZFTurbo's [Music-Source-Separation-Training](https://github.com/ZFTurbo/Music-Source-Separation-Training/)\n",
        "\n",
        "\n",
        "<font size=1>*made by [jarredou](https://github.com/jarredou) & deton</font>  \n",
        "[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/Q5Q811R5YI)  "
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "vKOCPJkyw9yh"
      },
      "outputs": [],
      "source": [
        "#@markdown #Gdrive connection\n",
        "from google.colab import drive\n",
        "drive.mount('/content/drive')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "ScA4L7gmQEjM"
      },
      "outputs": [],
      "source": [
        "import base64\n",
        "#@markdown # Install\n",
        "\n",
        "%cd /content\n",
        "!git clone -b colab-inference https://github.com/jarredou/Music-Source-Separation-Training\n",
        "\n",
        "#generate new requirements.txt file for faster colab install\n",
        "req = 'IyB0b3JjaCAjPT0yLjAuMQ0KbnVtcHkNCnBhbmRhcw0Kc2NpcHkNCnNvdW5kZmlsZQ0KbWxfY29sbGVjdGlvbnMNCnRxZG0NCnNlZ21lbnRhdGlvbl9tb2RlbHNfcHl0b3JjaD09MC4zLjMNCnRpbW09PTAuOS4yDQphdWRpb21lbnRhdGlvbnM9PTAuMjQuMA0KcGVkYWxib2FyZD09MC44LjENCm9tZWdhY29uZj09Mi4yLjMNCmJlYXJ0eXBlPT0wLjE0LjENCnJvdGFyeV9lbWJlZGRpbmdfdG9yY2g9PTAuMy41DQplaW5vcHM9PTAuNi4xDQpsaWJyb3NhDQpkZW11Y3MgIz09NC4wLjANCiMgdHJhbnNmb3JtZXJzPT00LjM1LjANCnRvcmNobWV0cmljcz09MC4xMS40DQpzcGFmZT09MC4zLjINCnByb3RvYnVmPT0zLjIwLjMNCnRvcmNoX2F1ZGlvbWVudGF0aW9ucw0KYXN0ZXJvaWQ9PTAuNy4wDQphdXJhbG9zcw0KdG9yY2hzZWcNCg=='\n",
        "dec_req = base64.b64decode(req).decode('utf-8')\n",
        "f = open(\"Music-Source-Separation-Training/requirements.txt\", \"w\")\n",
        "f.write(dec_req)\n",
        "f.close()\n",
        "\n",
        "!mkdir '/content/Music-Source-Separation-Training/ckpts'\n",
        "\n",
        "print('Installing the dependencies... This will take few minutes')\n",
        "!pip install -r 'Music-Source-Separation-Training/requirements.txt' &> /dev/null\n",
        "\n",
        "print('Installation is done !')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "GS-QezQ-RG64"
      },
      "outputs": [],
      "source": [
        "%cd '/content/Music-Source-Separation-Training/'\n",
        "import os\n",
        "import torch\n",
        "import yaml\n",
        "from urllib.parse import quote\n",
        "\n",
        "class IndentDumper(yaml.Dumper):\n",
        "    def increase_indent(self, flow=False, indentless=False):\n",
        "        return super(IndentDumper, self).increase_indent(flow, False)\n",
        "\n",
        "\n",
        "def tuple_constructor(loader, node):\n",
        "    # Load the sequence of values from the YAML node\n",
        "    values = loader.construct_sequence(node)\n",
        "    # Return a tuple constructed from the sequence\n",
        "    return tuple(values)\n",
        "\n",
        "# Register the constructor with PyYAML\n",
        "yaml.SafeLoader.add_constructor('tag:yaml.org,2002:python/tuple',\n",
        "tuple_constructor)\n",
        "\n",
        "\n",
        "\n",
        "def conf_edit(config_path, chunk_size, overlap):\n",
        "    with open(config_path, 'r') as f:\n",
        "        data = yaml.load(f, Loader=yaml.SafeLoader)\n",
        "\n",
        "    # handle cases where 'use_amp' is missing from config:\n",
        "    if 'use_amp' not in data.keys():\n",
        "      data['training']['use_amp'] = True\n",
        "\n",
        "    data['audio']['chunk_size'] = chunk_size\n",
        "    data['inference']['num_overlap'] = overlap\n",
        "\n",
        "    if data['inference']['batch_size'] == 1:\n",
        "      data['inference']['batch_size'] = 2\n",
        "\n",
        "    print(\"Using custom overlap and chunk_size values:\")\n",
        "    print(f\"overlap = {data['inference']['num_overlap']}\")\n",
        "    print(f\"chunk_size = {data['audio']['chunk_size']}\")\n",
        "    print(f\"batch_size = {data['inference']['batch_size']}\")\n",
        "\n",
        "\n",
        "    with open(config_path, 'w') as f:\n",
        "        yaml.dump(data, f, default_flow_style=False, sort_keys=False, Dumper=IndentDumper, allow_unicode=True)\n",
        "\n",
        "def download_file(url):\n",
        "    # Encode the URL to handle spaces and special characters\n",
        "    encoded_url = quote(url, safe=':/')\n",
        "\n",
        "    path = 'ckpts'\n",
        "    os.makedirs(path, exist_ok=True)\n",
        "    filename = os.path.basename(encoded_url)\n",
        "    file_path = os.path.join(path, filename)\n",
        "\n",
        "    if os.path.exists(file_path):\n",
        "        print(f\"File '{filename}' already exists at '{path}'.\")\n",
        "        return\n",
        "\n",
        "    try:\n",
        "        response = torch.hub.download_url_to_file(encoded_url, file_path)\n",
        "        print(f\"File '{filename}' downloaded successfully\")\n",
        "    except Exception as e:\n",
        "        print(f\"Error downloading file '{filename}' from '{url}': {e}\")\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "#@markdown # Separation\n",
        "#@markdown #### Separation config:\n",
        "input_folder = '/content/drive/MyDrive/input' #@param {type:\"string\"}\n",
        "output_folder = '/content/drive/MyDrive/output' #@param {type:\"string\"}\n",
        "model = 'VOCALS-MelBand-Roformer (by KimberleyJSN)' #@param ['VOCALS-MelBand-Roformer (by KimberleyJSN)', 'VOCALS-MelBand-Roformer (by Becruily)' , 'INST-MelBand-Roformer (by Becruily)', 'VOCALS-MelBand-Roformer voc_Fv3 (by Gabox)', 'VOCALS-MelBand-Roformer Kim FT 2 (by Unwa)', 'VOCALS-MelBand-Roformer Kim FT (by Unwa)', 'VOCALS-Melband-Roformer BigBeta5e (by unwa)', 'VOCALS-Mel-Roformer big beta 4 (by unwa)', 'INST-Mel-Roformer v1e (by unwa)', 'INST-Mel-Roformer INSTV5 (by Gabox)', 'INST-Mel-Roformer INSTV6 (by Gabox)', 'INST-VOC-Mel-Roformer a.k.a. duality (by unwa)', 'INST-VOC-Mel-Roformer a.k.a. duality v2 (by unwa)', 'INST-Mel-Roformer v1 (by unwa)', 'INST-Mel-Roformer v2 (by unwa)', 'VOCALS-BS-RoformerLargev1 (by unwa)', 'VOCALS-InstVocHQ', 'VOCALS-BS-Roformer_1297 (by viperx)', 'VOCALS-BS-Roformer_1296 (by viperx)', 'KARAOKE-MelBand-Roformer (by aufr33 & viperx)', 'OTHER-BS-Roformer_1053 (by viperx)', '4STEMS-SCNet_XL_MUSDB18 (by ZFTurbo)', '4STEMS-SCNet_Large (by starrytong)', '4STEMS-BS-Roformer_MUSDB18 (by ZFTurbo)', '4STEMS-SCNet_MUSDB18 (by starrytong)', 'CROWD-REMOVAL-MelBand-Roformer (by aufr33)', 'VOCALS-VitLarge23 (by ZFTurbo)', 'CINEMATIC-BandIt_Plus (by kwatcharasupat)', 'DRUMSEP-MDX23C_DrumSep_6stem (by aufr33 & jarredou)', 'DE-REVERB-MDX23C (by aufr33 & jarredou)', 'DE-REVERB-MelBand-Roformer aggr./v2/19.1729 (by anvuew)', 'DE-REVERB-Echo-MelBand-Roformer (by Sucial)', 'DENOISE-MelBand-Roformer-1 (by aufr33)', 'DENOISE-MelBand-Roformer-2 (by aufr33)', 'DEBLEED-MelBand-Roformer (by unwa/97chris)', 'VOCALS-Male Female-BS-RoFormer Male Female Beta 7_2889 (by aufr33)']\n",
        "extract_instrumental = True #@param {type:\"boolean\"}\n",
        "export_format = 'flac PCM_16' #@param ['wav FLOAT', 'flac PCM_16', 'flac PCM_24']\n",
        "use_tta = True #@param {type:\"boolean\"}\n",
        "#@markdown ---\n",
        "#@markdown *Roformers custom config:*\n",
        "overlap = 2 #@param {type:\"slider\", min:2, max:40, step:1}\n",
        "chunk_size = 485100 #@param [352800, 485100] {type:\"raw\"}\n",
        "\n",
        "if export_format.startswith('flac'):\n",
        "    flac_file = True\n",
        "    pcm_type = export_format.split(' ')[1]\n",
        "else:\n",
        "    flac_file = False\n",
        "    pcm_type = None\n",
        "\n",
        "if model == 'VOCALS-InstVocHQ':\n",
        "    model_type = 'mdx23c'\n",
        "    config_path = 'ckpts/config_vocals_mdx23c.yaml'\n",
        "    start_check_point = 'ckpts/model_vocals_mdx23c_sdr_10.17.ckpt'\n",
        "    download_file('https://raw.githubusercontent.com/ZFTurbo/Music-Source-Separation-Training/main/configs/config_vocals_mdx23c.yaml')\n",
        "    download_file('https://github.com/ZFTurbo/Music-Source-Separation-Training/releases/download/v1.0.0/model_vocals_mdx23c_sdr_10.17.ckpt')\n",
        "\n",
        "elif model == 'VOCALS-MelBand-Roformer (by Becruily)':\n",
        "    model_type = 'mel_band_roformer'\n",
        "    config_path = 'ckpts/config_vocals_becruily.yaml'\n",
        "    start_check_point = 'ckpts/mel_band_roformer_vocals_becruily.ckpt'\n",
        "    download_file('https://huggingface.co/becruily/mel-band-roformer-vocals/resolve/main/config_vocals_becruily.yaml')\n",
        "    download_file('https://huggingface.co/becruily/mel-band-roformer-vocals/resolve/main/mel_band_roformer_vocals_becruily.ckpt')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'INST-MelBand-Roformer (by Becruily)':\n",
        "    model_type = 'mel_band_roformer'\n",
        "    config_path = 'ckpts/config_instrumental_becruily.yaml'\n",
        "    start_check_point = 'ckpts/mel_band_roformer_instrumental_becruily.ckpt'\n",
        "    download_file('https://huggingface.co/becruily/mel-band-roformer-instrumental/resolve/main/config_instrumental_becruily.yaml')\n",
        "    download_file('https://huggingface.co/becruily/mel-band-roformer-instrumental/resolve/main/mel_band_roformer_instrumental_becruily.ckpt')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'VOCALS-MelBand-Roformer (by KimberleyJSN)':\n",
        "    model_type = 'mel_band_roformer'\n",
        "    config_path = 'ckpts/config_vocals_mel_band_roformer_kj.yaml'\n",
        "    start_check_point = 'ckpts/MelBandRoformer.ckpt'\n",
        "    download_file('https://raw.githubusercontent.com/ZFTurbo/Music-Source-Separation-Training/main/configs/KimberleyJensen/config_vocals_mel_band_roformer_kj.yaml')\n",
        "    download_file('https://huggingface.co/KimberleyJSN/melbandroformer/resolve/main/MelBandRoformer.ckpt')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'VOCALS-MelBand-Roformer voc_Fv3 (by Gabox)':\n",
        "    model_type = 'mel_band_roformer'\n",
        "    config_path = 'ckpts/voc_gabox.yaml'\n",
        "    start_check_point = 'ckpts/voc_Fv3.ckpt'\n",
        "    download_file('https://huggingface.co/GaboxR67/MelBandRoformers/resolve/main/melbandroformers/vocals/voc_gabox.yaml')\n",
        "    download_file('https://huggingface.co/GaboxR67/MelBandRoformers/resolve/main/melbandroformers/vocals/voc_Fv3.ckpt')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'VOCALS-MelBand-Roformer Kim FT (by Unwa)':\n",
        "    model_type = 'mel_band_roformer'\n",
        "    config_path = 'ckpts/config_kimmel_unwa_ft.yaml'\n",
        "    start_check_point = 'ckpts/kimmel_unwa_ft.ckpt'\n",
        "    download_file('https://huggingface.co/pcunwa/Kim-Mel-Band-Roformer-FT/resolve/main/config_kimmel_unwa_ft.yaml')\n",
        "    download_file('https://huggingface.co/pcunwa/Kim-Mel-Band-Roformer-FT/resolve/main/kimmel_unwa_ft.ckpt')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'VOCALS-MelBand-Roformer Kim FT 2 (by Unwa)':\n",
        "    model_type = 'mel_band_roformer'\n",
        "    config_path = 'ckpts/config_kimmel_unwa_ft.yaml'\n",
        "    start_check_point = 'ckpts/kimmel_unwa_ft.ckpt'\n",
        "    download_file('https://huggingface.co/pcunwa/Kim-Mel-Band-Roformer-FT/resolve/main/config_kimmel_unwa_ft.yaml')\n",
        "    download_file('https://huggingface.co/pcunwa/Kim-Mel-Band-Roformer-FT/resolve/main/kimmel_unwa_ft2.ckpt')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'VOCALS-BS-Roformer_1297 (by viperx)':\n",
        "    model_type = 'bs_roformer'\n",
        "    config_path = 'ckpts/model_bs_roformer_ep_317_sdr_12.9755.yaml'\n",
        "    start_check_point = 'ckpts/model_bs_roformer_ep_317_sdr_12.9755.ckpt'\n",
        "    download_file('https://raw.githubusercontent.com/ZFTurbo/Music-Source-Separation-Training/main/configs/viperx/model_bs_roformer_ep_317_sdr_12.9755.yaml')\n",
        "    download_file('https://github.com/TRvlvr/model_repo/releases/download/all_public_uvr_models/model_bs_roformer_ep_317_sdr_12.9755.ckpt')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'VOCALS-BS-Roformer_1296 (by viperx)':\n",
        "    model_type = 'bs_roformer'\n",
        "    config_path = 'ckpts/model_bs_roformer_ep_368_sdr_12.9628.yaml'\n",
        "    start_check_point = 'ckpts/model_bs_roformer_ep_368_sdr_12.9628.ckpt'\n",
        "    download_file('https://github.com/TRvlvr/model_repo/releases/download/all_public_uvr_models/model_bs_roformer_ep_368_sdr_12.9628.ckpt')\n",
        "    download_file('https://raw.githubusercontent.com/TRvlvr/application_data/main/mdx_model_data/mdx_c_configs/model_bs_roformer_ep_368_sdr_12.9628.yaml')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'VOCALS-BS-RoformerLargev1 (by unwa)':\n",
        "    model_type = 'bs_roformer'\n",
        "    config_path = 'ckpts/config_bsrofoL.yaml'\n",
        "    start_check_point = 'ckpts/BS-Roformer_LargeV1.ckpt'\n",
        "    download_file('https://huggingface.co/jarredou/unwa_bs_roformer/resolve/main/BS-Roformer_LargeV1.ckpt')\n",
        "    download_file('https://huggingface.co/jarredou/unwa_bs_roformer/raw/main/config_bsrofoL.yaml')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'VOCALS-Melband-Roformer BigBeta5e (by unwa)':\n",
        "    model_type = 'mel_band_roformer'\n",
        "    config_path = 'ckpts/big_beta5e.yaml'\n",
        "    start_check_point = 'ckpts/big_beta5e.ckpt'\n",
        "    download_file('https://huggingface.co/pcunwa/Mel-Band-Roformer-big/resolve/main/big_beta5e.ckpt')\n",
        "    download_file('https://huggingface.co/pcunwa/Mel-Band-Roformer-big/resolve/main/big_beta5e.yaml')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'VOCALS-Mel-Roformer big beta 4 (by unwa)':\n",
        "    model_type = 'mel_band_roformer'\n",
        "    config_path = 'ckpts/config_melbandroformer_big_beta4.yaml'\n",
        "    start_check_point = 'ckpts/melband_roformer_big_beta4.ckpt'\n",
        "    download_file('https://huggingface.co/pcunwa/Mel-Band-Roformer-big/resolve/main/melband_roformer_big_beta4.ckpt')\n",
        "    download_file('https://huggingface.co/pcunwa/Mel-Band-Roformer-big/raw/main/config_melbandroformer_big_beta4.yaml')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'INST-Mel-Roformer v1 (by unwa)':\n",
        "    model_type = 'mel_band_roformer'\n",
        "    config_path = 'ckpts/config_melbandroformer_inst.yaml'\n",
        "    start_check_point = 'ckpts/melband_roformer_inst_v1.ckpt'\n",
        "    download_file('https://huggingface.co/pcunwa/Mel-Band-Roformer-Inst/resolve/main/melband_roformer_inst_v1.ckpt')\n",
        "    download_file('https://huggingface.co/pcunwa/Mel-Band-Roformer-Inst/raw/main/config_melbandroformer_inst.yaml')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'INST-Mel-Roformer v2 (by unwa)':\n",
        "    model_type = 'mel_band_roformer'\n",
        "    config_path = 'ckpts/config_melbandroformer_inst_v2.yaml'\n",
        "    start_check_point = 'ckpts/melband_roformer_inst_v2.ckpt'\n",
        "    download_file('https://huggingface.co/pcunwa/Mel-Band-Roformer-Inst/resolve/main/melband_roformer_inst_v2.ckpt')\n",
        "    download_file('https://huggingface.co/pcunwa/Mel-Band-Roformer-Inst/raw/main/config_melbandroformer_inst_v2.yaml')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'INST-Mel-Roformer v1e (by unwa)':\n",
        "    model_type = 'mel_band_roformer'\n",
        "    config_path = 'ckpts/config_melbandroformer_inst.yaml'\n",
        "    start_check_point = 'ckpts/inst_v1e.ckpt'\n",
        "    download_file('https://huggingface.co/pcunwa/Mel-Band-Roformer-Inst/resolve/main/inst_v1e.ckpt')\n",
        "    download_file('https://huggingface.co/pcunwa/Mel-Band-Roformer-Inst/raw/main/config_melbandroformer_inst.yaml')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "\n",
        "elif model == 'INST-Mel-Roformer INSTV5 (by Gabox)':\n",
        "    model_type = 'mel_band_roformer'\n",
        "    config_path = 'ckpts/inst_gabox.yaml'\n",
        "    start_check_point = 'ckpts/INSTV5.ckpt'\n",
        "    download_file('https://huggingface.co/GaboxR67/MelBandRoformers/resolve/main/melbandroformers/instrumental/INSTV5.ckpt')\n",
        "    download_file('https://huggingface.co/GaboxR67/MelBandRoformers/resolve/main/melbandroformers/instrumental/inst_gabox.yaml')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'INST-Mel-Roformer INSTV6 (by Gabox)':\n",
        "    model_type = 'mel_band_roformer'\n",
        "    config_path = 'ckpts/inst_gabox.yaml'\n",
        "    start_check_point = 'ckpts/INSTV6.ckpt'\n",
        "    download_file('https://huggingface.co/GaboxR67/MelBandRoformers/resolve/main/melbandroformers/instrumental/INSTV6.ckpt')\n",
        "    download_file('https://huggingface.co/GaboxR67/MelBandRoformers/resolve/main/melbandroformers/instrumental/inst_gabox.yaml')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'INST-VOC-Mel-Roformer a.k.a. duality (by unwa)':\n",
        "    model_type = 'mel_band_roformer'\n",
        "    config_path = 'ckpts/config_melbandroformer_instvoc_duality.yaml'\n",
        "    start_check_point = 'ckpts/melband_roformer_instvoc_duality_v1.ckpt'\n",
        "    download_file('https://huggingface.co/pcunwa/Mel-Band-Roformer-InstVoc-Duality/resolve/main/melband_roformer_instvoc_duality_v1.ckpt')\n",
        "    download_file('https://huggingface.co/pcunwa/Mel-Band-Roformer-InstVoc-Duality/raw/main/config_melbandroformer_instvoc_duality.yaml')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'INST-VOC-Mel-Roformer a.k.a. duality v2 (by unwa)':\n",
        "    model_type = 'mel_band_roformer'\n",
        "    config_path = 'ckpts/config_melbandroformer_instvoc_duality.yaml'\n",
        "    start_check_point = 'ckpts/melband_roformer_instvox_duality_v2.ckpt'\n",
        "    download_file('https://huggingface.co/pcunwa/Mel-Band-Roformer-InstVoc-Duality/resolve/main/melband_roformer_instvox_duality_v2.ckpt')\n",
        "    download_file('https://huggingface.co/pcunwa/Mel-Band-Roformer-InstVoc-Duality/raw/main/config_melbandroformer_instvoc_duality.yaml')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'KARAOKE-MelBand-Roformer (by aufr33 & viperx)':\n",
        "    model_type = 'mel_band_roformer'\n",
        "    config_path = 'ckpts/config_mel_band_roformer_karaoke.yaml'\n",
        "    start_check_point = 'ckpts/mel_band_roformer_karaoke_aufr33_viperx_sdr_10.1956.ckpt'\n",
        "    download_file('https://huggingface.co/jarredou/aufr33-viperx-karaoke-melroformer-model/resolve/main/mel_band_roformer_karaoke_aufr33_viperx_sdr_10.1956.ckpt')\n",
        "    download_file('https://huggingface.co/jarredou/aufr33-viperx-karaoke-melroformer-model/resolve/main/config_mel_band_roformer_karaoke.yaml')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'OTHER-BS-Roformer_1053 (by viperx)':\n",
        "    model_type = 'bs_roformer'\n",
        "    config_path = 'ckpts/model_bs_roformer_ep_937_sdr_10.5309.yaml'\n",
        "    start_check_point = 'ckpts/model_bs_roformer_ep_937_sdr_10.5309.ckpt'\n",
        "    download_file('https://github.com/TRvlvr/model_repo/releases/download/all_public_uvr_models/model_bs_roformer_ep_937_sdr_10.5309.ckpt')\n",
        "    download_file('https://raw.githubusercontent.com/TRvlvr/application_data/main/mdx_model_data/mdx_c_configs/model_bs_roformer_ep_937_sdr_10.5309.yaml')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'CROWD-REMOVAL-MelBand-Roformer (by aufr33)':\n",
        "    model_type = 'mel_band_roformer'\n",
        "    config_path = 'ckpts/model_mel_band_roformer_crowd.yaml'\n",
        "    start_check_point = 'ckpts/mel_band_roformer_crowd_aufr33_viperx_sdr_8.7144.ckpt'\n",
        "    download_file('https://github.com/ZFTurbo/Music-Source-Separation-Training/releases/download/v.1.0.4/mel_band_roformer_crowd_aufr33_viperx_sdr_8.7144.ckpt')\n",
        "    download_file('https://github.com/ZFTurbo/Music-Source-Separation-Training/releases/download/v.1.0.4/model_mel_band_roformer_crowd.yaml')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'VOCALS-VitLarge23 (by ZFTurbo)':\n",
        "    model_type = 'segm_models'\n",
        "    config_path = 'ckpts/config_vocals_segm_models.yaml'\n",
        "    start_check_point = 'ckpts/model_vocals_segm_models_sdr_9.77.ckpt'\n",
        "    download_file('https://raw.githubusercontent.com/ZFTurbo/Music-Source-Separation-Training/refs/heads/main/configs/config_vocals_segm_models.yaml')\n",
        "    download_file('https://github.com/ZFTurbo/Music-Source-Separation-Training/releases/download/v1.0.0/model_vocals_segm_models_sdr_9.77.ckpt')\n",
        "\n",
        "elif model == 'CINEMATIC-BandIt_Plus (by kwatcharasupat)':\n",
        "    model_type = 'bandit'\n",
        "    config_path = 'ckpts/config_dnr_bandit_bsrnn_multi_mus64.yaml'\n",
        "    start_check_point = 'ckpts/model_bandit_plus_dnr_sdr_11.47.chpt'\n",
        "    download_file('https://github.com/ZFTurbo/Music-Source-Separation-Training/releases/download/v.1.0.3/config_dnr_bandit_bsrnn_multi_mus64.yaml')\n",
        "    download_file('https://github.com/ZFTurbo/Music-Source-Separation-Training/releases/download/v.1.0.3/model_bandit_plus_dnr_sdr_11.47.chpt')\n",
        "\n",
        "elif model == 'DRUMSEP-MDX23C_DrumSep_6stem (by aufr33 & jarredou)':\n",
        "    model_type = 'mdx23c'\n",
        "    config_path = 'ckpts/aufr33-jarredou_DrumSep_model_mdx23c_ep_141_sdr_10.8059.yaml'\n",
        "    start_check_point = 'ckpts/aufr33-jarredou_DrumSep_model_mdx23c_ep_141_sdr_10.8059.ckpt'\n",
        "    download_file('https://github.com/jarredou/models/releases/download/aufr33-jarredou_MDX23C_DrumSep_model_v0.1/aufr33-jarredou_DrumSep_model_mdx23c_ep_141_sdr_10.8059.ckpt')\n",
        "    download_file('https://github.com/jarredou/models/releases/download/aufr33-jarredou_MDX23C_DrumSep_model_v0.1/aufr33-jarredou_DrumSep_model_mdx23c_ep_141_sdr_10.8059.yaml')\n",
        "\n",
        "elif model == '4STEMS-SCNet_XL_MUSDB18 (by ZFTurbo)':\n",
        "    model_type = 'scnet'\n",
        "    config_path = 'ckpts/config_musdb18_scnet_xl.yaml'\n",
        "    start_check_point = 'ckpts/model_scnet_ep_54_sdr_9.8051.ckpt'\n",
        "    download_file('https://github.com/ZFTurbo/Music-Source-Separation-Training/releases/download/v1.0.13/config_musdb18_scnet_xl.yaml')\n",
        "    download_file('https://github.com/ZFTurbo/Music-Source-Separation-Training/releases/download/v1.0.13/model_scnet_ep_54_sdr_9.8051.ckpt')\n",
        "\n",
        "elif model == '4STEMS-SCNet_Large (by starrytong)':\n",
        "    model_type = 'scnet'\n",
        "    config_path = 'ckpts/config_musdb18_scnet_large_starrytong.yaml'\n",
        "    start_check_point = 'ckpts/SCNet-large_starrytong_fixed.ckpt'\n",
        "    download_file('https://github.com/ZFTurbo/Music-Source-Separation-Training/releases/download/v1.0.9/config_musdb18_scnet_large_starrytong.yaml')\n",
        "    download_file('https://github.com/ZFTurbo/Music-Source-Separation-Training/releases/download/v1.0.9/SCNet-large_starrytong_fixed.ckpt')\n",
        "\n",
        "elif model == '4STEMS-SCNet_MUSDB18 (by starrytong)':\n",
        "    model_type = 'scnet'\n",
        "    config_path = 'ckpts/config_musdb18_scnet.yaml'\n",
        "    start_check_point = 'ckpts/scnet_checkpoint_musdb18.ckpt'\n",
        "    download_file('https://github.com/ZFTurbo/Music-Source-Separation-Training/releases/download/v.1.0.6/config_musdb18_scnet.yaml')\n",
        "    download_file('https://github.com/ZFTurbo/Music-Source-Separation-Training/releases/download/v.1.0.6/scnet_checkpoint_musdb18.ckpt')\n",
        "\n",
        "elif model == '4STEMS-BS-Roformer_MUSDB18 (by ZFTurbo)':\n",
        "    model_type = 'bs_roformer'\n",
        "    config_path = 'ckpts/config_bs_roformer_384_8_2_485100.yaml'\n",
        "    start_check_point = 'ckpts/model_bs_roformer_ep_17_sdr_9.6568.ckpt'\n",
        "    download_file('https://github.com/ZFTurbo/Music-Source-Separation-Training/releases/download/v1.0.12/config_bs_roformer_384_8_2_485100.yaml')\n",
        "    download_file('https://github.com/ZFTurbo/Music-Source-Separation-Training/releases/download/v1.0.12/model_bs_roformer_ep_17_sdr_9.6568.ckpt')\n",
        "\n",
        "elif model == 'DE-REVERB-MDX23C (by aufr33 & jarredou)':\n",
        "    model_type = 'mdx23c'\n",
        "    config_path = 'ckpts/config_dereverb_mdx23c.yaml'\n",
        "    start_check_point = 'ckpts/dereverb_mdx23c_sdr_6.9096.ckpt'\n",
        "    download_file('https://huggingface.co/jarredou/aufr33_jarredou_MDXv3_DeReverb/resolve/main/dereverb_mdx23c_sdr_6.9096.ckpt')\n",
        "    download_file('https://huggingface.co/jarredou/aufr33_jarredou_MDXv3_DeReverb/resolve/main/config_dereverb_mdx23c.yaml')\n",
        "\n",
        "elif model == 'DE-REVERB-MelBand-Roformer aggr./v2/19.1729 (by anvuew)':\n",
        "    model_type = 'mel_band_roformer'\n",
        "    config_path = 'ckpts/dereverb_mel_band_roformer_anvuew.yaml'\n",
        "    start_check_point = 'ckpts/dereverb_mel_band_roformer_anvuew_sdr_19.1729.ckpt'\n",
        "    download_file('https://huggingface.co/anvuew/dereverb_mel_band_roformer/resolve/main/dereverb_mel_band_roformer_anvuew_sdr_19.1729.ckpt')\n",
        "    download_file('https://huggingface.co/anvuew/dereverb_mel_band_roformer/resolve/main/dereverb_mel_band_roformer_anvuew.yaml')\n",
        "\n",
        "elif model == 'DE-REVERB-Echo-MelBand-Roformer (by Sucial)':\n",
        "    model_type = 'mel_band_roformer'\n",
        "    config_path = 'ckpts/config_dereverb-echo_mel_band_roformer.yaml'\n",
        "    start_check_point = 'ckpts/dereverb-echo_mel_band_roformer_sdr_10.0169.ckpt'\n",
        "    download_file('https://huggingface.co/Sucial/Dereverb-Echo_Mel_Band_Roformer/resolve/main/dereverb-echo_mel_band_roformer_sdr_10.0169.ckpt')\n",
        "    download_file('https://huggingface.co/Sucial/Dereverb-Echo_Mel_Band_Roformer/resolve/main/config_dereverb-echo_mel_band_roformer.yaml')\n",
        "\n",
        "elif model == 'DENOISE-MelBand-Roformer-1 (by aufr33)':\n",
        "    model_type = 'mel_band_roformer'\n",
        "    config_path = 'ckpts/model_mel_band_roformer_denoise.yaml'\n",
        "    start_check_point = 'ckpts/denoise_mel_band_roformer_aufr33_sdr_27.9959.ckpt'\n",
        "    download_file('https://huggingface.co/jarredou/aufr33_MelBand_Denoise/resolve/main/denoise_mel_band_roformer_aufr33_sdr_27.9959.ckpt')\n",
        "    download_file('https://huggingface.co/jarredou/aufr33_MelBand_Denoise/resolve/main/model_mel_band_roformer_denoise.yaml')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'DENOISE-MelBand-Roformer-2 (by aufr33)':\n",
        "    model_type = 'mel_band_roformer'\n",
        "    config_path = 'ckpts/model_mel_band_roformer_denoise.yaml'\n",
        "    start_check_point = 'ckpts/denoise_mel_band_roformer_aufr33_aggr_sdr_27.9768.ckpt'\n",
        "    download_file('https://huggingface.co/jarredou/aufr33_MelBand_Denoise/resolve/main/denoise_mel_band_roformer_aufr33_aggr_sdr_27.9768.ckpt')\n",
        "    download_file('https://huggingface.co/jarredou/aufr33_MelBand_Denoise/resolve/main/model_mel_band_roformer_denoise.yaml')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'DEBLEED-MelBand-Roformer (by unwa/97chris)':\n",
        "    model_type = 'mel_band_roformer'\n",
        "    config_path = 'ckpts/config_bleed_suppressor_v1.yaml'\n",
        "    start_check_point = 'ckpts/bleed_suppressor_v1.ckpt'\n",
        "    download_file('https://shared.multimedia.workers.dev/download/1/other/bleed_suppressor_v1.ckpt')\n",
        "    download_file('https://shared.multimedia.workers.dev/download/1/other/config_bleed_suppressor_v1.yaml')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "elif model == 'VOCALS-Male Female-BS-RoFormer Male Female Beta 7_2889 (by aufr33)':\n",
        "    model_type = 'bs_roformer'\n",
        "    config_path = 'ckpts/config_chorus_male_female_bs_roformer.yaml'\n",
        "    start_check_point = 'ckpts/bs_roformer_male_female_by_aufr33_sdr_7.2889.ckpt'\n",
        "    download_file('https://huggingface.co/RareSirMix/AIModelRehosting/resolve/main/bs_roformer_male_female_by_aufr33_sdr_7.2889.ckpt')\n",
        "    download_file('https://huggingface.co/Sucial/Chorus_Male_Female_BS_Roformer/resolve/main/config_chorus_male_female_bs_roformer.yaml')\n",
        "    conf_edit(config_path, chunk_size, overlap)\n",
        "\n",
        "\n",
        "!python inference.py \\\n",
        "    --model_type {model_type} \\\n",
        "    --config_path '{config_path}' \\\n",
        "    --start_check_point '{start_check_point}' \\\n",
        "    --input_folder '{input_folder}' \\\n",
        "    --store_dir '{output_folder}' \\\n",
        "    {('--extract_instrumental' if extract_instrumental else '')} \\\n",
        "    {('--flac_file' if flac_file else '')} \\\n",
        "    {('--use_tta' if use_tta else '')} \\\n",
        "    {('--pcm_type ' + pcm_type if pcm_type else '')}"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "**INST-Mel-Roformer v1/1x/2** has switched output file names - files labelled as vocals are instrumentals (if you uncheck extract_instrumentals for v1e model, only one stem caled \"other\" will be rendered, and it will be instrumental.<br><br>\n",
        "**TTA** - results in longer separation time, \"it gives a little better SDR score but hard to tell if it's really audible in most cases\". <br> it “means \"test time augmentation\", (...) it will do 3 passes on the audio file instead of 1. 1 pass with be with original audio. 1 will be with inverted stereo (L becomes R, R become L). 1 will be with phase inverted and then results are averaged for final output. ” - jarredou\n",
        "<br><br>\n",
        "**Overlap** - higher means longer separation time. 4 is already balanced value, 2 is fast and some people still won't notice any difference. Normally there's not point going over 8.<br><br>\n",
        "If your separation can't start and \"Total files found: 0\" is shown, be aware that: <br>1) Input must be a path to a folder containing audio files, not direct path to an audio file<br> 2) The Colab is case aware - e.g. call your folder \"input\" not \"Input\".<br> 3) Check if your Google Drive mounting was executed correctly. Open file manager on the left to check if your drive folder is not empty. If it's the case, force remount with the following line:"
      ],
      "metadata": {
        "id": "fJ-4Ilx2XTKd"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "drive.mount(\"/content/drive\", force_remount=True)"
      ],
      "metadata": {
        "id": "Tfv8v8jgihdQ"
      },
      "execution_count": null,
      "outputs": []
    }
  ],
  "metadata": {
    "accelerator": "GPU",
    "colab": {
      "gpuType": "T4",
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}