Instructions to use jauntybrain/musicgen-small with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use jauntybrain/musicgen-small with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-to-audio", model="jauntybrain/musicgen-small")# Load model directly from transformers import AutoProcessor, AutoModelForTextToWaveform processor = AutoProcessor.from_pretrained("jauntybrain/musicgen-small") model = AutoModelForTextToWaveform.from_pretrained("jauntybrain/musicgen-small") - Notebooks
- Google Colab
- Kaggle
Commit ·
33b11ab
1
Parent(s): 3408f20
Update handler.py
Browse files- handler.py +2 -2
handler.py
CHANGED
|
@@ -31,13 +31,13 @@ class EndpointHandler:
|
|
| 31 |
|
| 32 |
# pass inputs with all kwargs in data
|
| 33 |
with torch.autocast("cuda"):
|
| 34 |
-
audio_values = self.model.generate(**inputs, do_sample=
|
| 35 |
|
| 36 |
# postprocess the prediction
|
| 37 |
sampling_rate = self.model.config.audio_encoder.sampling_rate
|
| 38 |
audio_samples = audio_values[0].cpu().numpy()[0].tolist()
|
| 39 |
|
| 40 |
-
audio_samples = [int(min(max(sample *
|
| 41 |
|
| 42 |
# Create BytesIO object to capture the audio in-memory
|
| 43 |
audio_io = io.BytesIO()
|
|
|
|
| 31 |
|
| 32 |
# pass inputs with all kwargs in data
|
| 33 |
with torch.autocast("cuda"):
|
| 34 |
+
audio_values = self.model.generate(**inputs, do_sample=True, guidance_scale=3, max_new_tokens=400)
|
| 35 |
|
| 36 |
# postprocess the prediction
|
| 37 |
sampling_rate = self.model.config.audio_encoder.sampling_rate
|
| 38 |
audio_samples = audio_values[0].cpu().numpy()[0].tolist()
|
| 39 |
|
| 40 |
+
audio_samples = [int(min(max(sample * 32000, -32000), 32000)) for sample in audio_samples]
|
| 41 |
|
| 42 |
# Create BytesIO object to capture the audio in-memory
|
| 43 |
audio_io = io.BytesIO()
|