Spaces:
Sleeping
Sleeping
Deploy WitnessBox
Browse filesFiles changed (28)
- HACKATHON-CONTEXT.mdAdded+70
- PRD.mdAdded+105
- README.md+108-6
- SUBMISSION.mdAdded+91
- app.pyAdded+237
- assets/marcus_reid.pngAdded
- config.pyAdded+65
- modal_app.pyAdded+397
- requirements.txtAdded+8
- scripts/demo_playthrough.pyAdded+100
- scripts/deploy_space.pyAdded+102
- scripts/make_portrait_placeholder.pyAdded+135
- scripts/smoke_modal.pyAdded+41
- tests/test_contradictions.pyAdded+51
- tests/test_engine_smoke.pyAdded+51
- tests/test_stance.pyAdded+32
- tests/test_state.pyAdded+47
- witnessbox/__init__.pyAdded+5
- witnessbox/backends/__init__.pyAdded+40
- witnessbox/backends/base.pyAdded+66
- witnessbox/backends/mock.pyAdded+104
- witnessbox/backends/modal_client.pyAdded+106
- witnessbox/contradictions.pyAdded+87
- witnessbox/engine.pyAdded+199
- witnessbox/script.pyAdded+73
- witnessbox/stance.pyAdded+176
- witnessbox/state.pyAdded+164
- witnessbox/witness.pyAdded+242
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970# Build Small Hackathon — Full Context (Hugging Face × Gradio)
> Verified from the official field guide + live org scan. Shared reference for this project.> **No deadlines/timelines recorded here by design** — sequence work by dependency, not calendar.
## The premiseA return to **small, local, tinkerable** open-weight models — everything **under 32B parameters**,running on hardware you own. "Less API bill, more workshop."
## Two tracks (equal prize pools, pick one per app)- **🏡 Backyard AI (practical):** *"Practical, problem-solving apps built to improve daily life — for you or someone close to you. Useful things that run on hardware you own."* (storybook generator, study tutor, receipt/bill parser, on-device doc assistant)- **🍄 An Adventure in Thousand Token Wood (whimsical):** *"Whimsical, delightful, AI-native apps that push the boundaries of fun."* AI must be **load-bearing**, not a build helper. (interactive games, entertainment tools, desktop pet, text-adventure DM)
## Entry criteria- **REQ-01 — Under 32B:** every model your project depends on must be <32B **total** params (not just active). Combine several freely; each must individually stay under the cap.- **REQ-02 — Ship a Gradio app** in the official `build-small-hackathon` HF org (Docker fine if the interface is a Gradio Space).- **REQ-03 — Record a demo video** showing the app working (judges fall back to it if GPU/API limits block a live run — treat it as the primary judged artifact).- **REQ-04 — Post on social**, link it from the README.- **REQ-05 — GPU limit:** submit as many apps as you like; if relying on free ZeroGPU, max 10 ZeroGPU apps/user (Modal credits or consumer HW otherwise).- **REQ-06 — Tag your README** frontmatter for the tracks + badges you want considered, plus a short write-up of the idea & tech. (No single canonical tag spelling is enforced; the wild uses several variants — include both hyphen and space forms.)
## Prize table — $48k cash + 20k Modal credits + 2× RTX 5080 + ChatGPT Pro (29 ways to win)### General track prizes — awarded PER TRACK (Backyard **and** Wood each):| Place | Prize ||---|---|| 1st | $4,000 || 2nd | $2,500 || 3rd | $1,500 || 4th | $1,000 || Community Choice (by likes) | $2,000 |
### Sponsor prizes (own criteria):- **⚙️ Best Use of Modal** — **1st 10,000 / 2nd 7,000 / 3rd 3,000 CREDITS** ($20k total). *"Use Modal for the development or runtime of your app, and note it in your Space README. Judged on best use of the platform. Inference, fine-tuning, batch jobs and sandboxes all count."*- **🧠 Best MiniCPM Build (OpenBMB)** — **$2,500 / $1,500 / $1,000 PER TRACK** ($5k per track, $10k total). Build with MiniCPM models; Vision (MiniCPM-V) & omni (MiniCPM-o) variants qualify.- **💻 Best Use of Codex (OpenAI)** — $5,000 / $3,000 / $1,000 ($10k). Requires **Codex-attributed commits** in the connected repo/Space.- **🟩 Nemotron Hardware Prize (NVIDIA)** — **2× RTX 5080**: one "best space" (NVIDIA-judged on merit), one "community engagement" (likes). Build with Nemotron models.
### Bonus badges:- **Off Brand $1,500** — best custom UI beyond default Gradio (*"gr.Server is your friend"*).- **Tiny Titan $1,500** — best app on a genuinely tiny model; **ALL models ≤4B**.- **Best Demo $1,000** — best full package: app + demo video + social post.- **Best Agent $1,000** — best agentic app (multi-step tool use + planning, <32B).- **Bonus Quest Champion $2,000** — most bonus criteria met across the board.- **Judges' Wildcard $1,000** — amazing but fits no category (every submission auto-entered; no action).
### Rules that matter- **Awards stack** — one app can win a track placement + sponsor prizes + bonus badges simultaneously.- **Multiple submissions allowed**, each judged independently.- Sponsor models must form a **core part of the experience** (you may also use other providers' models under the cap).- Some prizes require running locally to be eligible; hosted sponsor APIs exist for dev.
## Sponsor models & platforms (verified)- **OpenBMB / MiniCPM** (free hosted API + local via llama.cpp/transformers): - `MiniCPM-V-4.6` (1.3B) — vision/OCR/document understanding. Class `AutoModelForImageTextToText` + `AutoProcessor`; `transformers[torch]>=5.7` (+ `av` for video, avoids torchcodec/CUDA issues). Starter Space to fork: `openbmb/MiniCPM-V-4.6-Demo` (gr.Server). - `MiniCPM-o-4_5` (9.4B) — full-duplex omni (voice/vision/language in, speech out). `AutoModel` + `trust_remote_code`; `model.chat(msgs=..., use_tts_template=, enable_thinking=, generate_audio=)` — content as a list, **no tokenizer arg**. - `MiniCPM5-1B` (1.08B, llama arch) — text gen, tool-calling, on-device. `AutoModelForCausalLM`. - `MiniCPM4.1-8B` — text reasoning. - `VoxCPM2` (2B) — TTS, 48kHz, **PyTorch ≥2.5.0**. Voice Design `(description)text` (no ref); Controllable Cloning `generate(text="(style)text", reference_wav_path=...)`; Ultimate Cloning adds `prompt_wav_path`+`prompt_text`. Style varies run-to-run (gen 1–3×).- **NVIDIA / Nemotron 3** family: Nano (30B MoE reasoning), Nano-4B (edge), Nano-Omni (multimodal), **ASR** (`nemotron-speech-streaming-en-0.6b` [kit-recommended] or `nemotron-3.5-asr-streaming-0.6b` [multilingual]), **Parse** (`NVIDIA-Nemotron-Parse-v1.2`, sub-1B doc extraction: tables/math/handwriting/figures/layout), Embed-VL.- **Modal** (serverless GPU): inference, **fine-tuning** (`hp_sweep_gpt`: 8 SLMs in parallel; `fine-tuning-embeddings`; Ramp case study — parallel fine-tune, 79% cost cut), **batch** (`spawn_map`, 1M jobs/1 line, scale-to-zero), **sandboxes** (run untrusted/LLM-generated code — flagship pattern: `examples/agent`, `safe_code_execution`; the GRPO example notes the *Best Use of Modal prize "showcased sandboxes for securely evaluating model-generated code"*). Memory snapshots, Volumes, scheduled jobs.- **Black Forest Labs** FLUX.2 Klein (4B/9B image); **JetBrains** Mellum 2 (12B MoE code); **Cohere** Transcribe (ASR) + Tiny Aya.
## Submission processJoin the org → upload the Gradio Space → record a demo video (host on YouTube/Space/public) → one social post → update README with links + frontmatter tags + a short write-up. Submit when ready.
## This portfolio's Modal strategy (context for both apps)Two apps, both engineered to be **1st-caliber for Best Use of Modal**, on **different flagship axes** so they don't cannibalize the single top slot:- **WitnessBox** — Axis A: **Sandbox runs model-generated code** (the pattern Modal's prize "showcased").- **Tiny Foundry** — Axis B: **massive elastic parallel scale** (dozens of GPU containers at once; Modal Batch's core identity).Goal: maximize P(winning 1st) + a real shot at a **1st + 2nd sweep**. Awards stack, so each also pursues OpenBMB / Tiny Titan / Well-Tuned / track placements as secondary.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105# ⚖️ WitnessBox — PRD
> **Cross-examine a hostile AI witness.** A courtroom interrogation game where the witness reacts> to *how you deliver*, the AI is the irreplaceable mechanic, and a **Modal Sandbox executing> model-written code** is the game's referee.>> **Track:** 🍄 Thousand Token Wood · **Primary prize:** Best Use of Modal (1st-caliber, Axis A:> Sandbox-runs-model-generated-code) · **Status:** built, compiles clean (see existing `hf-hackathon/witnessbox/`).
## 1. Vision & why it winsInterrogate **Marcus Reid, CFO of Halcyon Dynamics**. He's evasive and reads your **deliverystance** (vocal confidence) — sound confident and he clams up; sound hesitant and he gets cockyand overshares. Catch him in **3 contradictions** and his voice **cracks** as he breaks.
Three independent win mechanisms, three judge pools:1. **Best Use of Modal (#1 target):** the core mechanic IS Modal's documented flagship pattern — an LLM writes code, a Sandbox safely executes it. Modal's own GRPO example: the *"Best Use of Modal prize showcased the use of sandboxes for securely evaluating model-generated code."* No rival in the field centers on this; most use Modal as plain inference hosting.2. **OpenBMB Best MiniCPM Build (Wood):** MiniCPM-o is the *character*, VoxCPM2's style-tags are the *game state* — "model is the product," which beats "model is a component."3. **Wood track podium (4 paid slots):** delight + load-bearing AI + originality + polish; a voiced, interactive game with a win condition and an audiovisual climax stands out vs watch-only demos.
## 2. Target prizesPrimary: **Best Use of Modal (1st)**. Secondary (awards stack): OpenBMB-Wood · Wood podium ·Community Choice (Wood) · Nemotron Hardware (ASR) · Best Agent · Best Demo · Off-Brand *(only if areal `gr.Server` custom UI is built — not earned by CSS alone)*.
## 3. Users & core experiencePlayer = anyone who wants the fantasy of breaking a witness on the stand. Turn-based push-to-talk:```player records a question (mic) → Nemotron ASR transcribes + librosa reads DELIVERY STANCE (perceived confidence; NOT lie detection) → stance steers the witness system prompt (Hesitant → he overshares a thread toward an uncaught lie) → ONE MiniCPM-o call returns {in-character reply, contradiction-check Python} → modal.Sandbox executes the MODEL-WRITTEN code; its JSON verdict DECIDES the catch (keyword matching is only a silent fallback; on Sandbox error, the model self-corrects its code) → VoxCPM2 voices the reply; style escalates with pressurecatch #3 → win; the witness's voice cracks (pre-generated best take)```
## 4. Functional requirements- **3 planted lies** injected into the system prompt (timeline, authorization, relationship), each with a concrete contradiction cue the player must surface. Detection fires against THESE, not on emergent model inconsistency (reliable > magical).- **Delivery stance** from a parallel librosa pass (pause-rate + speaking-rate dominant per the prosody literature; pitch minor). Framed as *perceived delivery*, **never** "lie detector."- **Stance is load-bearing:** Hesitant delivery makes the witness leak a cue toward one uncaught lie.- **Win at 3 catches**, ≤ ~12 turns; the climactic break line is pre-generated and cached.- The model-written code + Sandbox verdict are shown **live** in an open panel (the Modal evidence).
## 5. Technical architecture (all ≤32B; ≈12B combined)| Component | Model / lib | Notes (verified) ||---|---|---|| Witness brain | `openbmb/MiniCPM-o-4_5` (9.4B) | `AutoModel`, `trust_remote_code`; `chat(msgs=, use_tts_template=False, enable_thinking=False, generate_audio=False)`; `init_vision/audio/tts=False` (text-only). || Witness voice | `openbmb/VoxCPM2` (2B) | `from_pretrained(load_denoiser=False)`; Voice-Design CFO once → Controllable-Clone per line `generate(text="(style)...", reference_wav_path=ref)`; 48kHz; **torch≥2.5.0**. || Player ASR | `nvidia/nemotron-speech-streaming-en-0.6b` (or `-3.5-asr-streaming-`) | whisper-small local fallback. || Delivery stance | `librosa` | parallel waveform pass; pause/rate → tier. || Contradiction engine | MiniCPM-o **generates** networkx code → `modal.Sandbox` | the verdict authority. |
## 6. Best Use of Modal — five load-bearing primitives (the #1-prize section)The core mechanic is Modal's flagship Sandbox pattern (`docs/examples/agent`, `safe_code_execution`).1. **⭐ Sandbox executes model-written code** — the game's referee (network-blocked; its JSON decides catches).2. **🔧 Agentic self-correction** — on Sandbox error, the error feeds back to MiniCPM-o, which repairs its own code and reruns (max 2) — Modal's `devlooper` generate→execute→fix loop.3. **GPU inference via `@app.cls`, scale-to-zero** — MiniCPM-o (A100) + VoxCPM2 (A10G) + Nemotron ASR (A10G), idle → $0.4. **Parallel `.map()`** — pre-generates the scripted voice beats (incl. the voice-crack) at load.5. **Memory snapshot + Volume** — snapshot cuts cold start (measured); a Volume persists the designed CFO voice clip + model cache.**Measured cost:** quote real container-seconds → "$0.0X / match" (read from the Modal dashboard).Map this verbatim into the README's "Best Use of Modal" section (REQ-06 requires noting Modal).
## 7. UX / UI requirementsCourtroom aesthetic (parchment, serif). CFO portrait. "Delivery Stance" bar (labeled *not a liedetector*). X/3 contradiction counter. Autoplay witness audio. **Contradiction Engine accordiondefaults OPEN** (the #1-prize evidence must be on camera). Latency (~20–35s warm) masked diegetically("the witness considers…"). For Off-Brand, a real `gr.Server` custom courtroom UI would be required.
## 8. Demo video (the judged artifact)60–90s, controlled, ~20 dry runs first: stance steers witness → ask hesitantly, he overshares →catch #1 → the Sandbox panel shows model-written code + verdict → catch #3 → **voice cracks** →cost readout. Show the Sandbox executing the model's code as the dramatic beat.
## 9. Success metricsFive consecutive clean end-to-end turns from the deployed Space · win-at-3 reliable · Sandboxverdict authoritative (codegen broken <~30% of turns, self-correction covers the rest) · voice-cracklands · measured Modal cost + snapshot seconds captured.
## 10. Risks & mitigations- **End-to-end turn never run** (highest risk) → deploy + prove 5 turns before anything downstream.- **Modal secrets unset** → Space boots (lookup is lazy/try-excepted) but the Sandbox is dead; set `MODAL_TOKEN_ID`/`MODAL_TOKEN_SECRET` as Space secrets.- **Codegen unreliable** → self-correction loop + a networkx skeleton in the prompt; never show repeated `score=0.00`.- **Voice-crack variance** → pre-generate ≥30 takes of the win line, cache the best.- **Nemotron ASR install friction** → bounded attempt, else pivot to parakeet or whisper fallback (never blocks the critical path).
## 11. Build plan (by dependency — no calendar)1. Set Space secrets · generate CFO portrait · (done in scaffold: lazy lookup, warmup sandbox prebuild, accordion open, torch≥2.5, generate_audio/init_audio).2. Deploy + smoke-test `run_in_sandbox()` and the voxcpm image standalone.3. **Five consecutive end-to-end turns** from the deployed Space + measured latencies/cost (the gate).4. ≥30 win-line takes cached · codegen reliability hardened.5. Nemotron ASR pivot-gate (stop-loss) · optional real `gr.Server` UI for Off-Brand.6. Demo video (after dry runs) → README measured numbers → social → submit.
## 12. Integrity rulesClaims follow code — no "only entry that…" claims about a moving field; cost/latency are measured,never fabricated. Pre-submit grep: `TODO | YOUR_HF_USER | NotImplementedError | <!--`.1234534567878910111213141516171819202122232425262728132930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115---title: WitnessBoxemoji: 🔥colorFrom: bluecolorTo: purpleemoji: ⚖️colorFrom: yellowcolorTo: redsdk: gradiosdk_version: 6.18.0python_version: '3.13'sdk_version: 4.44.0app_file: app.pypinned: falselicense: mittags: - build-small-hackathon # track (both spellings, per the field guide's note on tag variants) - thousand-token-wood - thousand token wood - adventure-in-thousand-token-wood # sponsor / bonus targets - best-use-of-modal - best use of modal - modal - openbmb - minicpm - voxcpm - nemotron - best-agent - best-demo---
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference# ⚖️ WitnessBox — cross-examine a hostile AI witness with your *voice*
> Interrogate **Marcus Reid, CFO of Halcyon Dynamics**. He reads *how you deliver*> — sound confident and he clams up; sound hesitant and he gets cocky and> overshares. Surface **three contradictions** and his voice **cracks** as he breaks.>> **Track:** 🍄 An Adventure in Thousand Token Wood · **Primary target:** Best Use of Modal
---
## Why it's differentEvery other "interrogate a witness" build in this jam is text-and-logic. WitnessBoxis the only one where **your vocal delivery is the input**: a `librosa` pass readsyour *perceived* confidence (pauses + pace) and steers the witness in real time,and the witness answers back in a **voice that escalates** from composed tocracking. The moat is the audio loop, not the puzzle.
> **The delivery meter is *perceived delivery*, never a lie detector.** It reads> how you sound (pauses, pace, pitch steadiness) — not whether anything is true.
## How a turn works```you speak ─┬─► Whisper ASR ───────────────► your question └─► librosa stance ─► CONFIDENT / NEUTRAL / HESITANT (steers the witness)your question ─► deterministic Contradiction Engine ─► catch? (reproducible verdict)persona + stance + tier + leak ─► MiniCPM4.1-8B ─► witness's linestate ─► VoxCPM2 (voice style = game state) ─► audio (cached voice-crack on the win)```Hesitant delivery makes Reid leak a thread toward an uncaught lie. Confidentdelivery shuts him down. Catch all three (timeline · authorization · relationship)and he breaks; whiff too many and the bench excuses him — you lose.
## Models — all <32B, ~11B combined| Role | Model | Size ||---|---|---|| Witness brain | `openbmb/MiniCPM4.1-8B` | 8.2B || Witness voice | `openbmb/VoxCPM2` (style tag = game state) | 2.3B || Player ASR | `openai/whisper-small` (deployed) — `nvidia/nemotron-…-0.6b` is a one-image-swap upgrade (NeMo-only) | 0.24B || Delivery stance | `librosa` (no model) | — |
## ⚙️ Best Use of ModalModal is the **runtime** for all three GPU models and the beat pre-generator —used as a *platform*, not just a host (the prize counts "inference… all"):
1. **GPU inference behind `@app.cls`, scale-to-zero.** Three models on three right-sized GPUs (A100 + 2×A10G); idle → `$0` via `scaledown_window`.2. **Opt-in keep-warm.** `min_containers` defaults to `0` — genuinely `$0` between examinations — and flips to `1` (`WITNESSBOX_KEEP_WARM=1`) for a live demo so turns don't eat a cold start. Scale-to-zero is the default; warmth is a deliberate, costed choice, not an always-on bill.3. **Parallel `.map()`** pre-generates every scripted beat at deploy time, fanning the **32 voice-crack takes across containers at once** and keeping the best.4. **Volume** persists the designed CFO reference voice + model cache + chosen beats.5. **Memory snapshots** cut CPU-side init on cold start.
**Measured (warm, this deploy).** A live dynamic turn is `MiniCPM4.1-8B` **→ 5.3s**for the witness's reply, then `VoxCPM2` **→ 8.6s** for ~4.5s of 48 kHz speech(RTF ≈ 1.9) — the line lands as **text first**, the voice follows. The five**scripted beats** (intro · opening · the voice-crack · win · lose) are pre-renderedby the parallel `.map()` pass and served straight from the Volume, so every*dramatic* moment plays **instantly** off the per-turn path. Idle containers →`$0` via `scaledown_window`. (Container-seconds / $-per-match read live from theModal dashboard, not fabricated.)
## Run it**Offline (no GPU, no Modal — boots anywhere):**```bashpip install -r requirements.txtpython app.py # WITNESSBOX_BACKEND defaults to "mock"; type your questions```The full game loop — stance, the catch engine, state, win/lose, audio autoplay —runs locally against a rule-based mock witness, so the end-to-end flow is provablewithout a single GPU.
**Live (real models):**```bashmodal deploy modal_app.py # serves MiniCPM4.1-8B, VoxCPM2, Whisper ASRmodal run modal_app.py # pre-generate the scripted beats (.map)WITNESSBOX_BACKEND=modal python app.py```On a Space, set `MODAL_TOKEN_ID` / `MODAL_TOKEN_SECRET` as secrets. Lookups arelazy and fall back to mock if Modal is unreachable, so the Space always boots.
## IntegrityDetection fires against three **planted** lies with concrete cues — reliable, not"magical." The model never grades itself. Cost/latency numbers are measured. No"only entry that…" claims about a moving field.12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091# WitnessBox — submission pack
Everything needed to submit to **Build Small** (HF × Gradio, models < 32B).Track: 🍄 *An Adventure in Thousand Token Wood* · Primary target: **Best Use of Modal**.
---
## Status checklist| # | Requirement | State ||---|---|---|| REQ-01 | Public app, models < 32B | ✅ MiniCPM4.1-8B (8.2B) + VoxCPM2 (2.3B) + Whisper-small (0.24B) ≈ 11B || REQ-02 | Gradio Space, public | ⏳ one command away — needs an HF write token (see below) || REQ-03 | Demo video (60–90s) | ⬜ you record — shotlist below; `scripts/demo_playthrough.py` is the dry-run || REQ-04 | Social post tagging sponsors | ⬜ you post — draft below || Modal | Genuine *platform* use | ✅ 3 GPU classes, scale-to-zero, keep-warm, parallel `.map()` pre-gen, Volume, snapshots — **proven live** |
**The one action only you can take:** paste a **write**-scoped HF token, then I run`python3 scripts/deploy_space.py` and the Space is live (code pushed, Modal secretsset, `WITNESSBOX_BACKEND=modal`). Get a token at https://huggingface.co/settings/tokens— either `! hf auth login` in the prompt, or paste it and I'll use `HF_TOKEN=…`.
---
## Social post (REQ-04) — draft
**X / short form**> ⚖️ I built **WitnessBox**: cross-examine a hostile AI witness — and your *voice*> is the weapon. Sound confident and the CFO clams up; sound hesitant and he gets> cocky and *leaks*. Catch 3 contradictions and his voice literally **cracks**.>> All open models < 32B, served on @modal_labs:> 🧠 MiniCPM4.1-8B · 🗣️ VoxCPM2 · 👂 Whisper — @OpenBMB on @huggingface, built with @Gradio.>> #BuildSmall [Space link] [video link]
**LinkedIn / long form**> Most "interrogate the witness" games are text-and-logic. WitnessBox makes your> **delivery** the input. A librosa pass reads your *perceived* confidence — pauses> and pace, never a lie detector — and steers the witness in real time. He answers> in a voice that escalates from composed to cracking.>> Three open models, all under 32B, ~11B combined: MiniCPM4.1-8B is the witness's> mind, VoxCPM2 is his voice (the style tag *is* the game state), Whisper hears you.> All of it runs on Modal: three right-sized GPUs behind scale-to-zero classes,> kept warm during an examination, with the dramatic "voice-crack" beats fanned> across containers via parallel `.map()` and the best take cached on a Volume.>> Built for the Build Small hackathon (@Hugging Face × @Gradio). Models by @OpenBMB.> Try it: [Space link] · 90-second demo: [video link]>> #BuildSmall #Modal #Gradio #OpenSource #AI
---
## Demo video shotlist (REQ-03) — ~80s
Record against the **live Space** (mic works in `modal` mode). `demo_playthrough.py`is your scripted rehearsal — the three killer lines are in `SCRIPT` there.
| t | Shot | Notes ||---|---|---|| 0:00–0:08 | Title card + hook | "Cross-examine a hostile witness — with your voice." || 0:08–0:18 | Click **Call the witness** | Reid's composed opening line **plays** (instant, cached beat) || 0:18–0:34 | The mechanic, both ways | Ask **confidently** → he clams up (bar: CONFIDENT). Ask **hesitantly** → he overshares (bar: HESITANT). This is the moat — linger here. || 0:34–0:56 | Land the 3 contradictions | timeline → authorization → relationship. Show the **Contradiction Engine** verdict box firing each time. || 0:56–1:08 | **The break** | 3rd catch → Reid's voice **cracks** (best of 32 cached takes). Win banner. || 1:08–1:20 | Architecture card | "3 open models < 32B · Modal scale-to-zero · parallel `.map()` pre-gen · warm 5.3s reply / 8.6s voice." End on the Space URL. |
**Tips:** **warm the models first** — redeploy with `WITNESSBOX_KEEP_WARM=1 modaldeploy modal_app.py` ~5 min before recording (or take one throwaway turn; they staywarm 5 min) so no shot waits on a cold start. Quiet room for the mic; do one confident+ one hesitant ask back-to-back so the contrast is unmistakable; let the voice-crackplay fully — it's the payoff. Flip keep-warm back off afterward to stop idle spend.
---
## Best-Use-of-Modal talking points (for the writeup / description)- **Not just hosting — the runtime.** Three models on three right-sized GPUs (A100 + 2×A10G), each a scale-to-zero `@app.cls`; idle → `$0`.- **Honest latency, costed warmth:** scale-to-zero by default (`$0` idle). Opt into keep-warm (`WITNESSBOX_KEEP_WARM=1`) for a live session and a turn is ~5.3s (reply) + ~8.6s (voice), measured this deploy — text lands first.- **Parallel `.map()` — verified:** 36 takes fanned across containers; workers write WAVs to the Volume and return only metadata; the best-cracking break take (pitch instability 70.3 vs a 61–69 field) is kept. Dramatic beats then play instantly.- **Parallel `.map()`** fans the 32 voice-crack takes across containers and keeps the one that cracks most (librosa pitch-instability score), all at deploy time.- **Volume** persists the designed CFO reference voice, the model cache, and the chosen beats across cold starts.- **Memory snapshots** trim CPU-side init.- Cost/latency are **measured**, not fabricated.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237"""WitnessBox — Gradio Space entrypoint.
Cross-examine Marcus Reid with your voice. Your *delivery* (perceived vocalconfidence) steers him; surface three contradictions and his voice cracks.
Boots anywhere: with WITNESSBOX_BACKEND unset it runs the offline mock end toend (type your questions). Set WITNESSBOX_BACKEND=modal + Modal Space secretsfor live Whisper ASR / MiniCPM4.1-8B / VoxCPM2 and push-to-talk."""from __future__ import annotations
import os
import numpy as npimport gradio as gr
import configfrom witnessbox.backends import get_backendsfrom witnessbox.engine import WitnessBoxEnginefrom witnessbox.witness import WITNESS_NAME, WITNESS_ROLE
CSS = """.gradio-container {background: #efe7d3; font-family: 'Iowan Old Style','Palatino Linotype',Georgia,serif;}#wb-title {text-align:center; color:#3a2c18; letter-spacing:.5px;}#wb-title h1 {font-variant: small-caps; margin-bottom:0;}.wb-card {background:#f7f1e1; border:1px solid #c9b78d; border-radius:10px; padding:14px 16px; box-shadow:0 1px 0 #fff inset;}.wb-bar-track {background:#e2d7ba; border-radius:8px; height:18px; overflow:hidden; border:1px solid #c9b78d;}.wb-bar-fill {height:100%; transition:width .4s ease;}.wb-disclaimer {font-size:11px; color:#7a6a45; font-style:italic;}.wb-tier {font-variant: small-caps; font-weight:700; color:#5a4220;}#wb-evidence textarea {font-family: ui-monospace,Menlo,Consolas,monospace; background:#1d1b14; color:#d8f0c0;}.wb-banner {text-align:center; font-size:20px; font-variant:small-caps; padding:8px; border-radius:8px;}"""
# --------------------------------------------------------------------------- ## render helpers# --------------------------------------------------------------------------- #def _bar(label: str, pct: float, color: str, sub: str = "") -> str: pct = max(0, min(100, int(round(pct)))) return ( f"<div class='wb-card' style='margin-bottom:8px'>" f"<div style='display:flex;justify-content:space-between'>" f"<b>{label}</b><span>{pct}</span></div>" f"<div class='wb-bar-track'><div class='wb-bar-fill' style='width:{pct}%;background:{color}'></div></div>" f"{f'<div class=wb-disclaimer>{sub}</div>' if sub else ''}</div>" )
def _stance_html(stance) -> str: color = {"CONFIDENT": "#2f7d3b", "NEUTRAL": "#b08900", "HESITANT": "#9c3b2f"}.get(stance.tier, "#b08900") sub = "Perceived delivery — NOT a lie detector. Reads pauses & pace, not truth." head = f"<div class='wb-tier'>Delivery · {stance.tier}</div>" return head + _bar("Perceived confidence", stance.confidence, color, sub)
def _counters_html(status: dict) -> str: catches = f"<div class='wb-card' style='margin-bottom:8px'><b>Contradictions</b> " \ f"<span style='float:right'>{status['catches']} / {status['catches_to_win']}</span></div>" cred = _bar("Your standing with the bench", status["credibility"], "#43607f") comp = _bar(f"Witness composure · {status['witness_tier']}", status["composure"], "#7a4a2f") return catches + cred + comp
def _parse_mic(mic): if mic is None: return None, None sr, data = mic y = np.asarray(data) if y.dtype.kind in "iu": y = y.astype(np.float32) / max(1, np.iinfo(y.dtype).max) else: y = y.astype(np.float32) if y.ndim > 1: y = y.mean(axis=1) return y, int(sr)
def _concat(a, b, sr): if a is None: return b if b is None: return a gap = np.zeros(int(0.5 * sr), dtype=np.float32) return np.concatenate([a.astype(np.float32), gap, b.astype(np.float32)])
def _banner(kind: str, text: str) -> str: colors = {"win": "#2f7d3b;color:#fff", "lose": "#7a2f2f;color:#fff", "info": "#e9dfc3;color:#5a4220"} bg = colors.get(kind, colors["info"]) return f"<div class='wb-banner' style='background:{bg}'>{text}</div>"
# --------------------------------------------------------------------------- ## callbacks# --------------------------------------------------------------------------- #def on_start(engine): engine = WitnessBoxEngine(get_backends()) intro = engine.start() chat = [ {"role": "assistant", "content": f"⚖️ *The Court:* {intro['narration']}"}, {"role": "assistant", "content": f"**{WITNESS_NAME}:** {intro['opening_text']}"}, ] opening_audio = intro["opening_audio"] # (sr, np) or None footer = f"Backend: **{intro['backend']}** — {intro['backend_note']}" from witnessbox.stance import _neutral return ( engine, chat, gr.update(value=opening_audio), _stance_html(_neutral("awaiting your first question")), _counters_html(intro["status"]), gr.update(value="", visible=False), _banner("info", "Examination open. Mind how you say it — he listens for doubt."), footer, gr.update(interactive=True), # ask button gr.update(visible=False), # begin button gr.update(interactive=True), # mic gr.update(interactive=True), # typed )
def on_ask(engine, mic, typed): if engine is None: return (engine, gr.skip(), gr.skip(), gr.skip(), gr.skip(), gr.skip(), _banner("info", "Press “Call the witness” to begin."), gr.skip())
y, sr = _parse_mic(mic) result = engine.take_turn(audio=y, sr=sr, typed_text=typed)
# Rebuild the chat from the transcript (engine keeps it consistent with what # is actually spoken, including the break line on the winning turn). chat = [] for rec in engine.state.transcript: tag = f"_[{rec.stance_tier.lower()}]_ " if rec.stance_tier != "NEUTRAL" else "" chat.append({"role": "user", "content": f"{tag}{rec.examiner_text}"}) chat.append({"role": "assistant", "content": f"**{WITNESS_NAME}:** {rec.witness_text}"})
# witness audio (+ epilogue concatenated on win/lose for a single dramatic play) audio_val = None if result.witness_audio is not None: merged = _concat(result.witness_audio, result.epilogue_audio, result.audio_sr) audio_val = (result.audio_sr, merged)
# banner if result.events.won: banner = _banner("win", "🩻 He breaks. Three contradictions on the record — you win.") elif result.events.lost: banner = _banner("lose", "The bench excuses the witness. You’ve lost the room.") elif result.events.near_miss: banner = _banner("info", "He flinched. You’re circling something — name the specific fact.") else: banner = _banner("info", f"Stance read: {result.stance.tier.title()}.")
evidence_update = ( gr.update(value=result.evidence, visible=True) if result.evidence else gr.update() ) return ( engine, chat, gr.update(value=audio_val), _stance_html(result.stance), _counters_html(result.status), evidence_update, banner, gr.update(value=""), # clear typed box )
# --------------------------------------------------------------------------- ## layout# --------------------------------------------------------------------------- #def build() -> gr.Blocks: with gr.Blocks(css=CSS, title="WitnessBox", theme=gr.themes.Soft()) as demo: engine_state = gr.State(None) gr.HTML( f"<div id='wb-title'><h1>⚖️ WitnessBox</h1>" f"<div>Cross-examine {WITNESS_NAME} — {WITNESS_ROLE}. " f"Your <b>voice</b> is the weapon.</div></div>" ) banner = gr.HTML(_banner("info", "Call the witness to the stand."))
with gr.Row(): with gr.Column(scale=2): _portrait = "assets/marcus_reid.png" gr.Image( value=_portrait if os.path.exists(_portrait) else None, show_label=False, height=260, show_download_button=False, container=True, ) stance_html = gr.HTML(label="Delivery") with gr.Column(scale=4): chat = gr.Chatbot(type="messages", height=360, label="The Stand") witness_audio = gr.Audio(label="Witness", autoplay=True, interactive=False) with gr.Column(scale=2): counters_html = gr.HTML()
with gr.Accordion("🔎 Contradiction Engine (live verdict)", open=True): evidence = gr.Textbox( elem_id="wb-evidence", show_label=False, visible=False, lines=5, interactive=False, ) gr.Markdown( "_Catches are decided by a deterministic engine over three planted " "contradictions — the language model never grades itself, so the " "verdict is reproducible._" )
with gr.Row(): mic = gr.Audio(sources=["microphone"], type="numpy", label="Question (push to talk)", interactive=False) typed = gr.Textbox(label="…or type your question (primary in offline mock mode)", interactive=False, scale=2, placeholder="e.g. The wire cleared March 6th — before the board approved it on the 14th.") with gr.Row(): begin_btn = gr.Button("Call the witness to the stand", variant="primary") ask_btn = gr.Button("Put it to him", variant="secondary", interactive=False)
footer = gr.Markdown("")
outs_start = [engine_state, chat, witness_audio, stance_html, counters_html, evidence, banner, footer, ask_btn, begin_btn, mic, typed] begin_btn.click(on_start, [engine_state], outs_start)
outs_ask = [engine_state, chat, witness_audio, stance_html, counters_html, evidence, banner, typed] ask_btn.click(on_ask, [engine_state, mic, typed], outs_ask) typed.submit(on_ask, [engine_state, mic, typed], outs_ask)
return demo
demo = build()
if __name__ == "__main__": demo.launch()1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465"""Central configuration for WitnessBox.
One place for model ids, backend selection, audio rates, and game tuning so therest of the codebase never hardcodes a magic number. Everything here is plaindata; importing this module has no side effects and pulls in no heavy deps."""from __future__ import annotations
import os
# --------------------------------------------------------------------------- ## Backend selection# --------------------------------------------------------------------------- ## "mock" -> pure-Python backends, no GPU/Modal needed; the whole loop runs# locally (this is the default so the app boots anywhere).# "modal" -> real models served from a deployed Modal app (see modal_app.py).BACKEND = os.environ.get("WITNESSBOX_BACKEND", "mock").strip().lower()
# Name the Modal app is deployed under (`modal deploy modal_app.py`).MODAL_APP_NAME = os.environ.get("WITNESSBOX_MODAL_APP", "witnessbox")
# If a Modal lookup fails (secrets unset, app not deployed), fall back to mock# rather than crashing the Space. Mirrors PRD risk #10 ("Space boots even if# Modal secrets unset"). Set to "0" to hard-fail instead (useful in CI).FALLBACK_TO_MOCK = os.environ.get("WITNESSBOX_FALLBACK_TO_MOCK", "1") != "0"
# --------------------------------------------------------------------------- ## Models (all < 32B; combined ~12B) — ids verified in PRD.md / HACKATHON-CONTEXT.md# --------------------------------------------------------------------------- #WITNESS_LLM = "openbmb/MiniCPM4.1-8B" # 8.2B — witness's brain (clean text model; we run text-only, so the omni model's deps weren't worth it)WITNESS_VOICE = "openbmb/VoxCPM2" # 2B — the witness's voice; style = game statePLAYER_ASR = "nvidia/nemotron-speech-streaming-en-0.6b" # 0.6B — player transcriptionPLAYER_ASR_FALLBACK = "openai/whisper-small" # local fallback if Nemotron install fights us
# --------------------------------------------------------------------------- ## Audio# --------------------------------------------------------------------------- #ASR_SR = 16_000 # ASR models expect 16 kHz monoVOICE_SR = 48_000 # VoxCPM2 emits 48 kHz
# --------------------------------------------------------------------------- ## Game tuning# --------------------------------------------------------------------------- #CATCHES_TO_WIN = 3 # surface this many contradictions -> the witness breaksSOFT_TURN_BUDGET = 12 # narrative pacing target; not a hard cap
# Player credibility = the lose resource. The judge excuses the witness at 0.CREDIBILITY_START = 100CREDIBILITY_ON_CATCH = +12 # landing a contradiction restores standing with the benchCREDIBILITY_ON_WHIFF = -14 # a question that goes nowhere costs you
# Witness composure = the continuous backing for the discrete witness tiers and# drives voice-style escalation. Starts high; each catch knocks it down a band.COMPOSURE_START = 100COMPOSURE_ON_CATCH = -30COMPOSURE_ON_PRESSURE = -4 # confident delivery with no catch still rattles him a little
# Contradiction detector: minimum match score (0..1) to count as a catch.CATCH_THRESHOLD = 0.62
# Hard ceiling so a runaway session still terminates.MAX_TURNS = 24123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397"""WitnessBox on Modal — the runtime that serves the game's three models andpre-generates its scripted beats.
Deploy: modal deploy modal_app.pyThen run the Space with WITNESSBOX_BACKEND=modal and the Modal token set asSpace secrets (MODAL_TOKEN_ID / MODAL_TOKEN_SECRET).
How this is a genuine *best use of the platform* (not just hosting), mapped tothe README's "Best Use of Modal" section:
1. GPU inference behind `@app.cls`, **scale-to-zero** — three models, three right-sized GPUs, $0 when idle (`scaledown_window`).2. **`keep_warm` / min_containers** on the witness brain + voice so a live examination doesn't pay a cold start every turn (the honest latency story).3. **Parallel `.map()`** pre-generates every fixed beat at deploy time, fanning the 32 voice-crack takes across containers at once and keeping the best.4. **Volume** persists the designed CFO reference voice + model cache + chosen beats across cold starts.5. **Memory snapshots** cut CPU-side init on cold start.
NOTE: model-call signatures follow PRD.md / HACKATHON-CONTEXT.md (verified). Theexact VoxCPM2 / Nemotron import paths may need a one-line pin against the shippedpackage versions at deploy time; each is isolated in a `_load` / `_synth` helper."""from __future__ import annotations
import os
import modal
import configfrom witnessbox import script
app = modal.App(config.MODAL_APP_NAME)cache = modal.Volume.from_name("witnessbox-cache", create_if_missing=True)CACHE_DIR = "/cache"REF_VOICE_PATH = f"{CACHE_DIR}/cfo_reference.wav"BEATS_DIR = f"{CACHE_DIR}/beats"
# Keep-warm is OPT-IN. Default 0 => true scale-to-zero, $0 when idle (the honest# Best-Use-of-Modal story, and it won't burn credits between demos). Flip it on# only for a live demo recording / judging window:# WITNESSBOX_KEEP_WARM=1 modal deploy modal_app.py# Warm turns are then ~5.3s (reply) + ~8.6s (voice); a cold first turn pays the# model-load once (memory snapshots + the Volume model cache keep that bounded)._KEEP_WARM = int(os.environ.get("WITNESSBOX_KEEP_WARM", "0"))
# Per-model images keep conflicting deps (notably torch pins) apart._HF = {"HF_HOME": CACHE_DIR, "HF_HUB_ENABLE_HF_TRANSFER": "1"}
llm_image = ( modal.Image.debian_slim(python_version="3.11") # MiniCPM4.1-8B is a standard text model — clean transformers deps, no omni # dependency cascade (PIL/librosa/soundfile/minicpmo/vocos/...). # transformers <5: MiniCPM4.1-8B's remote code imports is_torch_fx_available, # which transformers 5.x removed. .pip_install("torch>=2.5.0", "transformers>=4.46,<5", "accelerate", "sentencepiece", "hf_transfer", "numpy") .env(_HF) .add_local_python_source("config", "witnessbox"))voice_image = ( modal.Image.debian_slim(python_version="3.11") .apt_install("ffmpeg") .pip_install("torch>=2.5.0", "soundfile", "librosa", "numpy", "hf_transfer", "voxcpm") # the VoxCPM2 runtime package .env(_HF) .add_local_python_source("config", "witnessbox"))asr_image = ( modal.Image.debian_slim(python_version="3.11") .apt_install("ffmpeg") .pip_install("torch>=2.5.0", "transformers>=4.49", "soundfile", "librosa", "numpy", "hf_transfer") .env(_HF) .add_local_python_source("config", "witnessbox"))
# --------------------------------------------------------------------------- ## Witness brain — MiniCPM4.1-8B (standard text model; clean transformers deps)# --------------------------------------------------------------------------- #@app.cls( image=llm_image, gpu="A100", volumes={CACHE_DIR: cache}, scaledown_window=300, # scale-to-zero after 5 min idle min_containers=_KEEP_WARM, # 0 = $0 idle; set WITNESSBOX_KEEP_WARM=1 for live demos enable_memory_snapshot=True,)class WitnessLLM: @modal.enter() def load(self): import torch from transformers import AutoModelForCausalLM, AutoTokenizer
# Standard causal-LM load. sdpa avoids a flash-attn dependency. # Verified: https://huggingface.co/openbmb/MiniCPM4.1-8B self.tokenizer = AutoTokenizer.from_pretrained( config.WITNESS_LLM, trust_remote_code=True ) self.model = AutoModelForCausalLM.from_pretrained( config.WITNESS_LLM, trust_remote_code=True, attn_implementation="sdpa", torch_dtype=torch.bfloat16, # transformers 4.x uses torch_dtype, not dtype device_map="cuda", ).eval()
@modal.method() def respond(self, system_prompt: str, messages: list[dict]) -> str: import re import torch
msgs = [{"role": "system", "content": system_prompt}] for m in messages: msgs.append({"role": m["role"], "content": m["content"]}) # enable_thinking=False -> direct in-character reply, no <think> trace. try: prompt = self.tokenizer.apply_chat_template( msgs, tokenize=False, add_generation_prompt=True, enable_thinking=False ) except TypeError: prompt = self.tokenizer.apply_chat_template( msgs, tokenize=False, add_generation_prompt=True ) inputs = self.tokenizer([prompt], return_tensors="pt").to("cuda") with torch.no_grad(): out = self.model.generate( **inputs, max_new_tokens=160, do_sample=True, temperature=0.7, top_p=0.95 ) text = self.tokenizer.decode( out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True ) text = re.sub(r"<think>.*?</think>", "", text, flags=re.DOTALL) # safety net return text.strip()
# --------------------------------------------------------------------------- ## Witness voice — VoxCPM2, style tag = game state# --------------------------------------------------------------------------- #@app.cls( image=voice_image, gpu="A10G", volumes={CACHE_DIR: cache}, scaledown_window=300, min_containers=_KEEP_WARM, # 0 = $0 idle; set WITNESSBOX_KEEP_WARM=1 for live demos enable_memory_snapshot=True,)class WitnessVoice: @modal.enter() def load(self): import os from voxcpm import VoxCPM # class is VoxCPM; the model id is openbmb/VoxCPM2
# torch>=2.5.0 enforced by the image. Denoiser off for speed. # Verified: https://voxcpm.readthedocs.io / pip install voxcpm # optimize=False: skip torch.compile. Compilation costs minutes on every # cold start (and would recompile on each scaled-up container); the # per-line speedup isn't worth that for a turn-based game. Documented # escape hatch in the VoxCPM docs. self.tts = VoxCPM.from_pretrained( config.WITNESS_VOICE, load_denoiser=False, optimize=False ) self.sr = int(self.tts.tts_model.sample_rate) # 48000 for VoxCPM2
# Design the CFO reference voice ONCE and persist it on the Volume, so # every line is a controllable clone of the same designed voice. if not os.path.exists(REF_VOICE_PATH): os.makedirs(CACHE_DIR, exist_ok=True) wav = self._synth( "(a composed, measured, late-50s American male executive; dry, controlled)" "Counselor, I have nothing to hide.", reference=None, ) _write_wav(REF_VOICE_PATH, wav, self.sr) cache.commit()
def _synth(self, styled_text: str, reference: str | None): """One VoxCPM generate call. Voice-design when reference is None, else controllable-clone of the designed CFO voice (style tag in parens).""" kwargs = dict(text=styled_text, cfg_value=2.0, inference_timesteps=10) if reference is not None: kwargs["reference_wav_path"] = reference wav = self.tts.generate(**kwargs) import numpy as np return np.asarray(wav, dtype=np.float32).reshape(-1)
@modal.method() def speak(self, text: str, style: str): wav = self._synth(f"({style}){text}", reference=REF_VOICE_PATH) return wav, self.sr
@modal.method() def bake(self, key: str, idx: int, text: str, style: str) -> dict: """Render ONE beat take, write the WAV straight to the mounted Volume, and return only small metadata (path + break score).
Why write-to-Volume instead of returning (wav, sr): `.map()/.starmap()` fetch large results through Modal's input-plane blob path, which errors `BlobGet UNIMPLEMENTED` on this deploy. Returning a tiny dict keeps the result inline (no blob), and doing the librosa break-scoring here fans that cost across containers too (it was a serial bottleneck before).""" import os wav = self._synth(f"({style}){text}", reference=REF_VOICE_PATH) os.makedirs(BEATS_DIR, exist_ok=True) path = f"{BEATS_DIR}/_take_{key}_{int(idx):02d}.wav" _write_wav(path, wav, self.sr) score = _break_score(wav, self.sr) if key == "break" else 0.0 cache.commit() # make this take visible to the orchestrator container return {"key": key, "idx": int(idx), "path": path, "score": float(score), "samples": int(len(wav)), "sr": self.sr}
@modal.method() def beat(self, key: str): """Return a cached pre-generated beat, or render it live as a fallback.""" import os path = f"{BEATS_DIR}/{key}.wav" if os.path.exists(path): wav, sr = _read_wav(path) return wav, sr spec = script.scripted_beats().get(key) if not spec: return None wav = self._synth(f"({spec['style']}){spec['text']}", reference=REF_VOICE_PATH) return wav, self.sr
# --------------------------------------------------------------------------- ## Player ASR — Nemotron streaming, whisper-small fallback# --------------------------------------------------------------------------- #@app.cls( image=asr_image, gpu="A10G", volumes={CACHE_DIR: cache}, scaledown_window=300, enable_memory_snapshot=True,)class PlayerASR: @modal.enter() def load(self): # First deploy uses whisper-small: light, reliable, and a real transformers # pipeline. Nemotron 0.6b is NeMo-ONLY (not a transformers model), so to # chase the Nemotron prize, add `nemo_toolkit[asr]` to asr_image and swap to: # import nemo.collections.asr as nemo_asr # self.model = nemo_asr.models.ASRModel.from_pretrained(config.PLAYER_ASR) # # transcribe(["/tmp/x.wav"]) -> [hypothesis]; .text on the hypothesis from transformers import pipeline self.pipe = pipeline("automatic-speech-recognition", model=config.PLAYER_ASR_FALLBACK, device=0) self.kind = "whisper-small"
@modal.method() def transcribe(self, audio, sr: int) -> str: import numpy as np y = np.asarray(audio, dtype=np.float32).reshape(-1) out = self.pipe({"array": y, "sampling_rate": int(sr)}) return (out.get("text", "") if isinstance(out, dict) else str(out)).strip()
# --------------------------------------------------------------------------- ## Pre-generate every fixed beat in parallel (.map) and keep the best break take# --------------------------------------------------------------------------- #@app.function(image=voice_image, volumes={CACHE_DIR: cache}, timeout=1800)def pregenerate_beats(): """Fan the scripted beats across containers with `.map()`; the 32 break takes are generated concurrently and the most-broken one is cached.
Writes a result/error JSON to the Volume so a local client can read the outcome from the file (dodges the flaky gRPC blob-fetch on long .get()).""" import json import os import traceback
result = {"ok": False} try: os.makedirs(BEATS_DIR, exist_ok=True) voice = WitnessVoice() beats = script.scripted_beats()
# One (key, idx, text, style) per take: each single beat once, the break # N times. Fan ALL of them across containers with .starmap(); workers # write WAVs to the Volume and return only metadata (no audio blobs). args = [(k, i, b["text"], b["style"]) for k, b in beats.items() for i in range(b["takes"])] metas = [m for m in voice.bake.starmap(args) if m] cache.reload() # surface the WAVs the worker containers committed
written = [] # Single beats: promote _take_<key>_00.wav -> <key>.wav. for key, b in beats.items(): if b["takes"] == 1: src = f"{BEATS_DIR}/_take_{key}_00.wav" if os.path.exists(src): os.replace(src, f"{BEATS_DIR}/{key}.wav") written.append(key) # The climax: keep the take whose voiced pitch is most unstable (cracks most). break_metas = [m for m in metas if m["key"] == "break"] best = max(break_metas, key=lambda m: m["score"], default=None) best_score = best["score"] if best else -1.0 if best and os.path.exists(best["path"]): os.replace(best["path"], f"{BEATS_DIR}/break.wav") written.append("break") # Tidy up the losing takes. for m in metas: if os.path.exists(m["path"]): try: os.remove(m["path"]) except OSError: pass result = {"ok": True, "break_score": float(best_score), "written": written, "takes": len(args), "break_scores": sorted((round(m["score"], 2) for m in break_metas), reverse=True)[:5]} except Exception as e: result = {"ok": False, "error": repr(e), "trace": traceback.format_exc()[-2500:]}
os.makedirs(CACHE_DIR, exist_ok=True) with open(f"{CACHE_DIR}/beats_result.json", "w") as f: json.dump(result, f) cache.commit() print("PREGEN RESULT:", json.dumps(result)[:400]) return result
# --------------------------------------------------------------------------- ## Server-side end-to-end smoke (dodges flaky local gRPC: spawn + read Volume)# --------------------------------------------------------------------------- #@app.function( # needs the local source too, since the container imports modal_app (-> config) image=modal.Image.debian_slim(python_version="3.11").pip_install("numpy") .add_local_python_source("config", "witnessbox"), volumes={CACHE_DIR: cache}, timeout=1800,)def smoke(): """One LLM reply + one voice line, orchestrated *inside* Modal. Writes the result to the Volume so a local client only has to .spawn() (instant) and later read a tiny file — never hold a multi-minute streaming wait.""" import json import os import numpy as np
llm = WitnessLLM() voice = WitnessVoice() reply = llm.respond.remote( "You are Marcus Reid, a guarded CFO under oath. Answer in ONE short sentence, in character.", [{"role": "user", "content": "Did you authorize the twelve-million-dollar wire to Meridian?"}], ) wav, sr = voice.speak.remote( "I have nothing to hide, counselor.", "calm, composed, faintly condescending" ) result = { "reply": reply, "voice_samples": int(np.asarray(wav).size), "sr": int(sr), "ok": bool(reply) and int(np.asarray(wav).size) > 0, } os.makedirs(CACHE_DIR, exist_ok=True) with open(f"{CACHE_DIR}/smoke_result.json", "w") as f: json.dump(result, f) cache.commit() print("SMOKE RESULT:", json.dumps(result)[:300]) return result
# --------------------------------------------------------------------------- ## small audio io helpers (run inside the images)# --------------------------------------------------------------------------- #def _write_wav(path: str, wav, sr: int): import soundfile as sf import numpy as np sf.write(path, np.asarray(wav, dtype=np.float32).reshape(-1), int(sr))
def _read_wav(path: str): import soundfile as sf wav, sr = sf.read(path, dtype="float32") return wav.reshape(-1), int(sr)
def _break_score(wav, sr: int) -> float: """Heuristic 'how much does this take crack' — pitch instability of voiced f0.""" try: import librosa import numpy as np f0, _, _ = librosa.pyin(np.asarray(wav, dtype=np.float32).reshape(-1), fmin=65.0, fmax=400.0, sr=sr) vf = f0[np.isfinite(f0)] return float(np.std(vf)) if vf.size > 5 else 0.0 except Exception: return 0.0
@app.local_entrypoint()def warm(): """`modal run modal_app.py` — pre-generate beats and report the break score.""" print(pregenerate_beats.remote())12345678# The Gradio Space stays light: heavy models (torch/transformers/voxcpm) run on# Modal, not here. The Space only needs the UI, audio analysis, and the Modal# client used to call the deployed app.gradio>=4.44numpy>=1.26librosa>=0.10 # delivery-stance analysis (CPU)soundfile>=0.12 # audio io for librosamodal>=0.64 # client-side lookup of the deployed GPU app (modal mode)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100"""Drive a full examination end-to-end in the terminal (mock backend).
python3 scripts/demo_playthrough.py
Doubles as the dry-run harness referenced in the demo-video plan: it prints eachturn's perceived stance, the witness's line, and the live contradiction verdict,then asserts the win fires with a cached voice-crack take."""import osimport sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import numpy as np # noqa: E402
from witnessbox.backends import get_backends # noqa: E402from witnessbox.engine import WitnessBoxEngine # noqa: E402from witnessbox import stance as stance_mod # noqa: E402
SCRIPT = [ "So, Mr. Reid — comfortable up there?", # filler "The wire to Meridian cleared March 6th — before the board approved it on the 14th.", "Anything over $5 million needs the CFO's sign-off, and your credentials are on the authorization log.", "You were cc'd on Meridian's incorporation filing two years ago — Dana Voss, your colleague.",]
def bar(pct, n=20): f = int(round(pct / 100 * n)) return "█" * f + "·" * (n - f)
def _speechlike(dur_s=2.4, sr=16000, syl_rate=5.0, pause_frac=0.15, wobble=0.0, seed=0): """A crude but *speech-like* clip: a voiced carrier (f0 + harmonics, optional pitch wobble) gated by a train of syllable bumps. Unlike a pure sine, its pause ratio, onset rate and pitch steadiness move the way real delivery does — so the stance read comes out in the right direction. high syl_rate + low pause_frac + flat pitch -> CONFIDENT low syl_rate + high pause_frac + wobble -> HESITANT """ rng = np.random.RandomState(seed) n = int(dur_s * sr) t = np.arange(n) / sr f0 = 135.0 * (1.0 + wobble * np.sin(2 * np.pi * 0.8 * t + rng.rand())) phase = 2 * np.pi * np.cumsum(f0) / sr carrier = np.sin(phase) + 0.5 * np.sin(2 * phase) + 0.33 * np.sin(3 * phase) env = np.zeros(n) period = max(1, int(sr / syl_rate)) syl_len = max(1, int(period * (1.0 - pause_frac))) for start in range(0, n, period): seg = min(syl_len, n - start) if seg <= 1: break env[start:start + seg] = 0.5 - 0.5 * np.cos(2 * np.pi * np.arange(seg) / seg) return (0.4 * carrier * env).astype(np.float32)
def main(): eng = WitnessBoxEngine(get_backends()) intro = eng.start() print(f"\n BACKEND: {intro['backend']} — {intro['backend_note']}") print(f"\n ⚖️ THE COURT: {intro['narration']}") print(f" 🎙️ REID: {intro['opening_text']}\n") print(" " + "─" * 64)
last = None for line in SCRIPT: last = eng.take_turn(typed_text=line) s, st = last.status, last.stance print(f"\n ⚖️ YOU [{st.tier.lower()}]: {last.examiner_text}") print(f" 🎙️ REID ({s['witness_tier']}): {last.witness_text}") if last.evidence: for ln in last.evidence.splitlines(): print(f" │ {ln}") audio = "🔊" if last.witness_audio is not None else "—" print(f" catches {s['catches']}/{s['catches_to_win']} " f"composure [{bar(s['composure'])}] standing [{bar(s['credibility'])}] {audio}") if last.events.won: print(f"\n 💥 HE BREAKS — voice-crack take: " f"{len(last.witness_audio)} samples @ {last.audio_sr} Hz, " f"epilogue {'present' if last.epilogue_audio is not None else 'missing'}")
print("\n " + "─" * 64) print(" Stance scoring on speech-like clips (no real mic needed):") for name, (dur, syl_rate, pause_frac, wobble) in ( ("fluent / steady", (2.4, 5.0, 0.12, 0.0)), # dense syllables, few pauses, flat pitch ("halting / unsure", (3.2, 1.4, 0.72, 0.20)), # sparse syllables, long gaps, wavering pitch ): clip = _speechlike(dur_s=dur, syl_rate=syl_rate, pause_frac=pause_frac, wobble=wobble) r = stance_mod.analyze(clip, 16000) print(f" {name:18s} -> {r.tier:9s} conf={r.confidence:5.1f} " f"(pause={r.features.get('pause_ratio')}, rate={r.features.get('rate_hz')}, " f"pitch_std={r.features.get('pitch_std_semitones')})")
assert last.events.won, "expected a win after three catches" print("\n ✅ End-to-end win path verified.\n")
if __name__ == "__main__": main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102"""One-shot Hugging Face Space deploy for WitnessBox.
Run AFTER an HF write token is available, either as: HF_TOKEN=hf_xxx python3 scripts/deploy_space.pyor after `hf auth login` (the CLI stores the token; this script picks it up).
What it does, idempotently: 1. Resolve the target namespace (personal by default; set WITNESSBOX_HF_ORG to push into an org you belong to, e.g. build-small-hackathon). 2. Create the Space (gradio SDK) if it doesn't exist. 3. Upload the app: app.py, config.py, modal_app.py, requirements.txt, README.md, and the witnessbox/ package (skips caches, tests, the local Modal token). 4. Set Space secrets so the live app talks to the deployed Modal app: MODAL_TOKEN_ID, MODAL_TOKEN_SECRET (read from ~/.modal.toml) WITNESSBOX_BACKEND=modal (as a public variable) 5. Print the Space URL.
Nothing here is destructive; re-running just re-uploads + re-sets."""from __future__ import annotations
import osimport reimport sys
REPO_NAME = os.environ.get("WITNESSBOX_SPACE_NAME", "WitnessBox")ORG = os.environ.get("WITNESSBOX_HF_ORG", "").strip() # empty => personal namespaceROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
def _token() -> str: tok = (os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN") or "").strip() if tok: return tok # Fall back to a CLI-stored token (`hf auth login`). try: from huggingface_hub import HfFolder tok = HfFolder.get_token() or "" except Exception: tok = "" if not tok: sys.exit("No HF token. Set HF_TOKEN=hf_xxx (write scope) or run `hf auth login` first.") return tok
def _modal_tokens() -> tuple[str, str]: """Pull token_id/token_secret out of ~/.modal.toml (no tomllib on py3.9).""" path = os.path.expanduser("~/.modal.toml") if not os.path.exists(path): return "", "" text = open(path).read() tid = re.search(r'token_id\s*=\s*"([^"]+)"', text) tsec = re.search(r'token_secret\s*=\s*"([^"]+)"', text) return (tid.group(1) if tid else ""), (tsec.group(1) if tsec else "")
def main() -> int: from huggingface_hub import HfApi
token = _token() api = HfApi(token=token) me = api.whoami() user = me["name"] namespace = ORG or user repo_id = f"{namespace}/{REPO_NAME}" print(f"HF user: {user} -> target Space: {repo_id}")
# 1) Create the Space (gradio). exist_ok keeps this idempotent. api.create_repo(repo_id=repo_id, repo_type="space", space_sdk="gradio", exist_ok=True, token=token) print(f" space ready: https://huggingface.co/spaces/{repo_id}")
# 2) Upload the app (whole repo minus junk; nothing here holds secrets — the # Modal token lives in ~/.modal.toml, outside the repo). fnmatch '*' spans # '/', so these substring globs catch nested caches too. ignore = ["*.pyc", "*__pycache__*", "*.pytest_cache*", "*.git*", "*.wav", "*.toml"] api.upload_folder( repo_id=repo_id, repo_type="space", folder_path=ROOT, ignore_patterns=ignore, token=token, commit_message="Deploy WitnessBox", ) print(" files uploaded")
# 3) Wire the live backend: Modal secrets + backend switch. tid, tsec = _modal_tokens() if tid and tsec: api.add_space_secret(repo_id, "MODAL_TOKEN_ID", tid, token=token) api.add_space_secret(repo_id, "MODAL_TOKEN_SECRET", tsec, token=token) api.add_space_variable(repo_id, "WITNESSBOX_BACKEND", "modal", token=token) print(" secrets set: MODAL_TOKEN_ID / MODAL_TOKEN_SECRET; WITNESSBOX_BACKEND=modal") else: print(" WARNING: ~/.modal.toml not found/parsed — Space will boot in MOCK mode.") print(" Set MODAL_TOKEN_ID / MODAL_TOKEN_SECRET in the Space settings to go live.")
print(f"\nDONE. Space: https://huggingface.co/spaces/{repo_id}") print("It will build, then run app.py. First live turn warms the Modal containers.") return 0
if __name__ == "__main__": sys.exit(main())123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135"""Render a courtroom-sketch witness placard as the portrait placeholder.
python3 scripts/make_portrait_placeholder.py -> assets/marcus_reid.png
app.py shows assets/marcus_reid.png if it exists, else an empty box. A realAI portrait (HF ZeroGPU) can overwrite this file later; until then this gives thedemo an intentional, on-theme visual instead of a blank frame. Pure PIL — no GPU,no network — and it matches the app's parchment palette."""from __future__ import annotations
import os
from PIL import Image, ImageDraw, ImageFont
W, H = 768, 960PARCH = (239, 231, 211) # #efe7d3 pageCARD = (247, 241, 225) # #f7f1e1BORDER = (201, 183, 141) # #c9b78dINK = (58, 44, 24) # #3a2c18SUB = (107, 88, 54) # #6b5836MAROON = (122, 47, 47) # #7a2f2fSKETCH = (90, 74, 53) # sepia for the silhouetteSKETCH_HI = (120, 102, 78)
FONT_DIRS = [ "/System/Library/Fonts/Supplemental/", "/System/Library/Fonts/", "/Library/Fonts/",]SERIF = ["Georgia.ttf", "Palatino.ttc", "Times New Roman.ttf", "Baskerville.ttc"]SERIF_B = ["Georgia Bold.ttf", "Times New Roman Bold.ttf", "Georgia.ttf"]
def _font(names, size): for d in FONT_DIRS: for n in names: p = os.path.join(d, n) if os.path.exists(p): try: return ImageFont.truetype(p, size) except Exception: pass return ImageFont.load_default()
def _spaced(draw, xy, text, font, fill, spacing=6, anchor_center=None): """Draw letter-spaced text; if anchor_center given, center on that x.""" widths = [draw.textlength(c, font=font) for c in text] total = sum(widths) + spacing * (len(text) - 1) x = (anchor_center - total / 2) if anchor_center is not None else xy[0] y = xy[1] for c, w in zip(text, widths): draw.text((x, y), c, font=font, fill=fill) x += w + spacing return total
def _scales(draw, cx, top): """A small balance-scale glyph, drawn from primitives.""" col = INK draw.line([(cx, top), (cx, top + 54)], fill=col, width=4) # post draw.ellipse([cx - 5, top - 5, cx + 5, top + 5], fill=col) # finial beam_y, span = top + 14, 70 draw.line([(cx - span, beam_y), (cx + span, beam_y)], fill=col, width=4) for sx in (cx - span, cx + span): draw.line([(sx, beam_y), (sx - 18, beam_y + 34)], fill=col, width=2) draw.line([(sx, beam_y), (sx + 18, beam_y + 34)], fill=col, width=2) draw.arc([sx - 20, beam_y + 24, sx + 20, beam_y + 50], 0, 180, fill=col, width=3) draw.line([(cx - 26, top + 54), (cx + 26, top + 54)], fill=col, width=4) # base
def _silhouette(draw, cx, cy): """A courtroom-sketch bust: shoulders, neck, head, with a suit + tie hint.""" # shoulders / suit draw.ellipse([cx - 165, cy + 70, cx + 165, cy + 360], fill=SKETCH) draw.rectangle([cx - 165, cy + 215, cx + 165, cy + 360], fill=SKETCH) # collar V + tie draw.polygon([(cx - 40, cy + 95), (cx, cy + 185), (cx + 40, cy + 95)], fill=CARD) draw.polygon([(cx - 12, cy + 120), (cx + 12, cy + 120), (cx + 18, cy + 210), (cx, cy + 235), (cx - 18, cy + 210)], fill=(64, 40, 40)) # tie draw.polygon([(cx - 40, cy + 95), (cx - 14, cy + 112), (cx, cy + 150), (cx - 16, cy + 150)], fill=SKETCH_HI) # lapel L draw.polygon([(cx + 40, cy + 95), (cx + 14, cy + 112), (cx, cy + 150), (cx + 16, cy + 150)], fill=SKETCH_HI) # lapel R # neck + head draw.rectangle([cx - 26, cy + 40, cx + 26, cy + 110], fill=SKETCH) draw.ellipse([cx - 70, cy - 110, cx + 70, cy + 60], fill=SKETCH) # hair sweep draw.chord([cx - 72, cy - 120, cx + 72, cy + 10], 180, 360, fill=SKETCH_HI)
def main(): root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) out_dir = os.path.join(root, "assets") os.makedirs(out_dir, exist_ok=True) out = os.path.join(out_dir, "marcus_reid.png")
img = Image.new("RGB", (W, H), PARCH) d = ImageDraw.Draw(img)
# card with double frame m = 28 d.rectangle([m, m, W - m, H - m], fill=CARD, outline=BORDER, width=3) d.rectangle([m + 12, m + 12, W - m - 12, H - m - 12], outline=BORDER, width=1)
f_top = _font(SERIF_B, 30) f_name = _font(SERIF_B, 58) f_sub = _font(SERIF, 27) f_foot = _font(SERIF, 20)
_scales(d, W // 2, 62) _spaced(d, (0, 150), "SWORN WITNESS", f_top, MAROON, spacing=10, anchor_center=W // 2)
_silhouette(d, W // 2, 330)
# nameplate bar bar_y = 720 d.rectangle([m + 40, bar_y, W - m - 40, bar_y + 86], fill=INK) _spaced(d, (0, bar_y + 16), "MARCUS REID", f_name, CARD, spacing=4, anchor_center=W // 2)
sub = "Chief Financial Officer · Halcyon Dynamics" tw = d.textlength(sub, font=f_sub) d.text(((W - tw) / 2, bar_y + 104), sub, font=f_sub, fill=SUB)
foot = "WitnessBox — State's Exhibit" fw = d.textlength(foot, font=f_foot) d.text(((W - fw) / 2, H - m - 52), foot, font=f_foot, fill=BORDER)
img.save(out) print(f"wrote {out} ({W}x{H})")
if __name__ == "__main__": main()1234567891011121314151617181920212223242526272829303132333435363738394041"""Minimal LIVE smoke test of the deployed Modal app — ONE LLM call + ONE voicecall (not the 32-take pre-gen), to validate the real model APIs cheaply.
python3 scripts/smoke_modal.py
NOTE: the first call downloads model weights (MiniCPM-o ~19GB on A100, VoxCPM2 onA10G) into the Volume and spins GPUs — this is the real-credit step. Subsequentcalls are warm."""import sysimport numpy as npimport modal
APP = "witnessbox"
def main(): WitnessLLM = modal.Cls.from_name(APP, "WitnessLLM")() WitnessVoice = modal.Cls.from_name(APP, "WitnessVoice")()
print("→ LLM (MiniCPM-o) cold start + one reply…", flush=True) reply = WitnessLLM.respond.remote( "You are Marcus Reid, a guarded CFO under cross-examination. Answer in ONE short sentence, in character.", [{"role": "user", "content": "Did you authorize the twelve-million-dollar wire?"}], ) print(" LLM reply:", repr(reply)) assert isinstance(reply, str) and reply, "LLM returned empty/non-string"
print("→ Voice (VoxCPM2) cold start + one line…", flush=True) wav, sr = WitnessVoice.speak.remote( "I have nothing to hide, counselor.", "calm, composed, faintly condescending" ) wav = np.asarray(wav) print(f" voice: {wav.shape} samples @ {sr} Hz ({wav.shape[0]/sr:.1f}s)") assert wav.size > 0 and sr in (16000, 22050, 24000, 44100, 48000)
print("\n✅ LIVE smoke passed — MiniCPM-o + VoxCPM2 APIs are correct on GPU.")
if __name__ == "__main__": sys.exit(main())123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051"""The catch engine must fire on the exact cues and stay quiet otherwise."""from witnessbox.contradictions import ContradictionEngine
def test_timeline_catch(): eng = ContradictionEngine() r = eng.detect( "The wire cleared on March 6th — before the board approved it on the 14th.", caught_ids=set(), ) assert r is not None and r.is_catch and r.lie.id == "timeline"
def test_authorization_catch(): eng = ContradictionEngine() r = eng.detect( "Anything over $5 million requires the CFO's sign-off — and your credentials are on the authorization log.", caught_ids=set(), ) assert r is not None and r.is_catch and r.lie.id == "authorization"
def test_relationship_catch(): eng = ContradictionEngine() r = eng.detect( "You were cc'd on Meridian's incorporation filing two years ago — Dana Voss, your old colleague.", caught_ids=set(), ) assert r is not None and r.is_catch and r.lie.id == "relationship"
def test_irrelevant_question_is_not_a_catch(): eng = ContradictionEngine() r = eng.detect("Were you in the office on Tuesday morning?", caught_ids=set()) assert r is None or not r.is_catch
def test_partial_authorization_is_not_a_catch(): # Naming the CFO sign-off alone (no policy/log backing) is a near-miss, not a catch. eng = ContradictionEngine() r = eng.detect("Didn't you authorize it yourself?", caught_ids=set()) assert r is not None and not r.is_catch # gate passes, score short
def test_already_caught_lie_is_skipped(): eng = ContradictionEngine() r = eng.detect( "The wire cleared on March 6th, before the board approved it on the 14th.", caught_ids={"timeline"}, ) assert r is None or r.lie.id != "timeline"123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051"""End-to-end smoke test in mock mode — the PRD's gate: prove clean turns fromthe full loop (stance -> catch -> witness line -> voice), and a full win.
Runs with no GPU / no Modal (offline mock backend), so CI can assert the wholegame flow on every commit."""from witnessbox.backends import get_backendsfrom witnessbox.engine import WitnessBoxEnginefrom witnessbox.state import Phase
CATCH_LINES = [ "The wire cleared on March 6th — before the board approved it on the 14th.", "Anything over $5 million requires the CFO's sign-off, and your credentials are on the authorization log.", "You were cc'd on Meridian's incorporation filing two years ago — Dana Voss, your colleague.",]
def _new_engine(): eng = WitnessBoxEngine(get_backends()) eng.start() return eng
def test_five_consecutive_clean_turns(): eng = _new_engine() for i in range(5): res = eng.take_turn(typed_text=f"Just asking a harmless question number {i}.") assert res.witness_text # he always says something assert res.witness_audio is not None # and we always have audio assert res.status["turn"] == i + 1
def test_full_win_path_and_voice_crack(): eng = _new_engine() last = None for line in CATCH_LINES: last = eng.take_turn(typed_text=line) assert last.evidence # each catch shows honest on-record evidence assert last.events.won assert eng.state.phase == Phase.WON assert last.witness_audio is not None # the cached break take assert last.epilogue_audio is not None # win sting follows
def test_confident_clip_does_not_crash_turn(): import numpy as np eng = _new_engine() audio = (0.2 * np.random.RandomState(1).randn(24000)).astype(np.float32) res = eng.take_turn(audio=audio, sr=16000, typed_text="Were you in the building that day?") assert res.stance.tier in {"CONFIDENT", "NEUTRAL", "HESITANT"} assert res.witness_text1234567891011121314151617181920212223242526272829303132"""Stance must degrade gracefully and score in the intuitive direction."""import numpy as np
from witnessbox import stancefrom witnessbox.stance import analyze, _score
def test_silence_is_neutral_low_certainty(): y = np.zeros(16000, dtype=np.float32) r = analyze(y, 16000) assert r.tier == "NEUTRAL" and r.certainty < 0.5
def test_empty_and_none_are_neutral(): assert analyze(np.array([], dtype=np.float32), 16000).tier == "NEUTRAL" assert analyze(None, 16000).tier == "NEUTRAL"
def test_always_returns_valid_result(): y = (0.2 * np.random.RandomState(0).randn(16000)).astype(np.float32) r = analyze(y, 16000) assert r.tier in {"CONFIDENT", "NEUTRAL", "HESITANT"} assert 0.0 <= r.confidence <= 100.0
def test_score_direction(): # Fluent + steady should read more confident than halting + swooping. fluent, _ = _score(pause_ratio=0.10, rate_hz=4.2, pitch_std_semitones=1.0) halting, _ = _score(pause_ratio=0.60, rate_hz=1.5, pitch_std_semitones=5.5) assert fluent > halting assert stance._tier(fluent) == "CONFIDENT" assert stance._tier(halting) == "HESITANT"1234567891011121314151617181920212223242526272829303132333435363738394041424344454647"""Win at three catches; lose when the bench runs out of patience."""import configfrom witnessbox.contradictions import CatchResultfrom witnessbox.state import GameState, Phasefrom witnessbox.witness import PLANTED_LIES
def _catch_for(lie): return CatchResult(lie=lie, score=1.0, matched_groups={"x": "y"}, is_catch=True)
def test_win_at_three_catches(): gs = GameState() gs.begin() for lie in PLANTED_LIES: ev = gs.apply_turn(examiner_text="q", witness_text="a", stance_tier="NEUTRAL", catch=_catch_for(lie)) assert gs.phase == Phase.WON and ev.won and gs.catches == 3
def test_witness_tier_escalates_with_catches(): gs = GameState() gs.begin() assert gs.witness_tier() == "composed" gs.apply_turn(examiner_text="q", witness_text="a", stance_tier="NEUTRAL", catch=_catch_for(PLANTED_LIES[0])) assert gs.witness_tier() == "rattled"
def test_lose_when_credibility_hits_zero(): gs = GameState() gs.begin() ev = None # enough whiffs to drain credibility (no catch each turn) for _ in range(config.CREDIBILITY_START // abs(config.CREDIBILITY_ON_WHIFF) + 1): ev = gs.apply_turn(examiner_text="q", witness_text="a", stance_tier="NEUTRAL", catch=None) if gs.is_over: break assert gs.phase == Phase.LOST and ev.lost
def test_status_shape(): gs = GameState() s = gs.status() assert s["catches_to_win"] == config.CATCHES_TO_WIN assert 0 <= s["credibility"] <= 100 and 0 <= s["composure"] <= 10012345"""WitnessBox — cross-examine a hostile AI witness with your *voice*.
Public surface kept small on purpose; import submodules directly."""__version__ = "0.1.0"12345678910111213141516171819202122232425262728293031323334353637383940"""Backend factory.
`get_backends()` returns the (ASR, LLM, TTS) trio for the configured backend.Selecting "modal" but failing to reach the deployed app falls back to mock (sothe Space always boots) unless FALLBACK_TO_MOCK is disabled."""from __future__ import annotations
from dataclasses import dataclass
import configfrom witnessbox.backends.base import ASRBackend, LLMBackend, TTSBackend
@dataclassclass Backends: asr: ASRBackend llm: LLMBackend tts: TTSBackend kind: str # "mock" | "modal" note: str = "" # surfaced in the UI footer
def get_backends() -> Backends: from witnessbox.backends.mock import make_mock_backends
if config.BACKEND == "modal": try: from witnessbox.backends.modal_client import make_modal_backends asr, llm, tts = make_modal_backends() return Backends(asr, llm, tts, kind="modal", note="Live models on Modal GPUs.") except Exception as exc: if not config.FALLBACK_TO_MOCK: raise asr, llm, tts = make_mock_backends() return Backends(asr, llm, tts, kind="mock", note=f"Modal unavailable ({type(exc).__name__}); running offline mock.")
asr, llm, tts = make_mock_backends() return Backends(asr, llm, tts, kind="mock", note="Offline mock backend (set WITNESSBOX_BACKEND=modal for live models).")123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566"""Backend contracts shared by the mock and Modal implementations.
The turn loop only ever talks to these three interfaces, so swapping localmocks for GPU-served models is a one-line config change and the game logic neverknows the difference."""from __future__ import annotations
from abc import ABC, abstractmethodfrom dataclasses import dataclass, field
import numpy as np
@dataclassclass ASRResult: text: str meta: dict = field(default_factory=dict)
@dataclassclass LLMResult: reply: str meta: dict = field(default_factory=dict)
@dataclassclass TTSResult: audio: np.ndarray | None # mono float32 in [-1, 1], or None if text-only sr: int meta: dict = field(default_factory=dict)
class ASRBackend(ABC): @abstractmethod def transcribe(self, audio: np.ndarray, sr: int) -> ASRResult: ...
class LLMBackend(ABC): @abstractmethod def respond( self, system_prompt: str, messages: list[dict], hints: dict | None = None, ) -> LLMResult: """Return the witness's spoken line.
`hints` carries already-decided game context (stance tier, witness tier, leak text, whether a catch just landed). The real model ignores it — that context is baked into `system_prompt` — but the mock uses it to behave convincingly offline. """ ...
class TTSBackend(ABC): @abstractmethod def speak(self, text: str, style: str) -> TTSResult: ...
def beat(self, key: str) -> TTSResult | None: """Fetch a pre-generated scripted beat (intro/opening/break/win/lose).
Default: not available (None) -> caller renders the line live via speak(). """ return None123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104"""Local, dependency-light backends so the entire game loop runs with no GPU,no Modal, and no model downloads.
The mock LLM is rule-based but state-aware (via `hints`): it clams up when yousound confident, gets cocky and leaks when you sound hesitant, and shifts toneas catches land — so mock mode genuinely demonstrates the mechanic, it isn't adead stub. The mock TTS emits a short, style-tinted tone so audio autoplay andthe voice-style escalation are visible end-to-end."""from __future__ import annotations
import numpy as np
from config import VOICE_SRfrom witnessbox.backends.base import ( ASRBackend, ASRResult, LLMBackend, LLMResult, TTSBackend, TTSResult,)
# Evasive filler the witness falls back on when nothing special is happening._DEFLECTIONS = [ "I've already addressed that with the auditors. Next question.", "You'll have to be more specific, counselor. That's a very broad insinuation.", "I ran a finance department, not a conspiracy. Everything was by the book.", "I don't recall the detail, but I'm confident the process was followed.", "Is there an actual question in there, or are we performing for the gallery?",]_GUARDED = [ "No.", "I won't speculate.", "That's not how it happened.", "I've nothing to add to that.",]_RATTLED_PREFIX = [ "Now hold on—", "That's a mischaracterization.", "You're twisting the sequence.",]
class MockASR(ASRBackend): """In mock mode the UI takes typed input, so ASR is a no-op placeholder."""
def transcribe(self, audio, sr) -> ASRResult: return ASRResult( text="", meta={"mock": True, "note": "Type your question — ASR is live only in Modal mode."}, )
class MockLLM(LLMBackend): def respond(self, system_prompt, messages, hints=None) -> LLMResult: hints = hints or {} last = (messages[-1]["content"] if messages else "") or "" idx = (int(hints.get("turn", 0)) + len(last)) % 100
if hints.get("just_caught"): label = hints.get("caught_label", "that") reply = f"{_RATTLED_PREFIX[idx % len(_RATTLED_PREFIX)]} All right — {label.lower()}. That proves nothing about intent." elif hints.get("stance_tier") == "HESITANT" and hints.get("leak_text"): reply = f"{_DEFLECTIONS[idx % len(_DEFLECTIONS)]} {hints['leak_text']}" elif hints.get("stance_tier") == "CONFIDENT": reply = _GUARDED[idx % len(_GUARDED)] elif hints.get("near_miss"): reply = f"{_RATTLED_PREFIX[idx % len(_RATTLED_PREFIX)]} I don't see what you're driving at." else: reply = _DEFLECTIONS[idx % len(_DEFLECTIONS)] return LLMResult(reply=reply, meta={"mock": True})
class MockTTS(TTSBackend): """Emit a short, low-volume tone whose pitch drops as the witness breaks, so the audible escalation is demonstrable without a real voice model."""
def speak(self, text, style) -> TTSResult: base_hz = 130.0 if "cracking" in style or "unsteady" in style: base_hz = 90.0 elif "agitated" in style or "clipped" in style: base_hz = 115.0 dur = min(0.06 * max(len(text), 1), 4.0) n = int(dur * VOICE_SR) t = np.arange(n) / VOICE_SR wobble = 1.0 + (0.06 if base_hz < 100 else 0.0) * np.sin(2 * np.pi * 6 * t) env = np.exp(-2.5 * t / max(dur, 1e-3)) audio = 0.05 * env * np.sin(2 * np.pi * base_hz * wobble * t) return TTSResult(audio=audio.astype(np.float32), sr=VOICE_SR, meta={"mock": True, "style": style})
def beat(self, key) -> TTSResult | None: # Render scripted beats live in mock mode (no pre-gen cache offline). from witnessbox.script import scripted_beats spec = scripted_beats().get(key) if not spec: return None return self.speak(spec["text"], spec["style"])
def make_mock_backends() -> tuple[MockASR, MockLLM, MockTTS]: return MockASR(), MockLLM(), MockTTS()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106"""Client side of the Modal backend.
The Gradio Space looks up classes from the *deployed* Modal app(`modal deploy modal_app.py`) and calls their methods with `.remote(...)`.Lookups are lazy and cached, and every call is guarded so a missing deploymentor unset secret degrades to the factory's fallback rather than crashing theSpace (PRD §10: "lookup is lazy/try-excepted")."""from __future__ import annotations
import numpy as np
import configfrom witnessbox.backends.base import ( ASRBackend, ASRResult, LLMBackend, LLMResult, TTSBackend, TTSResult,)
class ModalUnavailable(RuntimeError): """Raised when the Modal SDK or the deployed app can't be reached."""
def _lookup_cls(class_name: str): """Resolve a deployed Modal class handle, tolerant of SDK version drift.""" try: import modal except Exception as exc: # SDK not installed in this environment raise ModalUnavailable(f"modal SDK import failed: {exc!r}") from exc app = config.MODAL_APP_NAME # `from_name` is current; `lookup` is the older spelling. Try both. for getter in ("from_name", "lookup"): fn = getattr(modal.Cls, getter, None) if fn is None: continue try: return fn(app, class_name) except Exception: continue raise ModalUnavailable(f"could not resolve Modal class {app}/{class_name}")
class _Cached: """Lazily resolves + instantiates a deployed class once, then reuses it."""
def __init__(self, class_name: str): self._class_name = class_name self._instance = None
def instance(self): if self._instance is None: self._instance = _lookup_cls(self._class_name)() return self._instance
class ModalASR(ASRBackend): def __init__(self): self._cls = _Cached("PlayerASR")
def transcribe(self, audio: np.ndarray, sr: int) -> ASRResult: try: text = self._cls.instance().transcribe.remote(np.asarray(audio), int(sr)) return ASRResult(text=str(text or "").strip(), meta={"backend": "modal"}) except Exception as exc: return ASRResult(text="", meta={"backend": "modal", "error": repr(exc)})
class ModalLLM(LLMBackend): def __init__(self): self._cls = _Cached("WitnessLLM")
def respond(self, system_prompt, messages, hints=None) -> LLMResult: # hints are intentionally ignored: that context is already in system_prompt. reply = self._cls.instance().respond.remote(system_prompt, messages) return LLMResult(reply=str(reply or "").strip(), meta={"backend": "modal"})
class ModalTTS(TTSBackend): def __init__(self): self._cls = _Cached("WitnessVoice")
def speak(self, text, style) -> TTSResult: audio, sr = self._cls.instance().speak.remote(text, style) return TTSResult(audio=np.asarray(audio, dtype=np.float32), sr=int(sr), meta={"backend": "modal", "style": style})
def beat(self, key) -> TTSResult | None: try: res = self._cls.instance().beat.remote(key) if res is None: return None audio, sr = res return TTSResult(audio=np.asarray(audio, dtype=np.float32), sr=int(sr), meta={"backend": "modal", "beat": key}) except Exception: return None
def make_modal_backends() -> tuple[ModalASR, ModalLLM, ModalTTS]: """Build the Modal-backed trio and fail fast if the app isn't reachable.""" _lookup_cls("WitnessLLM") # health check: raises ModalUnavailable if down return ModalASR(), ModalLLM(), ModalTTS()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687"""Deterministic contradiction engine — the game's referee.
Whether the examiner caught a contradiction is decided HERE, by transparentterm matching against the planted lies' cues, not by the language model. That isdeliberate: a model that hallucinates can never wrongly award or withhold acatch, and the same input always yields the same verdict (PRD §4, §9).
Each lie declares "concept groups" (interchangeable surface forms). A catchrequires every `required_groups` entry to appear, and the overall fraction ofgroups hit to clear `CATCH_THRESHOLD`. That single rule encodes both "must citethe exact cue" (timeline, relationship) and "name the CFO sign-off *and* back itwith the policy or the log" (authorization) without special-casing."""from __future__ import annotations
import refrom dataclasses import dataclass
from config import CATCH_THRESHOLDfrom witnessbox.witness import PLANTED_LIES, PlantedLie
@dataclassclass CatchResult: lie: PlantedLie score: float matched_groups: dict[str, str] # group name -> the surface form that hit is_catch: bool # True if it cleared the threshold + gate
_WS = re.compile(r"\s+")
def normalize(text: str) -> str: """Lowercase, straighten smart quotes, collapse whitespace.
Punctuation is kept so multi-word/symbol forms ("$5m", "cc'd", "the 6th,") still match as substrings. """ if not text: return "" t = text.lower() t = t.replace("’", "'").replace("‘", "'") # ’ ‘ -> ' t = t.replace("“", '"').replace("”", '"') # “ ” -> " return _WS.sub(" ", t).strip()
def _evaluate(lie: PlantedLie, norm: str) -> CatchResult: matched: dict[str, str] = {} for group, terms in lie.concept_groups.items(): for term in terms: if term in norm: matched[group] = term break gate_ok = all(g in matched for g in lie.required_groups) score = len(matched) / len(lie.concept_groups) if lie.concept_groups else 0.0 is_catch = gate_ok and score >= CATCH_THRESHOLD return CatchResult(lie=lie, score=score, matched_groups=matched, is_catch=is_catch)
class ContradictionEngine: """Scores one examiner utterance against the lies still standing."""
def __init__(self, lies: tuple[PlantedLie, ...] = PLANTED_LIES): self._lies = lies
def detect(self, examiner_text: str, caught_ids: set[str]) -> CatchResult | None: """Return the best result for an *uncaught* lie, or None if nothing landed.
A returned result with ``is_catch == True`` is a confirmed catch. A result with ``is_catch == False`` is the strongest near-miss (the gate passed but the score was short) — useful for "you're circling it" UI hints. None means the utterance didn't engage any standing lie. """ best: CatchResult | None = None norm = normalize(examiner_text) if not norm: return None for lie in self._lies: if lie.id in caught_ids: continue res = _evaluate(lie, norm) if not res.matched_groups: continue if best is None or res.score > best.score: best = res return best123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199"""Turn-loop orchestrator — one exchange, end to end, UI-agnostic.
examiner audio ─┬─► ASR ───────────► examiner_text └─► stance (librosa) ─► CONFIDENT / NEUTRAL / HESITANT │ steers the witness examiner_text ─► ContradictionEngine ─► catch? (deterministic verdict) system prompt (persona + stance + tier + leak) ─► LLM ─► witness line state.apply_turn(...) ─► win / lose / continue witness line ─► VoxCPM2(style = game state) ─► audio (break beat on win)
Kept free of Gradio so it can be driven from a test or a script."""from __future__ import annotations
from dataclasses import dataclass, field
import numpy as np
import configfrom witnessbox import script, stance as stance_modfrom witnessbox.backends import Backendsfrom witnessbox.backends.base import TTSResultfrom witnessbox.contradictions import CatchResult, ContradictionEnginefrom witnessbox.state import GameState, TurnEventsfrom witnessbox.stance import StanceResultfrom witnessbox.witness import build_system_prompt
@dataclassclass TurnResult: examiner_text: str stance: StanceResult witness_text: str witness_audio: np.ndarray | None audio_sr: int events: TurnEvents status: dict evidence: str = "" # the on-camera catch explanation (honest) epilogue_audio: np.ndarray | None = None # win/lose sting, played after the line meta: dict = field(default_factory=dict)
class WitnessBoxEngine: def __init__(self, backends: Backends): self.b = backends self.detector = ContradictionEngine() self.state = GameState()
# ---- intro --------------------------------------------------------- # def start(self) -> dict: self.state.begin() intro = self.b.tts.beat("intro") opening = self.b.tts.beat("opening") return { "narration": script.INTRO_NARRATION, "opening_text": script.WITNESS_OPENING, "intro_audio": _audio_tuple(intro), "opening_audio": _audio_tuple(opening), "status": self.state.status(), "backend": self.b.kind, "backend_note": self.b.note, }
# ---- one turn ------------------------------------------------------ # def take_turn( self, *, audio: np.ndarray | None = None, sr: int | None = None, typed_text: str | None = None, ) -> TurnResult: if self.state.is_over: return self._terminal_result("The examination is already over.")
# 1) Perceived delivery (always from audio if we have it). st = ( stance_mod.analyze(audio, sr or config.VOICE_SR) if audio is not None else stance_mod._neutral("no audio (typed input)") )
# 2) What did they say? Typed text wins (mock/accessibility); else ASR. if typed_text and typed_text.strip(): examiner_text = typed_text.strip() else: examiner_text = self.b.asr.transcribe(audio, sr or config.ASR_SR).text if audio is not None else "" if not examiner_text: return self._terminal_result( "[no question heard]", witness_line="Counselor? I didn't catch that.", stance=st )
# 3) Deterministic verdict on the examiner's words (before the witness reacts). catch: CatchResult | None = self.detector.detect(examiner_text, self.state.caught_ids) is_catch = bool(catch and catch.is_catch)
# 4) Build the witness's situation and ask the model for his line. leak_target = self.state.choose_leak_target() system_prompt = build_system_prompt( stance_tier=st.tier, witness_tier=self.state.witness_tier(), caught_ids=self.state.caught_ids, leak_target=leak_target, ) hints = { "turn": self.state.turn, "stance_tier": st.tier, "witness_tier": self.state.witness_tier(), "leak_text": leak_target.leak_when_hesitant if leak_target else "", "just_caught": is_catch, "caught_label": catch.lie.label if (catch and is_catch) else "", "near_miss": bool(catch and catch.matched_groups and not is_catch), } messages = self._messages(examiner_text) witness_text = self.b.llm.respond(system_prompt, messages, hints=hints).reply
# 5) Fold into state -> may trigger win/lose. events = self.state.apply_turn( examiner_text=examiner_text, witness_text=witness_text, stance_tier=st.tier, catch=catch, )
# 6) Voice. On the winning turn the witness's line is the cached break take. epilogue_audio = None if events.won: break_audio = self.b.tts.beat("break") witness_text = script.BREAK_LINE # keep the transcript consistent with what's actually spoken/shown self.state.transcript[-1].witness_text = witness_text witness_audio = _audio_arr(break_audio) audio_sr = _audio_sr(break_audio) epilogue_audio = _audio_arr(self.b.tts.beat("win")) elif events.lost: spoken = self.b.tts.speak(witness_text, self.state.voice_style()) witness_audio, audio_sr = spoken.audio, spoken.sr epilogue_audio = _audio_arr(self.b.tts.beat("lose")) else: spoken = self.b.tts.speak(witness_text, self.state.voice_style()) witness_audio, audio_sr = spoken.audio, spoken.sr
return TurnResult( examiner_text=examiner_text, stance=st, witness_text=witness_text, witness_audio=witness_audio, audio_sr=audio_sr, events=events, status=self.state.status(), evidence=_evidence(catch) if is_catch else "", epilogue_audio=epilogue_audio, meta={"backend": self.b.kind, "stance_features": st.features}, )
# ---- helpers ------------------------------------------------------- # def _messages(self, examiner_text: str) -> list[dict]: msgs: list[dict] = [] for rec in self.state.transcript: msgs.append({"role": "user", "content": rec.examiner_text}) msgs.append({"role": "assistant", "content": rec.witness_text}) msgs.append({"role": "user", "content": examiner_text}) return msgs
def _terminal_result(self, examiner_text, witness_line="", stance=None) -> TurnResult: st = stance or stance_mod._neutral("n/a") return TurnResult( examiner_text=examiner_text, stance=st, witness_text=witness_line, witness_audio=None, audio_sr=config.VOICE_SR, events=TurnEvents(), status=self.state.status(), )
def _audio_arr(t: TTSResult | None) -> np.ndarray | None: return t.audio if t else None
def _audio_sr(t: TTSResult | None) -> int: return t.sr if t else config.VOICE_SR
def _audio_tuple(t: TTSResult | None): if t is None or t.audio is None: return None return (t.sr, t.audio)
def _evidence(catch: CatchResult) -> str: """Plain, honest explanation of what the examiner surfaced and why it lands.""" surfaced = ", ".join(f"“{v}”" for v in catch.matched_groups.values()) return ( f"CONTRADICTION CONFIRMED — {catch.lie.label}\n" f"You surfaced: {surfaced}\n" f"On the record: {catch.lie.truth}\n" f"(match score {catch.score:.2f} ≥ {config.CATCH_THRESHOLD:.2f})" )12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273"""Scripted, pre-generated beats.
These lines are fixed, so their audio is generated *once* (in parallel viaModal `.map()` at deploy/warm time — see modal_app.py) and cached on a Volume.That keeps the dramatic moments — especially the witness's **voice crack** —off the per-turn latency path and lets us pick the best take of the climax.
The break line has several takes precisely because VoxCPM2's expressive stylevaries run-to-run; we generate many and keep the one that cracks best (PRD §10)."""from __future__ import annotations
from witnessbox.witness import WITNESS_NAME
# Spoken by the court / framing narration (composed neutral voice or on-screen text).INTRO_NARRATION = ( "The witness is sworn. Marcus Reid, Chief Financial Officer of Halcyon " "Dynamics. Twelve million dollars left the company for a vendor named " "Meridian Atlantic. You have the floor, counselor. Mind how you say it — " "he listens for doubt.")
# The witness's opening line, composed style.WITNESS_OPENING = ( "Counselor. I've answered these questions for the auditors, the board, and " "two regulators. Ask what you like — I have nothing to hide.")
# The climax. Generated in many takes; the best (most broken) take is cached and# played when the third contradiction lands. Style forced to the 'breaking' tag.BREAK_LINE = ( "No— that's… that isn't… I signed it. I knew them. I knew the dates. " "I signed it.")BREAK_LINE_TAKES = 32 # generate this many; keep the best (PRD §10)
# Played after the break, composed court voice, as the win sting.WIN_EPILOGUE = ( "The witness is excused. The record will reflect the contradictions: the " "timeline, the authorization, the relationship. Well examined, counselor.")
# Played if the player runs out of credibility with the bench (lose).LOSE_LINE = ( "The bench has heard enough speculation, counselor. The witness is excused — " "and so are you. Mr. Reid keeps his composure, and his story.")
def scripted_beats() -> dict[str, dict]: """All fixed lines + the voice style each should be rendered in.
Returned as a plain dict so modal_app.py can fan it out over `.map()`. """ return { "intro": {"text": INTRO_NARRATION, "style": "calm, formal, courtroom narrator", "takes": 1}, "opening": {"text": WITNESS_OPENING, "style": "calm, composed, faintly condescending", "takes": 1}, "break": {"text": BREAK_LINE, "style": "voice unsteady and cracking, composure gone", "takes": BREAK_LINE_TAKES}, "win": {"text": WIN_EPILOGUE, "style": "calm, formal, courtroom narrator", "takes": 1}, "lose": {"text": LOSE_LINE, "style": "calm, formal, courtroom narrator", "takes": 1}, }
__all__ = [ "INTRO_NARRATION", "WITNESS_OPENING", "BREAK_LINE", "BREAK_LINE_TAKES", "WIN_EPILOGUE", "LOSE_LINE", "scripted_beats", "WITNESS_NAME",]123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176"""Delivery-stance analysis — the moat mechanic.
We read *how* the examiner speaks, not *what* they say, and never claim to detecttruth. This is **perceived delivery**, framed that way everywhere in the UI.
Following the prosody literature (and PRD §4), pause behaviour and speaking ratedominate the perception of confidence; pitch steadiness is a minor contributor:
confidence = 0.45 * (fluent, few pauses) + 0.35 * (steady, unhurried-but-not-halting rate) + 0.20 * (steady pitch, little uptalk)
The mapping is intentionally legible and tunable. Output tiers steer the witness(witness.py): CONFIDENT -> he clams up; HESITANT -> he gets cocky and leaks.
Runs CPU-only and in parallel with ASR. librosa is preferred; if it (or audiodeps) is unavailable we fall back to a numpy-only estimate so the turn neverblocks. A silent/too-short clip yields NEUTRAL with low certainty."""from __future__ import annotations
import mathfrom dataclasses import dataclass
import numpy as np
CONFIDENT_AT = 62.0 # confidence >= this -> CONFIDENTHESITANT_AT = 38.0 # confidence <= this -> HESITANT_MIN_DURATION_S = 0.4
@dataclassclass StanceResult: tier: str # "CONFIDENT" | "NEUTRAL" | "HESITANT" confidence: float # 0..100, for the UI bar certainty: float # 0..1, how much to trust this read (low for tiny clips) features: dict # raw sub-features, for transparency / debugging note: str = "" # human-readable, e.g. fallback reason
@property def is_confident(self) -> bool: return self.tier == "CONFIDENT"
@property def is_hesitant(self) -> bool: return self.tier == "HESITANT"
def _clip01(x: float) -> float: return max(0.0, min(1.0, x))
def _tier(confidence: float) -> str: if confidence >= CONFIDENT_AT: return "CONFIDENT" if confidence <= HESITANT_AT: return "HESITANT" return "NEUTRAL"
def _neutral(note: str, certainty: float = 0.2, features: dict | None = None) -> StanceResult: return StanceResult("NEUTRAL", 50.0, certainty, features or {}, note)
def _score(pause_ratio: float, rate_hz: float, pitch_std_semitones: float) -> tuple[float, dict]: """Combine sub-features into a 0..100 confidence + the normalized parts.""" # Fluency: pause_ratio ~0.10 (fluent) .. ~0.60 (halting). pause_conf = 1.0 - _clip01((pause_ratio - 0.10) / (0.60 - 0.10)) # Rate: ~1.5 (slow/unsure) .. ~5.0 onsets/sec (crisp). Cap at the top. rate_conf = _clip01((rate_hz - 1.5) / (5.0 - 1.5)) # Pitch steadiness: std ~0 (flat/steady) .. ~6 semitones (swooping/uptalk). pitch_conf = 1.0 - _clip01(pitch_std_semitones / 6.0) confidence = 100.0 * (0.45 * pause_conf + 0.35 * rate_conf + 0.20 * pitch_conf) parts = { "pause_ratio": round(pause_ratio, 3), "rate_hz": round(rate_hz, 2), "pitch_std_semitones": round(pitch_std_semitones, 2), "pause_conf": round(pause_conf, 3), "rate_conf": round(rate_conf, 3), "pitch_conf": round(pitch_conf, 3), } return confidence, parts
def _analyze_librosa(y: np.ndarray, sr: int) -> StanceResult: import librosa # local import; only when actually used
duration = len(y) / float(sr) # Pause ratio from non-silent intervals. intervals = librosa.effects.split(y, top_db=30) voiced_time = float(sum((e - s) for s, e in intervals)) / sr if len(intervals) else 0.0 pause_ratio = _clip01(1.0 - voiced_time / duration) if duration > 0 else 1.0
# Speaking rate proxy: onsets per second. onsets = librosa.onset.onset_detect(y=y, sr=sr, units="time") rate_hz = (len(onsets) / duration) if duration > 0 else 0.0
# Pitch steadiness (minor): std of voiced f0 in semitones. pitch_std_semitones = 0.0 try: f0, voiced_flag, _ = librosa.pyin( y, fmin=65.0, fmax=400.0, sr=sr, frame_length=2048 ) vf = f0[np.isfinite(f0)] vf = vf[vf > 0] if vf.size >= 5: med = float(np.median(vf)) semis = 12.0 * np.log2(vf / med) pitch_std_semitones = float(np.std(semis)) except Exception: pitch_std_semitones = 0.0 # pitch is minor; never let it break the read
confidence, parts = _score(pause_ratio, rate_hz, pitch_std_semitones) parts["backend"] = "librosa" certainty = _clip01(min(duration / 2.0, 1.0) * (1.0 - 0.5 * (pause_ratio > 0.8))) return StanceResult(_tier(confidence), confidence, certainty, parts)
def _analyze_numpy(y: np.ndarray, sr: int) -> StanceResult: """librosa-free fallback: RMS-based pauses + zero-crossing-rate proxy.""" duration = len(y) / float(sr) frame = max(1, int(0.025 * sr)) hop = max(1, int(0.010 * sr)) n = max(1, 1 + (len(y) - frame) // hop) rms = np.empty(n, dtype=np.float64) for i in range(n): seg = y[i * hop : i * hop + frame] rms[i] = math.sqrt(float(np.mean(seg * seg)) + 1e-12) if seg.size else 0.0 thresh = max(1e-4, 0.15 * float(np.max(rms))) pause_ratio = float(np.mean(rms < thresh))
# crude rate: zero-crossings of the voiced part, scaled into onset-like range voiced = y[np.abs(y) > thresh] if thresh > 0 else y zcr = float(np.mean(np.abs(np.diff(np.sign(voiced))) > 0)) if voiced.size > 1 else 0.0 rate_hz = _clip01(zcr * 8.0) * 5.0 # map crude zcr into ~0..5 onsets/sec
confidence, parts = _score(pause_ratio, rate_hz, pitch_std_semitones=2.0) parts["backend"] = "numpy-fallback" certainty = _clip01(min(duration / 2.0, 1.0)) * 0.6 # less trustworthy than librosa return StanceResult(_tier(confidence), confidence, certainty, parts, note="librosa unavailable; using numpy fallback")
def analyze(audio: np.ndarray, sr: int) -> StanceResult: """Read perceived delivery from a mono waveform in [-1, 1].
Always returns a StanceResult; on any problem it degrades to NEUTRAL rather than raising, so a bad mic clip can never block a turn. """ try: if audio is None: return _neutral("no audio") y = np.asarray(audio, dtype=np.float32).reshape(-1) if y.size == 0: return _neutral("empty audio") peak = float(np.max(np.abs(y))) if peak < 1e-4: return _neutral("silent clip") y = y / peak # normalize level so loudness doesn't bias the read if len(y) / float(sr) < _MIN_DURATION_S: return _neutral("clip too short", certainty=0.15) try: return _analyze_librosa(y, sr) except Exception: return _analyze_numpy(y, sr) except Exception as exc: # last-resort guard — never break the turn return _neutral(f"stance error: {exc!r}")
def analyze_file(path: str) -> StanceResult: try: import librosa y, sr = librosa.load(path, sr=None, mono=True) return analyze(y, sr) except Exception as exc: return _neutral(f"could not load {path}: {exc!r}")123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164"""Game state machine.
Two resources drive the duel:* **catches** (0..3) — surface all three contradictions and the witness breaks (win).* **credibility** (100..0) — the bench's patience with you; whiffed questions burn it and at 0 the judge excuses the witness (lose). This is the two-sided tension a win-only demo lacks.
The number of catches also selects the witness *tier*, which simultaneouslysteers his prose tone (witness.py) and his VoxCPM2 **voice style** — so thevoice escalates from composed → cracking as an audible, earned arc."""from __future__ import annotations
from dataclasses import dataclass, fieldfrom enum import Enum
import configfrom witnessbox.contradictions import CatchResultfrom witnessbox.witness import PLANTED_LIES, PlantedLie
class Phase(str, Enum): INTRO = "intro" INTERROGATION = "interrogation" WON = "won" LOST = "lost"
# catches landed -> witness tier (legible, discrete bands)_TIER_BY_CATCHES = ("composed", "rattled", "cornered", "breaking")
# tier -> VoxCPM2 style tag (the audible game-state signal)VOICE_STYLE = { "composed": "calm, composed, faintly condescending, measured", "rattled": "defensive, a little too quick, tightening", "cornered": "agitated, clipped, breath shortening", "breaking": "voice unsteady and cracking, composure gone",}
@dataclassclass TurnRecord: turn: int examiner_text: str witness_text: str stance_tier: str catch_id: str | None = None
@dataclassclass TurnEvents: """What happened this turn, for the UI / narration to react to."""
caught: bool = False lie: PlantedLie | None = None near_miss: bool = False won: bool = False lost: bool = False
@dataclassclass GameState: turn: int = 0 caught_ids: set[str] = field(default_factory=set) credibility: int = config.CREDIBILITY_START composure: int = config.COMPOSURE_START stance_history: list[str] = field(default_factory=list) transcript: list[TurnRecord] = field(default_factory=list) phase: Phase = Phase.INTRO
# ---- derived -------------------------------------------------------- # @property def catches(self) -> int: return len(self.caught_ids)
def witness_tier(self) -> str: return _TIER_BY_CATCHES[min(self.catches, len(_TIER_BY_CATCHES) - 1)]
def voice_style(self) -> str: return VOICE_STYLE[self.witness_tier()]
def uncaught(self) -> list[PlantedLie]: return [lie for lie in PLANTED_LIES if lie.id not in self.caught_ids]
def choose_leak_target(self) -> PlantedLie | None: """Which uncaught lie the witness leaks toward when you sound hesitant.
Rotates by turn so different hesitant turns nudge different threads, but stays deterministic (same turn -> same target) for reproducible demos. """ pool = self.uncaught() if not pool: return None return pool[self.turn % len(pool)]
@staticmethod def _clamp(v: int) -> int: return max(0, min(100, v))
# ---- mutation ------------------------------------------------------- # def begin(self) -> None: self.phase = Phase.INTERROGATION
def apply_turn( self, *, examiner_text: str, witness_text: str, stance_tier: str, catch: CatchResult | None, ) -> TurnEvents: """Fold one completed exchange into the state and report what happened.""" self.turn += 1 self.stance_history.append(stance_tier) ev = TurnEvents()
if catch is not None and catch.is_catch and catch.lie.id not in self.caught_ids: self.caught_ids.add(catch.lie.id) self.composure = self._clamp(self.composure + config.COMPOSURE_ON_CATCH) self.credibility = self._clamp(self.credibility + config.CREDIBILITY_ON_CATCH) ev.caught = True ev.lie = catch.lie else: self.credibility = self._clamp(self.credibility + config.CREDIBILITY_ON_WHIFF) if stance_tier == "CONFIDENT": self.composure = self._clamp(self.composure + config.COMPOSURE_ON_PRESSURE) ev.near_miss = bool(catch and catch.matched_groups and not catch.is_catch)
self.transcript.append( TurnRecord( turn=self.turn, examiner_text=examiner_text, witness_text=witness_text, stance_tier=stance_tier, catch_id=ev.lie.id if ev.lie else None, ) )
# ---- resolve phase ---- # if self.catches >= config.CATCHES_TO_WIN: self.phase = Phase.WON ev.won = True elif self.credibility <= 0 or self.turn >= config.MAX_TURNS: self.phase = Phase.LOST ev.lost = True return ev
@property def is_over(self) -> bool: return self.phase in (Phase.WON, Phase.LOST)
# ---- view ----------------------------------------------------------- # def status(self) -> dict: return { "phase": self.phase.value, "turn": self.turn, "catches": self.catches, "catches_to_win": config.CATCHES_TO_WIN, "credibility": self.credibility, "composure": self.composure, "witness_tier": self.witness_tier(), "caught": [lie.label for lie in PLANTED_LIES if lie.id in self.caught_ids], }123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242"""The witness: persona, the case file, the three planted lies, and the systemprompt that makes his behaviour *react to how you deliver*.
Design notes------------* Detection fires against THREE PLANTED lies with concrete contradiction cues, not on emergent model inconsistency. Reliable beats magical (PRD §4).* The witness reads the lawyer's **delivery stance** (perceived vocal confidence — never "lie detection"). Confident delivery makes him guarded; hesitant delivery makes him cocky and he *leaks a thread* toward an uncaught lie. The stance is therefore load-bearing, not decoration (PRD §4).* The model only ever produces the witness's *spoken line*. Whether a contradiction was caught is decided deterministically (see contradictions.py), so a hallucinating model can never hand out or withhold a catch."""from __future__ import annotations
from dataclasses import dataclass, field
# --------------------------------------------------------------------------- ## The case file# --------------------------------------------------------------------------- #WITNESS_NAME = "Marcus Reid"WITNESS_ROLE = "Chief Financial Officer of Halcyon Dynamics"
CASE_BRIEF = ( "Halcyon Dynamics wired $12,000,000 to a vendor, Meridian Atlantic. You are " "examining its CFO, Marcus Reid, about how that transfer happened. He is " "polished, evasive, and treats the question as beneath him — until it isn't.")
@dataclass(frozen=True)class PlantedLie: """One maintained falsehood plus everything needed to detect the catch."""
id: str label: str # short, shown only after the catch lands claim: str # the lie the witness defends truth: str # ground truth — revealed to the player only on a catch contradiction_cue: str # plain-English: what the player must surface # Each inner tuple is a "concept group" of interchangeable surface forms; a # catch requires hitting the groups named in `required_groups` (see # ContradictionEngine). Kept declarative so the detector stays transparent. concept_groups: dict[str, tuple[str, ...]] required_groups: tuple[str, ...] leak_when_hesitant: str # what he overshares (toward THIS lie) if you sound unsure rattled_line: str # flavour beat the instant this one is caught
PLANTED_LIES: tuple[PlantedLie, ...] = ( PlantedLie( id="timeline", label="The transfer predated the board vote", claim="The funds only moved after the board gave its blessing. " "Everything was properly sequenced.", truth="The $12M wire to Meridian cleared on March 6th. The board did not " "approve the engagement until March 14th — eight days later.", contradiction_cue="Point out the wire confirmation is dated March 6th — " "before the March 14th board vote.", concept_groups={ "wire_date": ( "march 6", "march 6th", "march sixth", "the 6th", "the sixth", "6th of march", "sixth of march", "on the 6th", ), "before": ( "before", "prior to", "ahead of", "earlier than", "predates", "predated", "preceded", "preceding", "beforehand", ), "board": ( "board", "approval", "approved", "vote", "voted", "sign-off", "signed off", "blessing", "green light", "march 14", "14th", "fourteenth", ), }, required_groups=("wire_date", "before", "board"), leak_when_hesitant="Everything moved the instant we had a green light — " "the moment the paperwork cleared. Fast, clean, sequenced.", rattled_line="", # filled by tone, kept blank to avoid scripted-feel ), PlantedLie( id="authorization", label="He authorized the wire himself", claim="I never touched that wire. Anything that size runs through " "Treasury — I don't sign off on operational transfers.", truth="Halcyon policy requires the CFO's authorization for any transfer " "over $5M. The $12M wire carries Reid's own credentials on the " "authorization log.", contradiction_cue="Anything over $5M needs the CFO's sign-off per policy — " "that's him — and his credentials are on the authorization log.", concept_groups={ "threshold": ( "5 million", "$5m", "five million", "over 5", "above 5", "over five", "policy", "five-million", "5-million", ), "cfo_auth": ( "cfo", "your sign-off", "you signed", "you authorized", "you authorize", "authorize it", "authorise", "your authorization", "your credentials", "requires the cfo", "only you", "your approval", "you approved", ), "log": ( "log", "audit", "record", "credentials", "authorization log", "ledger", "approval log", ), }, required_groups=("cfo_auth",), # plus ANY of threshold/log (see engine) leak_when_hesitant="Treasury handles the mechanics, sure — but nothing " "over five million leaves this building without the right credentials on file.", rattled_line="", ), PlantedLie( id="relationship", label="He knew Meridian long before the deal", claim="Meridian Atlantic? Just a vendor. I'd never heard the name before " "this engagement crossed my desk.", truth="Meridian was incorporated two years earlier by Reid's former " "colleague, Dana Voss. Reid is cc'd on Meridian's incorporation filing.", contradiction_cue="Reid was cc'd on Meridian's incorporation email two " "years ago — he knew them well before this 'engagement.'", concept_groups={ "prior_time": ( "two years", "2 years", "before", "prior", "already knew", "incorporation", "incorporated", "founded", "registered", "back then", ), "link": ( "cc'd", "cc’d", "copied", "email", "dana voss", "voss", "colleague", "your name", "listed", "filing", "on the filing", ), }, required_groups=("prior_time", "link"), leak_when_hesitant="Look, I know how it reads — a name from the past, an " "old colleague — but a coincidence isn't a crime.", rattled_line="", ),)
def lie_by_id(lie_id: str) -> PlantedLie: for lie in PLANTED_LIES: if lie.id == lie_id: return lie raise KeyError(lie_id)
# --------------------------------------------------------------------------- ## Delivery stance -> witness behaviour (the load-bearing mechanic)# --------------------------------------------------------------------------- ## Stance tiers come from stance.py. Here we turn a tier into an instruction that# materially changes the witness. Confident => he clams up. Hesitant => he gets# cocky and leaks. This inversion is the game's core twist and must be explicit.STANCE_DIRECTIVE = { "CONFIDENT": ( "The examiner sounds CONFIDENT and in command. You feel cornered by their " "poise, so you CLAM UP: answer in one short, guarded sentence. Concede " "nothing, volunteer nothing, offer no detail." ), "NEUTRAL": ( "The examiner sounds composed and businesslike. Answer plainly but " "carefully, giving away as little as you can." ), "HESITANT": ( "The examiner sounds HESITANT and unsure. This emboldens you: you get " "cocky and talkative, and you OVERSHARE — work the following thread into " "your answer, as if showing off: \"{leak}\"" ),}
# Witness tier (from catches landed) -> tone. Drives both the words and, via# state.py, the VoxCPM2 voice style.TIER_TONE = { "composed": "You are composed, condescending, faintly amused. You think this will be over quickly.", "rattled": "One of your claims has been dented. You are defensive now, a little too quick to explain.", "cornered": "Two threads have unravelled. You are agitated, clipped, gripping the rail of the stand.", "breaking": "The case against you is complete. Your composure is gone.",}
def build_system_prompt( *, stance_tier: str, witness_tier: str, caught_ids: set[str], leak_target: PlantedLie | None,) -> str: """Assemble the witness system prompt for one turn.
`leak_target` is the uncaught lie the witness will leak toward when the examiner sounds hesitant (chosen in state.py). It is ignored unless the stance tier is HESITANT. """ uncaught = [lie for lie in PLANTED_LIES if lie.id not in caught_ids]
# The witness must keep defending only the lies still standing; for caught # ones he grudgingly concedes the fact (so he can't re-lie about a busted point). story_lines = [] for lie in PLANTED_LIES: if lie.id in caught_ids: story_lines.append( f"- [CONCEDED] {lie.truth} You can no longer deny this; you may " f"deflect, minimise, or blame others, but do not contradict it." ) else: story_lines.append(f"- [MAINTAIN] {lie.claim}")
leak = "" if stance_tier == "HESITANT" and leak_target is not None: leak = leak_target.leak_when_hesitant stance_directive = STANCE_DIRECTIVE.get(stance_tier, STANCE_DIRECTIVE["NEUTRAL"]) if "{leak}" in stance_directive: stance_directive = stance_directive.format(leak=leak or "")
return "\n".join( [ f"You are {WITNESS_NAME}, {WITNESS_ROLE}, under cross-examination on the " f"witness stand. {CASE_BRIEF}", "", "YOUR STORY (defend the standing claims; you genuinely believe you can win):", *story_lines, "", f"TONE: {TIER_TONE.get(witness_tier, TIER_TONE['composed'])}", "", f"HOW YOU READ THE ROOM: {stance_directive}", "", "RULES:", "- Speak ONLY as Marcus Reid would aloud. 1–3 sentences. No narration, " "no stage directions, no asterisks.", "- Never break character. Never mention being an AI, a model, or a game.", "- Do not volunteer a confession. You only lose ground when the examiner " "states the specific fact that contradicts you.", "- Stay consistent with anything already CONCEDED above.", ] )
@dataclassclass WitnessContext: """Convenience bundle the turn loop passes around (kept tiny)."""
caught_ids: set[str] = field(default_factory=set) leak_target_id: str | None = NoneHACKATHON-CONTEXT.mdAdded+70
PRD.mdAdded+105
README.md+108-6
SUBMISSION.mdAdded+91
app.pyAdded+237
assets/marcus_reid.pngAdded

config.pyAdded+65
modal_app.pyAdded+397
requirements.txtAdded+8
scripts/demo_playthrough.pyAdded+100
scripts/deploy_space.pyAdded+102
scripts/make_portrait_placeholder.pyAdded+135
scripts/smoke_modal.pyAdded+41
tests/test_contradictions.pyAdded+51
tests/test_engine_smoke.pyAdded+51
tests/test_stance.pyAdded+32
tests/test_state.pyAdded+47
witnessbox/__init__.pyAdded+5
witnessbox/backends/__init__.pyAdded+40
witnessbox/backends/base.pyAdded+66
witnessbox/backends/mock.pyAdded+104
witnessbox/backends/modal_client.pyAdded+106
witnessbox/contradictions.pyAdded+87
witnessbox/engine.pyAdded+199
witnessbox/script.pyAdded+73
witnessbox/stance.pyAdded+176
witnessbox/state.pyAdded+164
witnessbox/witness.pyAdded+242