2Btainment commited on
Commit
c60d963
·
verified ·
1 Parent(s): b3eaf35

Space-E2E-Skript (ACE-Step, 8/8 PASS)

Browse files
Files changed (1) hide show
  1. scripts/e2e_space_chain.py +90 -0
scripts/e2e_space_chain.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """E2E-Abnahmekette gegen den deployten 2B-Studio-Space (2btainment-2b-studio.hf.space).
2
+
3
+ Kette: Health -> Producer-Chat -> Apply -> Generate (ACE-Step, 10 s) -> Master-Open
4
+ blockiert (Space-Modus). Ein Client = eine Session.
5
+ """
6
+ from __future__ import annotations
7
+
8
+ import os
9
+ import sys
10
+ import time
11
+
12
+ from gradio_client import Client
13
+
14
+ URL = os.environ.get("SPACE_URL", "https://2btainment-2b-studio.hf.space/")
15
+ TOKEN = os.environ.get("HF_TOKEN", "") or (
16
+ open(os.path.expanduser("~/.cache/huggingface/token")).read().strip()
17
+ if os.path.exists(os.path.expanduser("~/.cache/huggingface/token"))
18
+ else ""
19
+ )
20
+ MODEL = "ace-step" # neues Free-Modell (10-600 s)
21
+ DURATION = 10
22
+
23
+ results: list[str] = []
24
+
25
+
26
+ def step(name: str, ok: bool, detail: str = "") -> None:
27
+ results.append(f"{'PASS' if ok else 'FAIL'} {name}" + (f" | {detail}" if detail else ""))
28
+ print(results[-1], flush=True)
29
+
30
+
31
+ def unwrap(value: object) -> object:
32
+ """Gradio-Update-Objekte (dict mit value) auf den eigentlichen Wert reduzieren."""
33
+ if isinstance(value, dict) and "value" in value:
34
+ return value["value"]
35
+ return value
36
+
37
+
38
+ def main() -> int:
39
+ client = Client(URL, token=TOKEN or None, verbose=False)
40
+
41
+ # 1. Producer-Chat -> Vorschlag (im HTML gerendert, Index 2)
42
+ t0 = time.time()
43
+ chat_out = client.predict("Kurzer dunkler Ambient-Track, instrumental", api_name="/lambda_2")
44
+ proposal_html = chat_out[2].get("value", "") if isinstance(chat_out[2], dict) else str(chat_out[2])
45
+ step("Producer-Chat liefert Vorschlag", "Agent-Vorschlag" in proposal_html,
46
+ f"{time.time()-t0:.1f}s")
47
+ step("Vorschlag enthält Modell",
48
+ any(m in proposal_html for m in ("minimax-music3", "2b-musicgen-small",
49
+ "2b-musicgen-medium", "stable-audio-open",
50
+ "audioldm2", "ace-step")),
51
+ "Modell im Vorschlag gerendert")
52
+
53
+ # 2. Apply -> Felder gefüllt
54
+ applied = client.predict(api_name="/_apply_proposal")
55
+ model_id, genre, lyrics, negative, instrumental, seconds, _ = [unwrap(a) for a in applied]
56
+ step("Apply füllt Modell", model_id in ("minimax-music3", "2b-musicgen-small",
57
+ "2b-musicgen-medium", "stable-audio-open",
58
+ "audioldm2", "ace-step"),
59
+ f"model={model_id}")
60
+ step("Apply füllt Genre", bool(genre and str(genre).strip()), str(genre)[:60])
61
+ step("Instrumental gesetzt", bool(instrumental), f"instrumental={instrumental}")
62
+
63
+ # 3. Generate -> echter Track (ace-step, 10 s)
64
+ t0 = time.time()
65
+ gen = client.predict(
66
+ MODEL, genre, lyrics, negative, True, DURATION, 7, api_name="/lambda"
67
+ )
68
+ track_path = gen[0]
69
+ step("Generate liefert WAV", bool(track_path and track_path.endswith(".wav")),
70
+ f"{time.time()-t0:.1f}s")
71
+ if track_path:
72
+ size = os.path.getsize(track_path)
73
+ step("WAV ist nicht leer", size > 100_000, f"{size/1024:.0f} KiB")
74
+
75
+ # 4. Open Master -> im Space-Modus blockiert (erwartet)
76
+ t0 = time.time()
77
+ master = client.predict(api_name="/_open_master")
78
+ msg, label, original = master
79
+ step("Master-Open im Space blockiert", "nur lokal" in str(msg).lower(),
80
+ f"{time.time()-t0:.1f}s | {str(msg)[:80]}")
81
+
82
+ print("\n=== ERGEBNIS ===")
83
+ passed = sum(1 for r in results if r.startswith("PASS"))
84
+ failed = sum(1 for r in results if r.startswith("FAIL"))
85
+ print(f"{passed} PASS, {failed} FAIL")
86
+ return 0 if failed == 0 else 1
87
+
88
+
89
+ if __name__ == "__main__":
90
+ sys.exit(main())