Skip to content

Instantly share code, notes, and snippets.

@hathibelagal-dev
Created May 16, 2025 05:04
Show Gist options
  • Select an option

  • Save hathibelagal-dev/2baeb25cb26f474f6da46db248da2bfd to your computer and use it in GitHub Desktop.

Select an option

Save hathibelagal-dev/2baeb25cb26f474f6da46db248da2bfd to your computer and use it in GitHub Desktop.
StableAudioSmall.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"gpuType": "T4",
"authorship_tag": "ABX9TyMIyooOkbNOd0KvleXUJUsk",
"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/gist/hathibelagal-dev/2baeb25cb26f474f6da46db248da2bfd/stableaudiosmall.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"source": [
"!pip install torchsde"
],
"metadata": {
"id": "7uJmgn7sRNJz"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import torch\n",
"import soundfile as sf\n",
"from diffusers import StableAudioPipeline\n",
"\n",
"pipe = StableAudioPipeline.from_pretrained(\"stabilityai/stable-audio-open-1.0\", torch_dtype=torch.float16)"
],
"metadata": {
"id": "Nt2d_T-bQaVq"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"pipe.to(\"cuda\")"
],
"metadata": {
"id": "PtnO4f2zTGg7"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"prompt = \"128 BPM tech house drum loop\"\n",
"negative_prompt = \"Low quality.\""
],
"metadata": {
"id": "nw7iXhBDQm6U"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"audio = pipe(\n",
" prompt,\n",
" negative_prompt=negative_prompt,\n",
" num_inference_steps=50,\n",
" audio_end_in_s=10.0,\n",
" num_waveforms_per_prompt=3,\n",
").audios[0]"
],
"metadata": {
"id": "uSz87b8LQvDu"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"output = audio.T.float().cpu().numpy()\n",
"sf.write(\"beat.wav\", output, pipe.vae.sampling_rate)"
],
"metadata": {
"id": "iAVMsLo9Q1EY"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"from IPython.display import display, Audio\n",
"display(Audio(\"beat.wav\"))"
],
"metadata": {
"id": "x-G1O84sTZS_"
},
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment