Instructions to use jamesdon/audiogen-medium-endpoint with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use jamesdon/audiogen-medium-endpoint with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-to-audio", model="jamesdon/audiogen-medium-endpoint")# Load model directly from transformers import AutoProcessor, AutoModelForTextToWaveform processor = AutoProcessor.from_pretrained("jamesdon/audiogen-medium-endpoint") model = AutoModelForTextToWaveform.from_pretrained("jamesdon/audiogen-medium-endpoint", device_map="auto") - Notebooks
- Google Colab
- Kaggle
| from typing import Dict, List, Any | |
| # from transformers import AutoProcessor, MusicgenForConditionalGeneration | |
| # import torch | |
| # import torchaudio | |
| from audiocraft.models import AudioGen | |
| from audiocraft.data.audio import audio_write | |
| class EndpointHandler: | |
| def __init__(self, path=""): | |
| # load model and processor from path | |
| # path = "jamesdon/audiogen-medium-endpoint" | |
| # self.processor = AutoProcessor.from_pretrained(path) | |
| # self.model = MusicgenForConditionalGeneration.from_pretrained(path).to("cuda") | |
| self.model = AudioGen.get_pretrained(path) | |
| def __call__(self, data: Dict[str, Any]) -> Dict[str, str]: | |
| """ | |
| Args: | |
| data (:dict:): | |
| The payload with the text prompt and generation parameters. | |
| """ | |
| # process input | |
| inputs = data.pop("inputs", data) # list of string | |
| duration = data.pop("duration", 5) # seconds to generate | |
| self.model.set_generation_params(duration=duration) | |
| outputs = self.model.generate(inputs) | |
| prediction = outputs[0].cpu().numpy() | |
| return [{"generated_audio": prediction}] |