Instructions to use onurio/musicgen-large with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use onurio/musicgen-large with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-to-audio", model="onurio/musicgen-large")# Load model directly from transformers import AutoProcessor, AutoModelForTextToWaveform processor = AutoProcessor.from_pretrained("onurio/musicgen-large") model = AutoModelForTextToWaveform.from_pretrained("onurio/musicgen-large", device_map="auto") - Audiocraft
How to use onurio/musicgen-large with Audiocraft:
from audiocraft.models import MusicGen model = MusicGen.get_pretrained("onurio/musicgen-large") descriptions = ['happy rock', 'energetic EDM', 'sad jazz'] wav = model.generate(descriptions) # generates 3 samples. - Notebooks
- Google Colab
- Kaggle
Download test_api.py from onurio/musicgen-large: direct link, hf CLI and curl.
- Browser
- Download file 763 Bytes
-
https://huggingface.co/onurio/musicgen-large/resolve/main/test_api.py
- Command line
-
hf download hf://onurio/musicgen-large/test_api.py
-
curl -L -o test_api.py https://huggingface.co/onurio/musicgen-large/resolve/main/test_api.py
763 Bytes
| import requests | |
| import base64 | |
| import soundfile as sf | |
| import numpy as np | |
| API_URL = "https://qg5sx5kndg4rp1gn.us-east-1.aws.endpoints.huggingface.cloud" | |
| headers = { | |
| "Accept" : "application/json", | |
| "Authorization": "Bearer token", | |
| "Content-Type": "application/json" | |
| } | |
| def query(payload): | |
| response = requests.post(API_URL, headers=headers, json=payload) | |
| return response.json() | |
| response = query({ | |
| "inputs": "deep bass hip hop with trumpet", | |
| "parameters": {} | |
| }) | |
| audio_data = np.array(response["audio_data"], dtype=np.float32) | |
| sampling_rate = response["sampling_rate"] | |
| # Write the audio data to a WAV file | |
| output_file_path = "output.wav" # Specify the file path | |
| sf.write(output_file_path, audio_data, sampling_rate) | |
| print("Audio file saved successfully.") | |