2b-studio / scripts /e2e_studio_chain.py
2Btainment's picture
2B Studio v2: Toxic-Studio-Redesign, Raum-Leiste, Vorlagen-Bibliothek (30), Verlauf mit Wellenformen, Modell-Status-Chips; Fix MiniMax _studio_state, Paused-Status
d360571 verified
Raw History Blame Contribute Delete
4.53 kB
"""E2E-Abnahmekette gegen die laufende 2B-Studio-Instanz (localhost:7860).
Kette: Producer-Chat -> Apply -> Generate -> Open Master -> Master-Chat
-> Apply Master -> Run ONUS -> Master-WAV.
Ein Client = eine Session (Session-State bleibt erhalten).
"""
from __future__ import annotations
import sys
import time
from gradio_client import Client
URL = "http://localhost:7860/"
MODEL = "audioldm2" # schnellster Worker (~8 s Generierung)
DURATION = 8
results: list[str] = []
def step(name: str, ok: bool, detail: str = "") -> None:
results.append(f"{'PASS' if ok else 'FAIL'} {name}" + (f" | {detail}" if detail else ""))
print(results[-1], flush=True)
def unwrap(value: object) -> object:
"""Gradio-Update-Objekte (dict mit value) auf den eigentlichen Wert reduzieren."""
if isinstance(value, dict) and "value" in value:
return value["value"]
return value
def main() -> int:
client = Client(URL, verbose=False)
# 1. Producer-Chat -> Vorschlag (im HTML gerendert, Index 2)
t0 = time.time()
chat_out = client.predict("Kurzer dunkler Ambient-Track, instrumental", api_name="/producer_chat")
proposal_html = chat_out[2].get("value", "") if isinstance(chat_out[2], dict) else str(chat_out[2])
step("Producer-Chat liefert Vorschlag", "Agent-Vorschlag" in proposal_html,
f"{time.time()-t0:.1f}s")
step("Vorschlag enthält Modell", "2b-musicgen-small" in proposal_html or "minimax" in proposal_html,
"Modell im Vorschlag gerendert")
# 2. Apply -> Felder gefüllt
applied = client.predict(api_name="/_apply_proposal")
model_id, genre, lyrics, negative, instrumental, seconds, _ = [unwrap(a) for a in applied]
step("Apply füllt Modell", model_id in ("minimax-music3", "2b-musicgen-small",
"2b-musicgen-medium", "stable-audio-open", "audioldm2"),
f"model={model_id}")
step("Apply füllt Genre", bool(genre and str(genre).strip()), str(genre)[:60])
step("Apply füllt Lyrics", bool(lyrics and str(lyrics).strip()), str(lyrics)[:40])
step("Instrumental gesetzt", bool(instrumental), f"instrumental={instrumental}")
# 3. Generate -> echter Track (audioldm2, 8 s)
t0 = time.time()
gen = client.predict(
MODEL, genre, lyrics, negative, True, DURATION, 7, api_name="/generate"
)
track_path = gen[0]
step("Generate liefert WAV", bool(track_path and track_path.endswith(".wav")),
f"{time.time()-t0:.1f}s")
if track_path:
import os
size = os.path.getsize(track_path)
step("WAV ist nicht leer", size > 100_000, f"{size/1024:.0f} KiB")
# 4. Open Master -> ONUS-Ebene (lokal aktiv)
t0 = time.time()
master = client.predict(api_name="/_open_master")
msg, label, original = master
step("Master-Ebene öffnet", "ONUS" in msg or "übergeben" in msg.lower(), msg[:80])
# 5. Master-Chat -> Vorschlag (im HTML gerendert, Index 2)
t0 = time.time()
mchat = client.predict("Lauter für Streaming, aber Luft behalten", api_name="/_master_reply")
m_html = mchat[2].get("value", "") if isinstance(mchat[2], dict) else str(mchat[2])
step("Master-Chat liefert Vorschlag", "Agent-Vorschlag" in m_html or "streaming" in m_html.lower(),
f"{time.time()-t0:.1f}s")
step("Master-Profil erkennbar", "streaming_loud" in m_html or "streaming" in m_html.lower(),
"Profil im Vorschlag gerendert")
# 6. Apply Master -> Felder
mapplied = client.predict(api_name="/_apply_master_proposal")
profile, purity, air, margin, intensity, analyze, strict, _ = [unwrap(m) for m in mapplied]
step("Master-Felder gefüllt", bool(profile and purity), f"{profile} · {purity}")
# 7. Run ONUS -> Master-WAV
t0 = time.time()
onus = client.predict(
None, profile, purity, air, margin, intensity, analyze, strict,
api_name="/_run_onus",
)
master_wav = onus[2]
status = onus[8] if len(onus) > 8 else ""
step("ONUS liefert Master-WAV", bool(master_wav and master_wav.endswith(".wav")),
f"{time.time()-t0:.1f}s")
step("ONUS-Status ok", "fertig" in str(status).lower() or "master" in str(status).lower(),
str(status)[:100])
print("\n=== ERGEBNIS ===")
passed = sum(1 for r in results if r.startswith("PASS"))
failed = sum(1 for r in results if r.startswith("FAIL"))
print(f"{passed} PASS, {failed} FAIL")
return 0 if failed == 0 else 1
if __name__ == "__main__":
sys.exit(main())