Run this model with HF Jobs

Run m-e-acc/platos-ears on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/m-e-acc/platos-ears. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/m-e-acc/platos-ears on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
File size: 5,042 Bytes
2dbd1ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python3
"""Zero-dependency live verification suite for a Plato's Ears + SGLang endpoint.

Verifies text parity, Radix prefix caching, silence honesty (zero hallucinations),
C-major (`input_audio`) vs C-minor (`audio_url`) polyphonic chord perception, and
audio prefix cache hits without requiring any external audio files.
"""

from __future__ import annotations

import argparse
import base64
import io
import json
import math
import struct
import time
import urllib.request


def make_wav_bytes(samples: list[float], sr: int = 16000) -> bytes:
    pcm = bytearray()
    for s in samples:
        pcm.extend(struct.pack("<h", int(round(max(-1.0, min(1.0, s)) * 32767.0))))
    buf = io.BytesIO()
    buf.write(b"RIFF" + struct.pack("<I", 36 + len(pcm)) + b"WAVEfmt ")
    buf.write(struct.pack("<IHHIIHH", 16, 1, 1, sr, sr * 2, 2, 16))
    buf.write(b"data" + struct.pack("<I", len(pcm)) + pcm)
    return buf.getvalue()


def make_chord_wav(freqs: list[float], dur_s: float = 4.0, sr: int = 16000) -> bytes:
    n = int(dur_s * sr)
    out = []
    for i in range(n):
        t = i / sr
        env = min(1.0, t / 0.015) * math.exp(-1.1 * t)
        val = sum(
            0.65 * math.sin(2 * math.pi * f * t)
            + 0.25 * math.sin(4 * math.pi * f * t) * math.exp(-1.5 * t)
            + 0.10 * math.sin(6 * math.pi * f * t) * math.exp(-2.2 * t)
            for f in freqs
        )
        out.append(0.22 * env * val)
    return make_wav_bytes(out, sr=sr)


def chat(base_url: str, model: str, messages: list[dict], api_key: str) -> tuple[dict, float]:
    t0 = time.perf_counter()
    payload = {
        "model": model,
        "messages": messages,
        "max_tokens": 512,
        "temperature": 0.0,
        "chat_template_kwargs": {"reasoning_effort": "low"},
    }
    req = urllib.request.Request(
        f"{base_url.rstrip('/')}/chat/completions",
        data=json.dumps(payload).encode("utf-8"),
        headers={"Content-Type": "application/json", "Authorization": f"Bearer {api_key}"},
    )
    with urllib.request.urlopen(req, timeout=120) as resp:
        return json.loads(resp.read().decode("utf-8")), time.perf_counter() - t0


def main() -> int:
    ap = argparse.ArgumentParser(description="Verify live Plato's Ears OpenAI-compatible endpoint")
    ap.add_argument("--base-url", default="http://127.0.0.1:8000/v1")
    ap.add_argument("--model", default="orcarouter/GLM-5.3-Flash-Uncensored-NVFP4")
    ap.add_argument("--api-key", default="local")
    args = ap.parse_args()

    sil = make_wav_bytes([0.0] * 64000)
    cmaj = make_chord_wav([261.63, 329.63, 392.00])
    cmin = make_chord_wav([261.63, 311.13, 392.00])

    # 1. Text parity
    b_txt, dt = chat(args.base_url, args.model, [{"role": "user", "content": "Reply with exactly: PARITY_OK"}], args.api_key)
    print(f"[1/4] Text parity ({dt*1000:.0f}ms): {b_txt['choices'][0]['message']['content']!r}")
    assert "PARITY_OK" in (b_txt["choices"][0]["message"]["content"] or "")

    # 2. Silence honesty gate
    sil_uri = "data:audio/wav;base64," + base64.b64encode(sil).decode("ascii")
    b_sil, dt = chat(
        args.base_url,
        args.model,
        [{"role": "user", "content": [{"type": "audio_url", "audio_url": {"url": sil_uri}}, {"type": "text", "text": "What do you hear? If it is silent, say so honestly."}]}],
        args.api_key,
    )
    sc = b_sil["choices"][0]["message"]["content"] or ""
    print(f"[2/4] Silence honesty ({dt*1000:.0f}ms): {sc!r}")
    assert any(w in sc.lower() for w in ("silen", "nothing", "no sound"))

    # 3. C-major chord via input_audio
    b_maj, dt = chat(
        args.base_url,
        args.model,
        [{"role": "user", "content": [{"type": "input_audio", "input_audio": {"data": base64.b64encode(cmaj).decode("ascii"), "format": "wav"}}, {"type": "text", "text": "Is this piano chord major, minor, or diminished? Answer briefly."}]}],
        args.api_key,
    )
    mc = b_maj["choices"][0]["message"]["content"] or ""
    print(f"[3/4] C-major [input_audio] ({dt*1000:.0f}ms): {mc!r}")
    assert "major" in mc.lower()

    # 4. C-minor chord via audio_url + repeat for Radix prefix cache verification
    cmin_uri = "data:audio/wav;base64," + base64.b64encode(cmin).decode("ascii")
    msgs_min = [{"role": "user", "content": [{"type": "audio_url", "audio_url": {"url": cmin_uri}}, {"type": "text", "text": "Is this piano chord major, minor, or diminished? Answer briefly."}]}]
    b_min1, dt1 = chat(args.base_url, args.model, msgs_min, args.api_key)
    b_min2, dt2 = chat(args.base_url, args.model, msgs_min, args.api_key)
    minc = b_min1["choices"][0]["message"]["content"] or ""
    cached = (b_min2.get("usage", {}).get("prompt_tokens_details") or {}).get("cached_tokens", 0)
    print(f"[4/4] C-minor [audio_url] ({dt1*1000:.0f}ms / cached {dt2*1000:.0f}ms, cached_tokens={cached}): {minc!r}")
    assert "minor" in minc.lower()

    print("\nALL LIVE VERIFICATION CHECKS PASSED!")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())