{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "source": [ "\n", "

\n", " \n", "# Advanced RVC Inference v2.1.0\n", "\n", "---\n", "\n", "

\n", "\n", "Advanced RVC Inference presents itself as a state-of-the-art web UI crafted to streamline rapid and effortless inference. This comprehensive toolset encompasses a model downloader, a voice splitter, training, CLI tools and more.\n", "\n", "**v2.1.0 Changelog:** Stability fixes, improved exception handling, new CLI interface, Gradio fork integration, and missing module fixes.\n", "\n", "---\n", "\n", "[Discord](https://discord.gg/hvmsukmBHE) \u2022 [Github](https://github.com/ArkanDash/Advanced-RVC-Inference) \u2022 [CLI Guide](https://github.com/ArkanDash/Advanced-RVC-Inference/wiki/Cli-Guide)" ], "metadata": { "id": "MRUEMUzm9iCh" } }, { "cell_type": "code", "source": [ "# @title Mount Drive\n", "from google.colab import drive\n", "from google.colab._message import MessageError\n", "\n", "try:\n", " drive.mount(\"/content/drive\")\n", "except MessageError:\n", " print(\"\u274c Failed to mount drive\")" ], "metadata": { "cellView": "form", "id": "Geeo7M7DIkcA" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "cellView": "form", "id": "vtON700qokuQ", "collapsed": true }, "outputs": [], "source": [ "# @title Setup runtime environment\n", "# markdown ### Choose installation method:\n", "install_method = \"local\" # @param [\"local\", \"git+uv\"]\n", "\n", "from IPython.display import clear_output\n", "import os\n", "\n", "# Define paths first\n", "LOGS_PATH = \"/content/Advanced-RVC-Inference/advanced_rvc_inference/assets/logs\"\n", "BACKUPS_PATH = \"/content/drive/MyDrive/RVCBackup\"\n", "\n", "# Install system dependencies for audio processing\n", "!apt-get -y install libportaudio2 ffmpeg git -qq > /dev/null 2>&1\n", "\n", "# Install uv for faster package management\n", "!pip install uv -q\n", "\n", "if install_method == 'local':\n", " # Clone from git and install locally (Recommended for development)\n", " if os.path.exists(\"Advanced-RVC-Inference\"):\n", " %cd Advanced-RVC-Inference\n", " !git pull origin master\n", " else:\n", " !git clone https://github.com/ArkanDash/Advanced-RVC-Inference.git\n", " %cd Advanced-RVC-Inference\n", "\n", " !uv pip install -r requirements.txt --system -q\n", "\n", "elif install_method == 'git+uv':\n", " # Install latest version from GitHub with uv (fastest)\n", " # This uses the BF667-IDLE/gradio fork for enhanced Gradio features\n", " !uv pip install git+https://github.com/ArkanDash/Advanced-RVC-Inference.git -q\n", "\n", "\n", "clear_output()\n", "print(\"\u2705 Finished installing Advanced RVC Inference v2.1.0!\")\n", "print(\"Use the cell below to start the server, or use 'rvc-cli' for command-line operations.\")" ] }, { "cell_type": "markdown", "source": [ "# Start Server\n", "\n", "Launch the Gradio web UI using one of the sharing methods below." ], "metadata": { "id": "server-section" } }, { "cell_type": "code", "execution_count": null, "metadata": { "cellView": "form", "id": "nAlXiNYnFH9F", "collapsed": true }, "outputs": [], "source": [ "# @title **Start server**\n", "# @markdown ### Choose a sharing method:\n", "method = \"gradio\" # @param [\"gradio\", \"localtunnel\", \"ngrok\"]\n", "ngrok_token = \"\" # @param {type:\"string\"}\n", "from IPython.display import clear_output\n", "import os\n", "\n", "os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'\n", "os.environ['PYTORCH_ENABLE_MPS_FALLBACK'] = '1'\n", "\n", "# Additional environment variables for better performance\n", "os.environ['CUDA_LAUNCH_BLOCKING'] = '1'\n", "os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'\n", "\n", "# Change to project directory if using local installation\n", "if install_method == 'local':\n", " repo_dir = \"Advanced-RVC-Inference\"\n", " # Check if we're already in the repo directory\n", " if os.path.basename(os.getcwd()) != repo_dir:\n", " if os.path.exists(repo_dir):\n", " %cd $repo_dir\n", " !git pull -q\n", "\n", "clear_output()\n", "print(\"Starting Advanced RVC Inference v2.1.0 Server...\\n\")\n", "\n", "if method == 'gradio':\n", " # Start with Gradio public share link\n", " print(\"Starting Gradio server with public link...\")\n", " !python -m advanced_rvc_inference.app.gui --share\n", "\n", "elif method == 'localtunnel':\n", " !pip install localtunnel -q\n", " clear_output()\n", " print(\"Starting server with localtunnel...\")\n", " print(\"\\nPublic IP: $(curl -s ifconfig.me)\")\n", " print(\"\\nStarting localtunnel in background...\")\n", " # Start localtunnel and RVC server in parallel\n", " !lt --port 7869 --subdomain rvc-advanced &> /tmp/lt.log &\n", " !sleep 5\n", " !rvc-cli serve --host 0.0.0.0\n", "\n", "elif method == 'ngrok':\n", " !pip install pyngrok -q\n", " from pyngrok import ngrok, conf\n", "\n", " # Kill existing ngrok tunnels\n", " ngrok.kill()\n", "\n", " if ngrok_token:\n", " ngrok.set_auth_token(ngrok_token)\n", "\n", " clear_output()\n", " print(\"Starting server with ngrok...\")\n", "\n", " # Create ngrok tunnel\n", " public_url = ngrok.connect(7869)\n", " print(f\"\\nNgrok URL: {public_url}\")\n", "\n", " # Start RVC server via CLI\n", " !rvc-cli serve --host 0.0.0.0 --port 7869\n", "\n", "# Real-time monitoring and backup service (runs in background)\n", "print(\"\\n\\nStarting real-time backup service...\")\n", "print(\"This service will monitor for model changes and auto-backup.\")\n", "\n", "# Create a simple monitoring script\n", "monitor_script = '''\n", "#!/usr/bin/env python3\n", "import os\n", "import time\n", "import json\n", "from pathlib import Path\n", "from datetime import datetime\n", "import shutil\n", "\n", "LOGS_PATH = \"/content/Advanced-RVC-Inference/advanced_rvc_inference/assets/logs\"\n", "BACKUPS_PATH = \"/content/drive/MyDrive/RVCBackup\"\n", "CONFIG_FILE = os.path.join(BACKUPS_PATH, \"backup_config.json\")\n", "\n", "def load_config():\n", " if os.path.exists(CONFIG_FILE):\n", " with open(CONFIG_FILE, 'r') as f:\n", " return json.load(f)\n", " return {}\n", "\n", "def save_config(config):\n", " with open(CONFIG_FILE, 'w') as f:\n", " json.dump(config, f, indent=2)\n", "\n", "def backup_modified_models():\n", " config = load_config()\n", " if not config.get('auto_backup', True):\n", " return\n", "\n", " logs_path = Path(LOGS_PATH)\n", " backup_path = Path(BACKUPS_PATH)\n", "\n", " if not logs_path.exists() or not backup_path.exists():\n", " return\n", "\n", " for model_dir in logs_path.iterdir():\n", " if model_dir.is_dir() and model_dir.name not in ['mute', 'reference', 'zips']:\n", " backup_dir = backup_path / model_dir.name\n", "\n", " # Check if model was modified\n", " if not backup_dir.exists() or \\\n", " model_dir.stat().st_mtime > backup_dir.stat().st_mtime:\n", " try:\n", " if backup_dir.exists():\n", " shutil.rmtree(backup_dir)\n", " shutil.copytree(model_dir, backup_dir)\n", " print(f\"[Auto-Backup] Backed up {model_dir.name}\")\n", " except OSError as e:\n", " print(f\"[Auto-Backup] Failed to backup {model_dir.name}: {e}\")\n", "\n", " config['last_backup'] = datetime.now().isoformat()\n", " save_config(config)\n", "\n", "if __name__ == \"__main__\":\n", " print(\"Real-time backup monitor started...\")\n", " print(f\"Monitoring: {LOGS_PATH}\")\n", " print(f\"Backup to: {BACKUPS_PATH}\")\n", "\n", " while True:\n", " try:\n", " backup_modified_models()\n", " time.sleep(60) # Check every minute\n", " except KeyboardInterrupt:\n", " print(\"\\nBackup monitor stopped.\")\n", " break\n", " except Exception as e:\n", " print(f\"Monitor error: {e}\")\n", " time.sleep(60)\n", "'''\n", "\n", "# Write and start the monitor script\n", "with open('/tmp/backup_monitor.py', 'w') as f:\n", " f.write(monitor_script)\n", "\n", "# Start the monitor in the background\n", "!python /tmp/backup_monitor.py > /tmp/backup_monitor.log 2>&1 &\n", "\n", "print(\"\\n\u2705 Backup service started. Check /tmp/backup_monitor.log for details.\")" ] }, { "cell_type": "markdown", "source": [ "# CLI Usage\n", "\n", "Use `rvc-cli` for command-line voice conversion, audio separation, training, and more.\n", "\n", "See the full [CLI Guide](https://github.com/ArkanDash/Advanced-RVC-Inference/wiki/Cli-Guide) for all available commands and options." ], "metadata": { "id": "cli-section" } }, { "cell_type": "code", "execution_count": null, "metadata": { "cellView": "form", "id": "cli-infer-cell" }, "outputs": [], "source": [ "# @title **CLI: Voice Conversion (Inference)**\n", "# @markdown Convert voice using an RVC model. Make sure the model is in your weights folder or provide the full path.\n", "model_path = \"\" # @param {type:\"string\"}\n", "input_audio = \"\" # @param {type:\"string\"}\n", "output_audio = \"\" # @param {type:\"string\"}\n", "pitch_shift = 0 # @param {type:\"integer\"}\n", "f0_method = \"rmvpe\" # @param [\"rmvpe\", \"crepe-full\", \"fcpe\", \"harvest\", \"pyin\", \"hybrid\"]\n", "output_format = \"wav\" # @param [\"wav\", \"mp3\", \"flac\", \"ogg\"]\n", "\n", "if install_method == 'local':\n", " repo_dir = \"Advanced-RVC-Inference\"\n", " if os.path.basename(os.getcwd()) != repo_dir:\n", " %cd $repo_dir\n", "\n", "cmd = f\"rvc-cli infer -m \\\"{model_path}\\\" -i \\\"{input_audio}\\\"\"\n", "if output_audio:\n", " cmd += f\" -o \\\"{output_audio}\\\"\"\n", "if pitch_shift != 0:\n", " cmd += f\" -p {pitch_shift}\"\n", "cmd += f\" --f0_method {f0_method} -f {output_format}\"\n", "\n", "!{cmd}" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cellView": "form", "id": "cli-uvr-cell" }, "outputs": [], "source": [ "# @title **CLI: Audio Separation (UVR)**\n", "# @markdown Separate vocals from instrumentals using UVR5 models.\n", "input_audio = \"\" # @param {type:\"string\"}\n", "output_dir = \"\" # @param {type:\"string\"}\n", "uvr_model = \"MDXNET_Main\" # @param [\"MDXNET_Main\", \"MDX-NET-2\", \"MDX-Vocals-2\", \"BS-Roformer\", \"Roformer\"]\n", "\n", "if install_method == 'local':\n", " repo_dir = \"Advanced-RVC-Inference\"\n", " if os.path.basename(os.getcwd()) != repo_dir:\n", " %cd $repo_dir\n", "\n", "cmd = f\"rvc-cli uvr -i \\\"{input_audio}\\\" --model {uvr_model}\"\n", "if output_dir:\n", " cmd += f\" -o \\\"{output_dir}\\\"\"\n", "\n", "!{cmd}" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cellView": "form", "id": "cli-download-cell" }, "outputs": [], "source": [ "# @title **CLI: Download Model**\n", "# @markdown Download an RVC model from a URL (HuggingFace, etc.).\n", "download_url = \"\" # @param {type:\"string\"}\n", "model_name = \"\" # @param {type:\"string\"}\n", "\n", "if install_method == 'local':\n", " repo_dir = \"Advanced-RVC-Inference\"\n", " if os.path.basename(os.getcwd()) != repo_dir:\n", " %cd $repo_dir\n", "\n", "cmd = f\"rvc-cli download -l \\\"{download_url}\\\"\"\n", "if model_name:\n", " cmd += f\" -n \\\"{model_name}\\\"\"\n", "\n", "!{cmd}" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cellView": "form", "id": "cli-info-cell" }, "outputs": [], "source": [ "# @title **CLI: System Info & Model List**\n", "# @markdown Show system information and list installed models.\n", "\n", "if install_method == 'local':\n", " repo_dir = \"Advanced-RVC-Inference\"\n", " if os.path.basename(os.getcwd()) != repo_dir:\n", " %cd $repo_dir\n", "\n", "print(\"=== System Information ===\")\n", "!rvc-cli info\n", "print(\"\\n=== Installed Models ===\")\n", "!rvc-cli list-models\n", "print(\"\\n=== Available F0 Methods ===\")\n", "!rvc-cli list-f0-methods" ] }, { "cell_type": "markdown", "source": [ "# BackUp Model" ], "metadata": { "id": "UUzDdNF_D9_m" } }, { "cell_type": "code", "source": [ "\n", "\n", "\n", "\n", "# @markdown ### Enter the name of the model to backup:\n", "model_to_load = \"\" # @param {type:\"string\"}\n", "\n", "import os\n", "import shutil\n", "from google.colab import drive\n", "from google.colab._message import MessageError\n", "\n", "# Mount Google Drive if not already mounted\n", "try:\n", " drive.mount(\"/content/drive\")\n", " print(\"\u2705 Google Drive mounted successfully.\")\n", "except MessageError:\n", " print(\"\u274c Failed to mount drive. It might already be mounted.\")\n", "except Exception as e:\n", " print(f\"An unexpected error occurred while mounting drive: {e}\")\n", "\n", "# Define paths (using values from kernel state for consistency)\n", "LOGS_PATH = f\"/content/Advanced-RVC-Inference/advanced_rvc_inference/assets/logs/{model_to_load}\"\n", "BACKUPS_PATH = \"/content/drive/MyDrive/RVCBackup\"\n", "\n", "print(f\"\\nAttempting to backup logs from: {LOGS_PATH}\")\n", "print(f\"To Google Drive path: {BACKUPS_PATH}\")\n", "\n", "if not os.path.exists(LOGS_PATH):\n", " print(f\"\u274c Error: Source logs path '{LOGS_PATH}' does not exist.\")\n", "else:\n", " os.makedirs(BACKUPS_PATH, exist_ok=True)\n", " print(f\"Ensured backup directory '{BACKUPS_PATH}' exists.\")\n", "\n", " backed_up_count = 0\n", " # Iterate through each model directory in LOGS_PATH\n", " for item in os.listdir(LOGS_PATH):\n", " source_item_path = os.path.join(LOGS_PATH, item)\n", " destination_item_path = os.path.join(BACKUPS_PATH, item)\n", "\n", " # Exclude common non-model log directories\n", " if os.path.isdir(source_item_path) and item not in ['mute', 'reference', 'zips']:\n", " print(f\"Backing up model logs for '{item}'...\")\n", " try:\n", " if os.path.exists(destination_item_path):\n", " shutil.rmtree(destination_item_path) # Remove existing backup to ensure fresh copy\n", " shutil.copytree(source_item_path, destination_item_path)\n", " print(f\"\u2705 Successfully backed up '{item}' logs to '{destination_item_path}'\")\n", " backed_up_count += 1\n", " except OSError as e:\n", " print(f\"\u274c Failed to backup '{item}' logs: {e}\")\n", "\n", " if backed_up_count == 0:\n", " print(\"\u2139\ufe0f No eligible model log directories were found or backed up.\")\n", " else:\n", " print(f\"\\n\u2705 All eligible model logs from '{LOGS_PATH}' have been backed up to '{BACKUPS_PATH}'.\")" ], "metadata": { "cellView": "form", "id": "x5OH50RlCFIw" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "122ca2c6" }, "source": [ "### Load Backup Models from Google Drive\n", "\n", "Enter the name of the model you wish to load from your Google Drive backups. This will copy the model's log data from `RVCBackup` in your Drive back to the `advanced_rvc_inference/assets/logs` directory in the Colab environment." ] }, { "cell_type": "code", "metadata": { "cellView": "form", "id": "3c9e7cee" }, "source": [ "import os\n", "import shutil\n", "from google.colab import drive\n", "from google.colab._message import MessageError\n", "\n", "# Mount Google Drive if not already mounted\n", "try:\n", " drive.mount(\"/content/drive\")\n", " print(\"\u2705 Google Drive mounted successfully.\")\n", "except MessageError:\n", " print(\"\u274c Failed to mount drive. It might already be mounted.\")\n", "except Exception as e:\n", " print(f\"An unexpected error occurred while mounting drive: {e}\")\n", "\n", "# Define paths (using values from kernel state for consistency)\n", "LOGS_PATH = \"/content/Advanced-RVC-Inference/advanced_rvc_inference/assets/logs\"\n", "BACKUPS_PATH = \"/content/drive/MyDrive/RVCBackup\"\n", "\n", "print(f\"\\nAvailable models in backup directory ('{BACKUPS_PATH}'):\")\n", "if not os.path.exists(BACKUPS_PATH):\n", " print(f\"\u274c Backup directory '{BACKUPS_PATH}' does not exist. No backups found.\")\n", "else:\n", " backup_models = [d for d in os.listdir(BACKUPS_PATH) if os.path.isdir(os.path.join(BACKUPS_PATH, d))]\n", " if backup_models:\n", " for i, model_name in enumerate(backup_models):\n", " print(f\" {i+1}. {model_name}\")\n", " else:\n", " print(\" No model backups found in the specified directory.\")\n", "\n", "\n", "# @markdown ### Enter the name of the model to load:\n", "model_to_load = \"\" # @param {type:\"string\"}\n", "\n", "if not model_to_load:\n", " print(\"Please enter a model name to load.\")\n", "elif model_to_load not in backup_models:\n", " print(f\"\u274c Model '{model_to_load}' not found in '{BACKUPS_PATH}'. Please check the name and try again.\")\n", "else:\n", " source_path = os.path.join(BACKUPS_PATH, model_to_load)\n", " destination_path = os.path.join(LOGS_PATH, model_to_load)\n", "\n", " print(f\"\\nAttempting to load model '{model_to_load}' from '{source_path}'\")\n", " print(f\"To Colab environment path: '{destination_path}'\")\n", "\n", " try:\n", " if os.path.exists(destination_path):\n", " shutil.rmtree(destination_path) # Remove existing model data in logs to avoid conflicts\n", " print(f\"Existing model data at '{destination_path}' removed.\")\n", "\n", " shutil.copytree(source_path, destination_path)\n", " print(f\"\u2705 Successfully loaded model '{model_to_load}' to '{destination_path}'.\")\n", " print(\"You may need to refresh the RVC GUI or restart the server to see the loaded model.\")\n", " except OSError as e:\n", " print(f\"\u274c Failed to load model '{model_to_load}': {e}\")" ], "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "# Push The Model" ], "metadata": { "id": "QTI2bz4EEkVq" } }, { "cell_type": "code", "source": [ "\n", "#@title - Join thousands of model makers by uploading your model to huggingface! All you need is your token. https://huggingface.co/settings/tokens\n", "%cd /content\n", "import os\n", "from google.colab import userdata\n", "from huggingface_hub import HfApi, create_repo, login\n", "\n", "HF_TOKEN = \"\" #@param {type:\"string\"}\n", "login(f\"{HF_TOKEN}\")\n", "api = HfApi()\n", "#@markdown Your REPO_ID is the name of your username + whatever you want to name the folder where it will be saved \ud83e\udd17\n", "repo_id = \"NeoPy/My-Voice\" #@param {type:\"string\"}\n", "model_name = \"\" #@param {type:\"string\"}\n", "model_path = f\"/content/Advanced-RVC-Inference/advanced_rvc_inference/assets/logs/{model_name}\"\n", "\n", "try:\n", " create_repo(repo_id)\n", "except Exception as e:\n", " print(f\"Note: {e}. Proceeding...\")\n", "\n", "api.upload_file(\n", " path_or_fileobj=f\"{model_path}/{model_name}.zip\",\n", " path_in_repo=f'{model_name}.zip',\n", " repo_id=repo_id,\n", " repo_type = \"model\"\n", ")" ], "metadata": { "cellView": "form", "id": "cOfsteO3FQQq" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "# CLI: Full Training Pipeline\n", "\n", "Run the complete training pipeline from dataset creation to model training using the CLI." ], "metadata": { "id": "cli-training-section" } }, { "cell_type": "code", "execution_count": null, "metadata": { "cellView": "form", "id": "cli-create-dataset-cell" }, "outputs": [], "source": [ "# @title **CLI: Create Dataset**\n", "# @markdown Create a training dataset from YouTube or local audio files.\n", "source_url = \"\" # @param {type:\"string\"}\n", "output_dir = \"./dataset\" # @param {type:\"string\"}\n", "clean_dataset = True # @param {type:\"boolean\"}\n", "\n", "if install_method == 'local':\n", " repo_dir = \"Advanced-RVC-Inference\"\n", " if os.path.basename(os.getcwd()) != repo_dir:\n", " %cd $repo_dir\n", "\n", "cmd = f\"rvc-cli create-dataset -u \\\"{source_url}\\\" -o \\\"{output_dir}\\\"\"\n", "if clean_dataset:\n", " cmd += \" --clean_dataset\"\n", "\n", "!{cmd}" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cellView": "form", "id": "cli-train-cell" }, "outputs": [], "source": [ "# @title **CLI: Train Model**\n", "# @markdown Train an RVC voice model. Set up your dataset first!\n", "model_name = \"\" # @param {type:\"string\"}\n", "sample_rate = 48000 # @param [\"40000\", \"48000\"]\n", "epochs = 300 # @param {type:\"integer\"}\n", "batch_size = 8 # @param [\"4\", \"8\", \"16\", \"32\"]\n", "save_every = 50 # @param {type:\"integer\"}\n", "gpu_id = \"0\" # @param {type:\"string\"}\n", "\n", "if install_method == 'local':\n", " repo_dir = \"Advanced-RVC-Inference\"\n", " if os.path.basename(os.getcwd()) != repo_dir:\n", " %cd $repo_dir\n", "\n", "cmd = (\n", " f\"rvc-cli train {model_name} \"\n", " f\"--sample_rate {sample_rate} \"\n", " f\"--epochs {epochs} \"\n", " f\"--batch_size {batch_size} \"\n", " f\"--save_every {save_every} \"\n", " f\"--gpu {gpu_id}\"\n", ")\n", "\n", "!{cmd}" ] } ], "metadata": { "accelerator": "GPU", "colab": { "collapsed_sections": [ "NXXzfHi7Db-y", "usage-examples" ], "provenance": [], "private_outputs": true, "include_colab_link": true }, "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 0 }