diff --git a/nbs/Stable_Audio_API.ipynb b/nbs/Stable_Audio_API.ipynb new file mode 100644 index 00000000..52803cbc --- /dev/null +++ b/nbs/Stable_Audio_API.ipynb @@ -0,0 +1,221 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "cellView": "form", + "id": "F5_PrjeRDnNl" + }, + "outputs": [], + "source": [ + "#@title Enter your Stability API key\n", + "# @markdown To get your API key visit https://platform.stability.ai/account/keys\n", + "import getpass, requests, IPython\n", + "STABILITY_KEY = getpass.getpass('Enter your API Key')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Saved txt2audio.mp3\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "#@title Text to Audio\n", + "\n", + "prompt = \"Genre: UK Bass | Instruments: 707 Drum Machine, Strings, 808 bass stabs, Beautiful Synths\" #@param {type:\"string\"}\n", + "duration = 45 #@param {type:\"number\"}\n", + "seed = 0 #@param {type:\"number\"}\n", + "steps = 50 #@param {type:\"number\"}\n", + "cfg_scale = 7.0 #@param {type:\"number\"}\n", + "output_format = \"mp3\" #@param ['mp3', 'wav'] {type:\"string\"}\n", + "\n", + "response = requests.post(\n", + " \"https://api.stability.ai/v2beta/audio/stable-audio-2.0/text-to-audio\",\n", + " headers={\"Authorization\": f\"Bearer {STABILITY_KEY}\", \"Accept\": \"audio/*\"},\n", + " files={\"image\": None},\n", + " data={\n", + " \"prompt\" : prompt,\n", + " \"duration\": duration,\n", + " \"seed\": seed,\n", + " \"steps\": steps,\n", + " \"cfg_scale\" : cfg_scale,\n", + " \"output_format\": output_format,\n", + " }\n", + ")\n", + "if not response.ok:\n", + " raise Exception(f\"HTTP {response.status_code}: {response.text}\")\n", + "\n", + "# Save and show the result\n", + "filename = f\"txt2audio.mp3\"\n", + "with open(filename, \"wb\") as f:\n", + " f.write(response.content)\n", + "print(f\"Saved {filename}\")\n", + "\n", + "IPython.display.display(IPython.display.Audio(filename))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Saved audio2audio.mp3\n", + "\n", + "Original audio:\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Generation result:\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "#@title Audio to Audio\n", + "\n", + "#@markdown - Drag and drop a .wav or .mp3 to file folder on left\n", + "#@markdown - Right click on it and choose Copy path\n", + "#@markdown - Paste that path into audio field below\n", + "#@markdown

\n", + "\n", + "prompt = \"Lofi hip hop beat, chillhop\" #@param {type:\"string\"}\n", + "audio = \"/content/piano.mp3\" #@param {type:\"string\"}\n", + "duration = 45 #@param {type:\"number\"}\n", + "seed = 0 #@param {type:\"number\"}\n", + "steps = 50 #@param {type:\"number\"}\n", + "cfg_scale = 7.0 #@param {type:\"number\"}\n", + "output_format = \"mp3\" #@param ['mp3', 'wav'] {type:\"string\"}\n", + "strength = 1.0 #@param {type:\"number\"}\n", + "\n", + "response = requests.post(\n", + " \"https://api.stability.ai/v2beta/audio/stable-audio-2.0/audio-to-audio\",\n", + " headers={\"Authorization\": f\"Bearer {STABILITY_KEY}\", \"Accept\": \"audio/*\"},\n", + " files={\"audio\": open(audio, \"rb\")},\n", + " data={\n", + " \"prompt\" : prompt,\n", + " \"duration\": duration,\n", + " \"seed\": seed,\n", + " \"steps\": steps,\n", + " \"cfg_scale\" : cfg_scale,\n", + " \"output_format\": output_format,\n", + " \"strength\": strength,\n", + " }\n", + ")\n", + "if not response.ok:\n", + " raise Exception(f\"HTTP {response.status_code}: {response.text}\")\n", + "\n", + "# Save and show the result\n", + "filename = f\"audio2audio.mp3\"\n", + "with open(filename, \"wb\") as f:\n", + " f.write(response.content)\n", + "print(f\"Saved {filename}\")\n", + "\n", + "print(\"\\nOriginal audio:\")\n", + "IPython.display.display(IPython.display.Audio(audio))\n", + "\n", + "print(\"\\nGeneration result:\")\n", + "IPython.display.display(IPython.display.Audio(filename))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "TDWW5DQbDnNo" + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.15" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/src/stability_sdk/interfaces b/src/stability_sdk/interfaces index 5b475498..57bdc2f8 160000 --- a/src/stability_sdk/interfaces +++ b/src/stability_sdk/interfaces @@ -1 +1 @@ -Subproject commit 5b475498665cbccc022aac5bbae989c520f2e894 +Subproject commit 57bdc2f88d63a4a08e6ffcf26ea330cd0faca276