# ============================================================ # AST — Sonification Client # Standalone Colab notebook. # Python fetches activations server-side (no CORS). # JS Web Audio API renders sound. # ============================================================ # ── CELL 1: Installs ───────────────────────────────────────── # !pip install requests -q # ── CELL 2 + 3: Callback + UI — must be ONE cell ───────────── import requests import numpy as np import json from google.colab import output import IPython.display as ipd API_URL = "https://phoniness-nimbly-gnat.ngrok-free.dev/" # ← paste your URL def fetch_activations(prompt): r = requests.post( f"{API_URL}/activate", json={"prompt": prompt}, timeout=30, ) r.raise_for_status() data = r.json() acts = np.array(data["activations"]) BUCKETS = 32 sz = len(acts) // BUCKETS bkt = np.array([acts[i*sz:(i+1)*sz].mean() for i in range(BUCKETS)]) mx = np.abs(bkt).max() or 1e-8 bkt = np.clip(bkt / mx, -1.0, 1.0) return { "activations": bkt.tolist(), "entropy_raw": float(data.get("entropy_raw", 0)), "entropy_norm": float(data.get("entropy_norm", 0)), "output": str(data.get("output", "")), } def prompt_callback(prompt): try: return json.dumps(fetch_activations(prompt)) except Exception as e: return json.dumps({"error": str(e)}) output.register_callback("ast.sonify", prompt_callback) # ── HTML + Web Audio ────────────────────────────────────────── HTML = r"""