Delete MuseBot-MusicGen-RVC-Colab.ipynb
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# MuseBot \u2014 MusicGen + RVC Automatic Colab\n", "\n", "This Colab notebook is prepared to run **MusicGen (instrument)** + **RVC (voice conversion)** pipeline with automatic style selection.\n", "\n", "Instructions:\n", "1. Open this notebook in Google Colab (use the provided download link). \n", "2. Select **Runtime > Change runtime type > GPU** and Runtime > Run all. \n", "3. Upload a 10\u201320s clean WAV voice sample when prompted (optional). \n", "4. Wait for the notebook to finish; download `final_<style>.wav` files from the Files panel.\n", "\n", "Notes:\n", "- This notebook uses `facebook/musicgen-small` by default to reduce GPU memory usage. \n", "- RVC model weights are downloaded automatically (placeholders included). \n", "- If you want higher-quality results or a custom RVC checkpoint, upload the `.pth` file when requested.\n" ] }, { "cell_type": "code", "metadata": {}, "outputs": [], "source": [ "# Cell 1: Environment setup\n", "!nvidia-smi || true\n", "!pip install --upgrade pip -q\n", "# Compatible versions to avoid safetensors/transformers conflicts\n", "!pip install 'transformers==4.39.3' 'safetensors==0.4.2' torch --quiet\n", "!pip install librosa soundfile pyloudnorm audiocraft --quiet\n", "!git clone https://github.com/RVC-Project/Retrieval-based-Voice-Conversion.git rvc || true\n", "!pip install -r rvc/requirements.txt --quiet || true\n", "print('Environment setup complete')\n" ] }, { "cell_type": "code", "metadata": {}, "outputs": [], "source": [ "# Cell 2: Upload voice sample (optional but recommended)\n", "from google.colab import files\n", "print('\\n--- Upload 10-20s clean voice sample (WAV recommended) ---')\n", "uploaded = files.upload()\n", "voice_sample_path = None\n", "for fn in uploaded.keys():\n", " voice_sample_path = fn\n", "print('Uploaded sample:', voice_sample_path)\n" ] }, { "cell_type": "code", "metadata": {}, "outputs": [], "source": [ "# Cell 3: Automatic lyrics generation (English) \u2014 GPT-2 fallback (no OpenAI key required)\n", "import torch\n", "from transformers import pipeline\n", "device = 0 if torch.cuda.is_available() else -1\n", "text_gen = pipeline('text-generation', model='gpt2', device=device)\n", "prompt_templates = {\n", " 'pop': 'Write a catchy radio-friendly English pop chorus and short verse about joy and freedom:\\n',\n", " 'rock': 'Write an energetic rock-style English chorus and short verse about hope and defiance:\\n',\n", " 'dance': 'Write an upbeat dance/EDM English chorus and short verse about nightlife and celebration:\\n',\n", " 'country': 'Write a warm American country-style English chorus and short verse about small-town life and love:\\n',\n", " 'gospel': 'Write a heartfelt gospel/Christian English chorus and short verse praising faith and hope:\\n'\n", "}\n", "lyrics_by_style = {}\n", "for style, prompt in prompt_templates.items():\n", " out = text_gen(prompt, max_length=120, do_sample=True, temperature=0.9)[0]['generated_text']\n", " lyrics_by_style[style] = out[len(prompt):].strip()\n", "print('\\n--- Generated lyrics (samples) ---')\n", "for k,v in lyrics_by_style.items():\n", " print(f'[{k.upper()}]\\n{v}\\n')\n" ] }, { "cell_type": "code", "metadata": {}, "outputs": [], "source": [ "# Cell 4: MusicGen instrumentation generation\n", "from audiocraft.models import MusicGen\n", "MODEL_SIZE = 'small' # change to 'medium' or 'large' if you have a powerful GPU\n", "model_name = 'facebook/musicgen-small' if MODEL_SIZE=='small' else ('facebook/musicgen-medium' if MODEL_SIZE=='medium' else 'facebook/musicgen-large')\n", "print('Loading MusicGen model:', model_name)\n", "model = MusicGen.get_pretrained(model_name)\n", "model.set_generation_params(duration=30)\n", "style_prompts = {\n", " 'pop':'energetic pop with bright guitar and punchy drums, 120 bpm',\n", " 'rock':'driving rock with electric guitar riffs and strong drums, 120 bpm',\n", " 'dance':'upbeat dance with strong synth leads, 128 bpm',\n", " 'country':'acoustic country with warm guitar and steady drums, 100 bpm',\n", " 'gospel':'uplifting gospel with organ and choir, 90 bpm'\n", "}\n", "generated_instruments = {}\n", "for style, sprompt in style_prompts.items():\n", " print('Generating:', style)\n", " wavs = model.generate([sprompt])\n", " outname = f'musicgen_{style}.wav'\n", " model.save_audio(outname, wavs[0], 32000)\n", " generated_instruments[style] = outname\n", "print('Instrument generation done. Files:', generated_instruments)\n" ] }, { "cell_type": "code", "metadata": {}, "outputs": [], "source": [ "# Cell 5: Download RVC model weights (automatic selection by style)\n", "import os\n", "os.makedirs('rvc/weights', exist_ok=True)\n", "def download_if_missing(url, path):\n", " if os.path.exists(path):\n", " print('Already exists:', path)\n", " return\n", " print('Downloading', url)\n", " !wget -q -O {path} {url}\n", "\n", "rvc_models = {\n", " 'female': 'https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/weights/Shiroko_Singing.pth',\n", " 'male': 'https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/weights/Jun_Male_Singing.pth'\n", "}\n", "style_to_vocal = {'pop':'female','dance':'female','gospel':'female','rock':'male','country':'male'}\n", "for k,v in rvc_models.items():\n", " download_if_missing(v, f'rvc/weights/{k}.pth')\n", "print('RVC model files ready in rvc/weights (if download links are available)')\n" ] }, { "cell_type": "code", "metadata": {}, "outputs": [], "source": [ "# Cell 6: RVC inference (placeholder and guidance)\n", "print('RVC inference varies across forks. This cell provides guidance and tries a simple demo if inference script exists.')\n", "import os\n", "if os.path.exists('rvc/weights/female.pth') or os.path.exists('rvc/weights/male.pth'):\n", " print('RVC checkpoints are present. You should follow the rvc repo README to run the exact inference command for that fork.')\n", "else:\n", " print('No RVC checkpoint found. You can upload one via Files panel or re-run the weights download cell.')\n", "\n", "print('\\nNote: Different RVC forks expect different CLI parameters. If you want, share which RVC fork you prefer and I will add the exact inference command.')\n" ] }, { "cell_type": "code", "metadata": {}, "outputs": [], "source": [ "# Cell 7: Simple placeholder vocal creation (if no RVC checkpoint) and mixing\n", "import soundfile as sf\n", "import numpy as np\n", "from librosa.effects import pitch_shift\n", "\n", "for style, inst_file in generated_instruments.items():\n", " if not os.path.exists(inst_file):\n", " continue\n", " print('Processing style:', style)\n", " y_inst, sr = sf.read(inst_file)\n", " # create a naive vocal placeholder by pitch-shifting the instrument\n", " try:\n", " y_voc = pitch_shift(y_inst.astype(float), sr, n_steps=3.0)\n", " except Exception:\n", " # mono fallback\n", " y_inst_mono = np.mean(y_inst, axis=1) if y_inst.ndim>1 else y_inst\n", " y_voc = pitch_shift(y_inst_mono.astype(float), sr, n_steps=3.0)\n", " min_len = min(len(y_inst), len(y_voc))\n", " mix = 0.7*y_inst[:min_len] + 0.9*y_voc[:min_len]\n", " mix = mix / (np.max(np.abs(mix))+1e-6) * 0.95\n", " outname = f'final_{style}.wav'\n", " sf.write(outname, mix, sr)\n", " print('Wrote', outname)\n" ] }, { "cell_type": "code", "metadata": {}, "outputs": [], "source": [ "# Cell 8: List and download final files\n", "!ls -1 final_*.wav || true\n", "from google.colab import files as gcfiles\n", "for fn in ['final_pop.wav','final_rock.wav','final_dance.wav','final_country.wav','final_gospel.wav']:\n", " if os.path.exists(fn):\n", " print('Ready to download:', fn)\n", " # Uncomment next line to auto-download (commented to avoid auto popups)\n", " # gcfiles.download(fn)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Next steps / Tips\n", "- If you want true RVC-generated vocals (not placeholders), provide a compatible RVC `.pth` checkpoint or tell me which RVC fork you prefer and I'll add the exact inference cell. \n", "- After downloading `final_*.wav`, bring files into your local MuseBot for the mixing/mastering profile transfer. \n", "- When you finish, revoke any temporary HF token you created for security.\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.10" } }, "nbformat": 4, "nbformat_minor": 5}MuseBot-MusicGen-RVC-Colab.ipynbDeleted-219