Julia Klee
Julia-2: julia2_audio_v1 (text = base_v2 byte-identical, + pruned audio tower, stem p9), int8/int4 variants, lean runtime 0.1.0 (audio, LiveSession, modalities), card with speech, live calls and variants
1d1c6db Download runtime/tests/test_audio.py from SupersonicLabs/Julia-2: direct link, hf CLI and curl.
- Browser
- Download file 4.08 kB
-
https://huggingface.co/SupersonicLabs/Julia-2/resolve/main/runtime/tests/test_audio.py
- Command line
-
hf download hf://SupersonicLabs/Julia-2/runtime/tests/test_audio.py
-
curl -L -o test_audio.py https://huggingface.co/SupersonicLabs/Julia-2/resolve/main/runtime/tests/test_audio.py
4.08 kB
| """Audio gap smoke: the three test calls as ONE-SHOT audio states (System One input_audio parts) vs the same calls as text | |
| transcripts. Reports per-question agreement audio-vs-text and (with --ref) agreement with stored reference probabilities. | |
| Gate: the audio answers must agree with the text answers on >= 70% of the questions (the published audio-vs-text gap on | |
| long states is ~.82 agreement; here n is small) and the audio path must run from file paths, bytes and arrays.""" | |
| import argparse, json, time | |
| from pathlib import Path | |
| import numpy as np | |
| from tests.common import REPO, agreement, answer_probs | |
| DATA = Path(__file__).resolve().parent / "data" | |
| def load_calls(): | |
| return json.loads((DATA / "calls.json").read_text()) | |
| def state_parts(call, spk, upto=None): | |
| """[text context, (speaker label, audio part)...] for the call up to turn `upto`.""" | |
| parts = [{"type": "text", "text": "Context: " + json.dumps(call["context"], ensure_ascii=False) + ("\nCall transcript:" if call["lang"] == "en" else "\nTranscrição da ligação:")}] | |
| for i, t in enumerate(call["turns"][: None if upto is None else upto + 1]): | |
| parts.append({"type": "text", "text": f"\n{spk[call['lang']][t['speaker']]}: "}) | |
| parts.append({"type": "input_audio", "input_audio": str(DATA / call["id"] / f"{i:02d}.flac")}) | |
| return parts | |
| def text_state(call, spk, upto=None): | |
| hdr = "Call transcript:" if call["lang"] == "en" else "Transcrição da ligação:" | |
| turns = call["turns"][: None if upto is None else upto + 1] | |
| return "Context: " + json.dumps(call["context"], ensure_ascii=False) + "\n" + hdr + "\n" + "\n".join(f"{spk[call['lang']][t['speaker']]}: {t['text']}" for t in turns) | |
| def run(device=None, precision="bf16", ref=None, verbose=True): | |
| from julia2 import Runtime | |
| from julia2.audio import load_wav | |
| rt = Runtime(REPO, device=device, precision=precision) | |
| assert rt.audio is not None, "no audio stem in this checkpoint" | |
| d = load_calls(); res = {"device": str(rt.device), "precision": precision, "calls": {}} | |
| pa, pt, pref = [], [], [] | |
| for c in d["calls"]: | |
| qs = d["questions"][c["lang"]] | |
| t0 = time.time(); oa = rt.predict_questions(state_parts(c, d["speakers"]), qs); ta = time.time() - t0 | |
| ot = rt.predict_questions(text_state(c, d["speakers"]), qs) | |
| for k in qs: | |
| pa.append(answer_probs(oa["answers"][k])); pt.append(answer_probs(ot["answers"][k])) | |
| res["calls"][c["id"]] = {"label": c["label"], "lang": c["lang"], "audio_sec": round(ta, 2), "audio": {k: (a.get("choice") or round(a["noul"], 3)) for k, a in oa["answers"].items()}, "text": {k: (a.get("choice") or round(a["noul"], 3)) for k, a in ot["answers"].items()}} | |
| res["audio_vs_text"] = agreement(pa, pt) | |
| # input forms: path == bytes == (array, sr) | |
| c = d["calls"][0]; p = str(DATA / c["id"] / "00.flac"); q = {"q": d["questions"][c["lang"]]["scam"]} | |
| import soundfile as sf | |
| arr, sr = sf.read(p, dtype="float32") | |
| o1 = rt.predict_questions([{"type": "input_audio", "input_audio": p}], q); o2 = rt.predict_questions([{"type": "input_audio", "input_audio": open(p, "rb").read()}], q) | |
| o3 = rt.predict_questions("", q, audio=[(arr, sr)]) | |
| forms = agreement([answer_probs(o2["answers"]["q"]), answer_probs(o3["answers"]["q"])], [answer_probs(o1["answers"]["q"])] * 2) | |
| res["input_forms_maxdp"] = forms["maxdp_max"] | |
| assert forms["maxdp_max"] < 1e-4, forms | |
| if ref: | |
| stored = json.loads(open(ref).read()) if isinstance(ref, str) else ref | |
| res["vs_ref"] = agreement(pa, stored) | |
| if verbose: | |
| print(json.dumps(res, ensure_ascii=False)) | |
| assert res["audio_vs_text"]["argmax_agree"] >= 0.7, res["audio_vs_text"] | |
| return res, pa | |
| if __name__ == "__main__": | |
| ap = argparse.ArgumentParser(); ap.add_argument("--device"); ap.add_argument("--precision", default="bf16"); ap.add_argument("--ref"); ap.add_argument("--save_ref") | |
| a = ap.parse_args() | |
| res, pa = run(a.device, a.precision, a.ref) | |
| if a.save_ref: | |
| json.dump(pa, open(a.save_ref, "w")) | |