2b-studio / scripts /e2e_space_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
3.6 kB
"""E2E-Abnahmekette gegen den deployten 2B-Studio-Space (2btainment-2b-studio.hf.space).
Kette: Health -> Producer-Chat -> Apply -> Generate (ACE-Step, 10 s) -> Master-Open
blockiert (Space-Modus). Ein Client = eine Session.
"""
from __future__ import annotations
import os
import sys
import time
from pathlib import Path
from gradio_client import Client
URL = os.environ.get("SPACE_URL", "https://2btainment-2b-studio.hf.space/")
_token_path = Path.home() / ".cache" / "huggingface" / "token"
TOKEN = os.environ.get("HF_TOKEN", "") or (
_token_path.read_text().strip() if _token_path.exists() else ""
)
MODEL = "ace-step" # neues Free-Modell (10-600 s)
DURATION = 10
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, token=TOKEN or None, 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",
any(m in proposal_html for m in ("minimax-music3", "2b-musicgen-small",
"2b-musicgen-medium", "stable-audio-open",
"audioldm2", "ace-step")),
"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", "ace-step"),
f"model={model_id}")
step("Apply füllt Genre", bool(genre and str(genre).strip()), str(genre)[:60])
step("Instrumental gesetzt", bool(instrumental), f"instrumental={instrumental}")
# 3. Generate -> echter Track (ace-step, 10 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:
size = os.path.getsize(track_path)
step("WAV ist nicht leer", size > 100_000, f"{size/1024:.0f} KiB")
# 4. Open Master -> im Space-Modus blockiert (erwartet)
t0 = time.time()
master = client.predict(api_name="/_open_master")
msg, label, original = master
step("Master-Open im Space blockiert", "nur lokal" in str(msg).lower(),
f"{time.time()-t0:.1f}s | {str(msg)[:80]}")
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())