Spaces:
Running on Zero
Running on Zero
AndrianBalanescu commited on
Commit ·
383324d
1
Parent(s): 434c049
fix(zerogpu): fix numpy float audio conversion in MiniMax Music 3
Browse files
app.py
CHANGED
|
@@ -705,6 +705,7 @@ def generate_zerogpu_music(
|
|
| 705 |
# detailed music description and produces complete vocal songs up to 5 min.
|
| 706 |
if repo_id == "MiniMaxAI/MiniMax-Music3":
|
| 707 |
from diffusers import ModularPipeline
|
|
|
|
| 708 |
if repo_id not in _audio_pipeline_cache:
|
| 709 |
pipe = ModularPipeline.from_pretrained(repo_id)
|
| 710 |
pipe.load_components(dtype=torch.bfloat16)
|
|
@@ -712,14 +713,26 @@ def generate_zerogpu_music(
|
|
| 712 |
_audio_pipeline_cache[repo_id] = pipe
|
| 713 |
else:
|
| 714 |
pipe = _audio_pipeline_cache[repo_id]
|
| 715 |
-
|
| 716 |
prompt=prompt.strip(),
|
| 717 |
lyrics=lyrics.strip(),
|
| 718 |
audio_duration=float(dur),
|
| 719 |
generator=torch.Generator("cuda").manual_seed(int(seed)),
|
| 720 |
output="audios",
|
| 721 |
-
)
|
| 722 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 723 |
return out_audio_path
|
| 724 |
|
| 725 |
# Stable Audio 3 uses its own pipeline and may require HF access approval.
|
|
|
|
| 705 |
# detailed music description and produces complete vocal songs up to 5 min.
|
| 706 |
if repo_id == "MiniMaxAI/MiniMax-Music3":
|
| 707 |
from diffusers import ModularPipeline
|
| 708 |
+
import numpy as np
|
| 709 |
if repo_id not in _audio_pipeline_cache:
|
| 710 |
pipe = ModularPipeline.from_pretrained(repo_id)
|
| 711 |
pipe.load_components(dtype=torch.bfloat16)
|
|
|
|
| 713 |
_audio_pipeline_cache[repo_id] = pipe
|
| 714 |
else:
|
| 715 |
pipe = _audio_pipeline_cache[repo_id]
|
| 716 |
+
raw_output = pipe(
|
| 717 |
prompt=prompt.strip(),
|
| 718 |
lyrics=lyrics.strip(),
|
| 719 |
audio_duration=float(dur),
|
| 720 |
generator=torch.Generator("cuda").manual_seed(int(seed)),
|
| 721 |
output="audios",
|
| 722 |
+
)
|
| 723 |
+
audio = raw_output[0]
|
| 724 |
+
if hasattr(audio, "detach"):
|
| 725 |
+
audio_np = audio.detach().cpu().float().numpy()
|
| 726 |
+
elif isinstance(audio, np.ndarray):
|
| 727 |
+
audio_np = audio.astype(np.float32)
|
| 728 |
+
else:
|
| 729 |
+
audio_np = np.asarray(audio, dtype=np.float32)
|
| 730 |
+
|
| 731 |
+
if audio_np.ndim > 1 and audio_np.shape[0] < audio_np.shape[1]:
|
| 732 |
+
audio_np = audio_np.T
|
| 733 |
+
|
| 734 |
+
sr = getattr(pipe, "sampling_rate", 44100)
|
| 735 |
+
sf.write(out_audio_path, audio_np, sr)
|
| 736 |
return out_audio_path
|
| 737 |
|
| 738 |
# Stable Audio 3 uses its own pipeline and may require HF access approval.
|