File size: 3,597 Bytes
c60d963
 
 
 
 
 
 
 
 
 
202c0e4
c60d963
 
 
 
202c0e4
c60d963
202c0e4
c60d963
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d360571
c60d963
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d360571
c60d963
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""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())