Spaces:
Sleeping
Sleeping
File size: 3,554 Bytes
89040ed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"\n",
"repo_path = Path(\"/content/AudioSep\")\n",
"if not repo_path.exists():\n",
" !git clone https://github.com/Audio-AGI/AudioSep.git\n",
"\n",
"%cd /content/AudioSep"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "pjIhw5ECS_3_"
},
"outputs": [],
"source": [
"!pip install torchlibrosa==0.1.0 gradio==3.47.1 gdown lightning transformers==4.28.1 ftfy braceexpand webdataset soundfile wget h5py"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "t6h9KB3CcjBd"
},
"outputs": [],
"source": [
"checkpoints_dir = Path(\"checkpoint\")\n",
"checkpoints_dir.mkdir(exist_ok=True)\n",
"\n",
"models = (\n",
" (\n",
" \"https://huggingface.co/spaces/badayvedat/AudioSep/resolve/main/checkpoint/audiosep_base_4M_steps.ckpt\",\n",
" checkpoints_dir / \"audiosep_base_4M_steps.ckpt\"\n",
" ),\n",
" (\n",
" \"https://huggingface.co/spaces/badayvedat/AudioSep/resolve/main/checkpoint/music_speech_audioset_epoch_15_esc_89.98.pt\",\n",
" checkpoints_dir / \"music_speech_audioset_epoch_15_esc_89.98.pt\"\n",
" )\n",
")\n",
"\n",
"for model_url, model_path in models:\n",
" if not model_path.exists():\n",
" !wget {model_url} -O {model_path}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "3uDrzCQyY58h"
},
"outputs": [],
"source": [
"!wget \"https://audio-agi.github.io/Separate-Anything-You-Describe/demos/exp31_water drops_mixture.wav\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "0nr77CGXTwO1"
},
"outputs": [],
"source": [
"import torch\n",
"from pipeline import build_audiosep, inference\n",
"\n",
"device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\n",
"\n",
"model = build_audiosep(\n",
" config_yaml='config/audiosep_base.yaml',\n",
" checkpoint_path=str(models[0][1]),\n",
" device=device)\n",
"\n",
"audio_file = 'exp31_water drops_mixture.wav'\n",
"text = 'water drops'\n",
"output_file='separated_audio.wav'\n",
"\n",
"# AudioSep processes the audio at 32 kHz sampling rate\n",
"inference(model, audio_file, text, output_file, device)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "kssOe0pbPSWp"
},
"outputs": [],
"source": [
"print(f\"The separated audio is saved to: '{output_file}' file.\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "sl35U3dAR6KN"
},
"outputs": [],
"source": []
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
|