Spaces:
Running on Zero
Running on Zero
make_video: resolve audio port value robustly
Browse filesThe executor strips 'path' when re-serializing the audio dict between
nodes; accept path/name keys, /gradio_api/file= URLs, or download http(s)
URLs to a temp file.
app.py
CHANGED
|
@@ -715,11 +715,35 @@ def generate_song(lyrics: str, global_meta: str, vocal_details: str, arrangement
|
|
| 715 |
raise gr.Error(_friendly_gpu_error(e)) from e
|
| 716 |
|
| 717 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 718 |
def make_video(audio, title: str):
|
| 719 |
-
"""Render the share visualizer for a generated song. `audio` is the audio port
|
| 720 |
if not audio:
|
| 721 |
raise gr.Error("Generate a song first — make_video needs the Output Song audio.")
|
| 722 |
-
wav_path =
|
|
|
|
|
|
|
| 723 |
out_path = render_video(wav_path, (title or "").strip() or "Untitled")
|
| 724 |
return _save_file(out_path, "minimax-music3-share.mp4", "video/mp4")
|
| 725 |
|
|
|
|
| 715 |
raise gr.Error(_friendly_gpu_error(e)) from e
|
| 716 |
|
| 717 |
|
| 718 |
+
def _audio_to_path(audio):
|
| 719 |
+
# The executor re-serializes port values between nodes, so the audio may arrive as a
|
| 720 |
+
# plain path, a file dict with path/name, or a URL-only dict (path stripped).
|
| 721 |
+
if isinstance(audio, str):
|
| 722 |
+
return audio
|
| 723 |
+
if isinstance(audio, dict):
|
| 724 |
+
for key in ("path", "name"):
|
| 725 |
+
if audio.get(key) and os.path.exists(audio[key]):
|
| 726 |
+
return audio[key]
|
| 727 |
+
url = audio.get("url") or ""
|
| 728 |
+
if url.startswith("/gradio_api/file="):
|
| 729 |
+
return url.split("/gradio_api/file=", 1)[1]
|
| 730 |
+
if url:
|
| 731 |
+
import urllib.request
|
| 732 |
+
|
| 733 |
+
suffix = os.path.splitext(url.split("?")[0])[1] or ".wav"
|
| 734 |
+
dst = os.path.join(tempfile.gettempdir(), f"mm3_in_{os.urandom(8).hex()}{suffix}")
|
| 735 |
+
urllib.request.urlretrieve(url, dst)
|
| 736 |
+
return dst
|
| 737 |
+
return None
|
| 738 |
+
|
| 739 |
+
|
| 740 |
def make_video(audio, title: str):
|
| 741 |
+
"""Render the share visualizer for a generated song. `audio` is the audio port value."""
|
| 742 |
if not audio:
|
| 743 |
raise gr.Error("Generate a song first — make_video needs the Output Song audio.")
|
| 744 |
+
wav_path = _audio_to_path(audio)
|
| 745 |
+
if not wav_path or not os.path.exists(wav_path):
|
| 746 |
+
raise gr.Error("Could not resolve the audio from the previous node — re-run generate_song.")
|
| 747 |
out_path = render_video(wav_path, (title or "").strip() or "Untitled")
|
| 748 |
return _save_file(out_path, "minimax-music3-share.mp4", "video/mp4")
|
| 749 |
|