AI Music Generation API • Real-time streaming • Custom fine-tune support
Research Project
You can boot this Space directly into your own finetune by setting the variables below in
Settings → Variables and secrets → Variables. If you don't set them, you can still
select models at runtime using /model/select
from the frontend/API.
MRT_CKPT_REPO
→ thepatch/magenta-ft
MRT_CKPT_STEP
→ 1863001
MRT_SIZE
→ large
Those values correspond to the example finetune in this repo (checkpoint_1863001.tgz on top of the large base).
Name | What it does | Example | When to set |
---|---|---|---|
MRT_CKPT_REPO |
Hugging Face repo ID that hosts your finetune checkpoints/assets. | thepatch/magenta-ft |
Set to make this finetune the default on boot. |
MRT_CKPT_STEP |
Checkpoint step number to load on boot. | 1863001 |
Set if you want a specific checkpoint preselected. |
MRT_SIZE |
Base model family used by the finetune (e.g., large). | large |
Set to match the base you finetuned from. |
SPACE_MODE |
Controls readiness behavior: serve (GPU, ready to generate) vs template (CPU template for duplication). If unset, the server auto-detects. |
serve or template |
Set for explicit behavior; otherwise it falls back to auto-detection. |
curl -X POST https://<your-space>.hf.space/model/select \
-H 'Content-Type: application/json' \
-d '{
"ckpt_repo": "thepatch/magenta-ft",
"ckpt_step": 1863001,
"size": "large",
"prewarm": true
}'
When you call prewarm:true
, the backend performs a bar-aligned warmup before returning, so the first jam starts hot.
iPhone app generating music in real-time
This API powers AI music generation using Google's MagentaRT, designed for real-time audio streaming using finetunes hosted on HF. Built for iOS app integration with WebSocket streaming support.
Connect to wss://<your-space>/ws/jam
for real-time audio generation:
{ "type": "start", "mode": "rt", "binary_audio": false, "params": { "styles": "electronic, ambient", "style_weights": "1.0, 0.8", "temperature": 1.1, "topk": 40, "guidance_weight": 1.1, "pace": "realtime", "style_ramp_seconds": 8.0, "mean": 0.0, "centroid_weights": "0.0, 0.0, 0.0" } }
{ "type": "update", "styles": "jazz, hiphop", "style_weights": "1.0, 0.8", "temperature": 1.2, "topk": 64, "guidance_weight": 1.0, "mean": 0.2, "centroid_weights": "0.1, 0.3, 0.0" }
{"type": "stop"}
Train your own MagentaRT models and use them with this API and the iOS app.
Use the official MagentaRT fine-tuning notebook:
This will create checkpoint folders like:
checkpoint_1861001/
checkpoint_1862001/
cluster_centroids.npy
, mean_style_embed.npy
Checkpoints must be compressed as .tgz files to preserve .zarray files correctly.
Use this in a Colab cell to properly package your checkpoints:
# Mount Drive to access your trained checkpoints from google.colab import drive drive.mount('/content/drive') # Set the path to your checkpoint folder CKPT_SRC = '/content/drive/MyDrive/thepatch/checkpoint_1862001' # Adjust path # Copy folder to local storage (preserves dotfiles) !rm -rf /content/checkpoint_1862001 !cp -a "$CKPT_SRC" /content/ # Verify .zarray files are present !find /content/checkpoint_1862001 -name .zarray | wc -l # Create properly formatted .tgz archive !tar -C /content -czf /content/checkpoint_1862001.tgz checkpoint_1862001 # Verify critical files are in the archive !tar -tzf /content/checkpoint_1862001.tgz | grep -c '.zarray' # Download the .tgz file from google.colab import files files.download('/content/checkpoint_1862001.tgz')
Create a model repository and upload:
.tgz
checkpoint filescluster_centroids.npy
(for steering)mean_style_embed.npy
(for steering)In the iOS app's model selector, point to your Hugging Face repository URL. The app will automatically discover available checkpoints and allow switching between them.
/generate_style
endpoint is experimental and may not properly adhere to BPM without additional context (considering metronome-based context instead of silence).
This API is designed to work seamlessly with our iOS music generation app:
To run your own instance:
https://your-username-magenta-retry.hf.space
)This is an active research project. For questions, technical support, or collaboration:
Email: kev@thecollabagepatch.com
Built on Google's MagentaRT (Apache 2.0 + CC-BY 4.0). Users are responsible for their generated outputs and ensuring compliance with applicable laws and platform policies.