Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions notebooks/HeartLib.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"machine_shape": "hm",
"gpuType": "A100",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/theelderemo/HeartLib-Google-Colab/blob/main/HeartLib.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "YkaqrXnP0WXF",
"collapsed": true
},
"outputs": [],
"source": [
"# @title Setup Environment\n",
"import os\n",
"\n",
"!sudo apt-get update && sudo apt-get install -y ffmpeg\n",
"\n",
"if not os.path.exists(\"heartlib\"):\n",
" !git clone https://github.com/HeartMuLa/heartlib.git\n",
"\n",
"%cd heartlib\n",
"\n",
"!pip install -e .\n",
"!pip install -u \"huggingface_hub[cli]\"\n",
"!pip install flash-attn --no-build-isolation\n",
"!pip install accelerate"
]
},
{
"cell_type": "code",
"source": [
"# @title Download Checkpoints\n",
"import os\n",
"\n",
"if os.path.basename(os.getcwd()) != \"heartlib\":\n",
" %cd heartlib\n",
"\n",
"os.makedirs('./ckpt', exist_ok=True)\n",
"\n",
"!huggingface-cli download --local-dir './ckpt' 'HeartMuLa/HeartMuLaGen'\n",
"!huggingface-cli download --local-dir './ckpt/HeartMuLa-oss-3B' 'HeartMuLa/HeartMuLa-oss-3B'\n",
"!huggingface-cli download --local-dir './ckpt/HeartCodec-oss' 'HeartMuLa/HeartCodec-oss'\n",
"!huggingface-cli download --local-dir './ckpt/HeartTranscriptor-oss' 'HeartMuLa/HeartTranscriptor-oss'"
],
"metadata": {
"id": "OcdLjfex0l6N"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# @title Run Music Generation\n",
"# No Touchy\n",
"import os\n",
"from IPython.display import Audio, display\n",
"import torch\n",
"\n",
"torch.backends.cuda.matmul.allow_tf32 = True\n",
"torch.backends.cudnn.allow_tf32 = True\n",
"torch.set_float32_matmul_precision('high')\n",
"\n",
"os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'max_split_size_mb:512'\n",
"os.environ['CUDA_LAUNCH_BLOCKING'] = '0'\n",
"\n",
"# -----------------------------------------------------------------------------\n",
"# 1. SETUP YOUR LYRICS AND TAGS (you can touch this lol)\n",
"# -----------------------------------------------------------------------------\n",
"my_lyrics = \"\"\"\n",
"[Verse]\n",
"The sun creeps in across the floor\n",
"I hear the traffic outside the door\n",
"The coffee pot begins to hiss\n",
"It is another morning just like this\n",
"\n",
"[Chorus]\n",
"Every day the light returns\n",
"Every day the fire burns\n",
"\"\"\"\n",
"\n",
"my_tags = \"piano,happy,pop\"\n",
"# -----------------------------------------------------------------------------\n",
"# Do Not Touch This Code Below, lol.\n",
"\n",
"if os.path.basename(os.getcwd()) != \"heartlib\":\n",
" if os.path.exists(\"heartlib\"):\n",
" %cd heartlib\n",
" else:\n",
" raise FileNotFoundError(\"Repo not found. Please run Block 1 (Setup) first.\")\n",
"\n",
"!python ./examples/run_music_generation.py \\\n",
" --model_path=./ckpt \\\n",
" --version=\"3B\" \\\n",
" --lyrics=\"$my_lyrics\" \\\n",
" --tags=\"$my_tags\" \\\n",
" --save_path=\"./assets/output.mp3\"\n",
"\n",
"if os.path.exists(\"./assets/output.mp3\"):\n",
" print(\"✓ Generation complete!\")\n",
" display(Audio(\"./assets/output.mp3\"))\n",
"else:\n",
" print(\"✗ Generation failed. Check logs above.\")\n"
],
"metadata": {
"id": "m7i-Cm0j0o3d"
},
"execution_count": null,
"outputs": []
}
]
}
90 changes: 90 additions & 0 deletions notebooks/heartlib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# -*- coding: utf-8 -*-
"""HeartLib.ipynb

Automatically generated by Colab.

Original file is located at
https://colab.research.google.com/drive/19yVmN9HIomBSi89nnpkUqzNkd8Ddb4sn
"""

# Commented out IPython magic to ensure Python compatibility.
# @title Setup Environment
import os

!sudo apt-get update && sudo apt-get install -y ffmpeg

if not os.path.exists("heartlib"):
!git clone https://github.com/HeartMuLa/heartlib.git

# %cd heartlib

!pip install -e .
!pip install -u "huggingface_hub[cli]"
!pip install flash-attn --no-build-isolation
!pip install accelerate

# Commented out IPython magic to ensure Python compatibility.
# @title Download Checkpoints
import os

if os.path.basename(os.getcwd()) != "heartlib":
# %cd heartlib

os.makedirs('./ckpt', exist_ok=True)

!huggingface-cli download --local-dir './ckpt' 'HeartMuLa/HeartMuLaGen'
!huggingface-cli download --local-dir './ckpt/HeartMuLa-oss-3B' 'HeartMuLa/HeartMuLa-oss-3B'
!huggingface-cli download --local-dir './ckpt/HeartCodec-oss' 'HeartMuLa/HeartCodec-oss'
!huggingface-cli download --local-dir './ckpt/HeartTranscriptor-oss' 'HeartMuLa/HeartTranscriptor-oss'

# Commented out IPython magic to ensure Python compatibility.
# @title Run Music Generation
# No Touchy
import os
from IPython.display import Audio, display
import torch

torch.backends.cuda.matmul.allow_tf32 = True
torch.backends.cudnn.allow_tf32 = True
torch.set_float32_matmul_precision('high')

os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'max_split_size_mb:512'
os.environ['CUDA_LAUNCH_BLOCKING'] = '0'

# -----------------------------------------------------------------------------
# 1. SETUP YOUR LYRICS AND TAGS (you can touch this lol)
# -----------------------------------------------------------------------------
my_lyrics = """
[Verse]
The sun creeps in across the floor
I hear the traffic outside the door
The coffee pot begins to hiss
It is another morning just like this

[Chorus]
Every day the light returns
Every day the fire burns
"""

my_tags = "piano,happy,pop"
# -----------------------------------------------------------------------------
# Do Not Touch This Code Below, lol.

if os.path.basename(os.getcwd()) != "heartlib":
if os.path.exists("heartlib"):
# %cd heartlib
else:
raise FileNotFoundError("Repo not found. Please run Block 1 (Setup) first.")

!python ./examples/run_music_generation.py \
--model_path=./ckpt \
--version="3B" \
--lyrics="$my_lyrics" \
--tags="$my_tags" \
--save_path="./assets/output.mp3"

if os.path.exists("./assets/output.mp3"):
print("✓ Generation complete!")
display(Audio("./assets/output.mp3"))
else:
print("✗ Generation failed. Check logs above.")