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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
## Run locally
|
| 26 |
|
| 27 |
```bash
|
| 28 |
# Install
|
| 29 |
-
uv sync # or pip install -e .
|
| 30 |
|
| 31 |
-
# Build index (The Office transcripts
|
| 32 |
witgym-index
|
| 33 |
|
| 34 |
-
#
|
| 35 |
-
python -m witgym.main --debug
|
| 36 |
-
|
| 37 |
-
# Gradio UI (local model)
|
| 38 |
-
python app.py
|
| 39 |
-
|
| 40 |
-
# Gradio UI via Hugging Face Inference Providers (no local 9B weights)
|
| 41 |
export HF_TOKEN=hf_...
|
| 42 |
export LLM_BACKEND=hf_api
|
| 43 |
python app.py
|
|
|
|
|
|
|
|
|
|
| 44 |
```
|
| 45 |
|
| 46 |
-
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
Set these
|
| 49 |
|
| 50 |
| Secret | Value |
|
| 51 |
-
|---
|
| 52 |
-
| `HF_TOKEN` | Write token with read access to the data dataset
|
| 53 |
-
| `LLM_BACKEND` | `hf_api`
|
| 54 |
-
| `WITGYM_DATA_REPO` | `build-small-hackathon/witgym-data` (default
|
| 55 |
|
| 56 |
-
Optional: `HF_INFERENCE_PROVIDER` (defaults to `together`
|
| 57 |
|
| 58 |
Do **not** set `WITGYM_SKIP_HUB` on the Space.
|
| 59 |
|
| 60 |
-
|
| 61 |
|
| 62 |
-
|
| 63 |
|
| 64 |
-
|
| 65 |
|
| 66 |
```bash
|
| 67 |
hf upload build-small-hackathon/witgym-data \
|
| 68 |
-
data/
|
| 69 |
-
--repo-type dataset --private
|
| 70 |
|
| 71 |
hf upload build-small-hackathon/witgym-data \
|
| 72 |
-
data/
|
| 73 |
-
--repo-type dataset
|
| 74 |
```
|
| 75 |
|
| 76 |
-
|
| 77 |
|
| 78 |
-
|
| 79 |
|
| 80 |
-
##
|
| 81 |
|
| 82 |
Pushes to `main` sync code to the Space via [`.github/workflows/sync-to-hub.yml`](.github/workflows/sync-to-hub.yml).
|
| 83 |
|
| 84 |
| Where | Secret | Purpose |
|
| 85 |
-
|---
|
| 86 |
-
| GitHub repo secrets | `HF_TOKEN` | CI
|
| 87 |
| Space secrets | `HF_TOKEN`, `WITGYM_DATA_REPO`, `LLM_BACKEND` | Runtime Hub API + dataset + inference |
|
| 88 |
|
| 89 |
These are **two different** `HF_TOKEN` placements. Configuring GitHub does not configure the Space runtime.
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
- **Small talk** (hi, who are you) β polite identity reply, no pipeline
|
| 94 |
-
- **Humour practice** β Pass 1 metadata β RAG retrieval β Pass 2 personas β rank β compress
|
| 95 |
|
| 96 |
-
|
|
|
|
| 16 |
- qwen
|
| 17 |
---
|
| 18 |
|
| 19 |
+
# π WitGym
|
| 20 |
|
| 21 |
+
> *A comedy coaching engine grounded in human precedent β not vibes.*
|
| 22 |
|
| 23 |
+
Paste an awkward real-life situation. WitGym dissects the **neurological structure of the moment**, retrieves analogous scenes from The Office, generates three distinct witty responses as different personas, ranks them, and explains precisely *why* the winner lands.
|
| 24 |
+
|
| 25 |
+
**[β Try it live on Hugging Face Spaces](https://huggingface.co/spaces/build-small-hackathon/WitGym)**
|
| 26 |
+
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
## Why comedy is hard for AI
|
| 30 |
+
|
| 31 |
+
Every comedy coaching app just asks a model to "be funny." That's like asking someone to "be good at chess" without ever showing them a game.
|
| 32 |
+
|
| 33 |
+
Wit has **structure**. It emerges from the gap between what's socially expected and what gets said. The Office didn't write jokes β it wrote *situations*, then let characters navigate them in character-consistent ways. That's the thing to learn from.
|
| 34 |
+
|
| 35 |
+
WitGym treats comedy the way researchers do: as a system of **social violations, status games, and tension types** β then grounds responses in scenes that worked for the same reason.
|
| 36 |
+
|
| 37 |
+
---
|
| 38 |
+
|
| 39 |
+
## Architecture
|
| 40 |
+
|
| 41 |
+
```mermaid
|
| 42 |
+
flowchart TD
|
| 43 |
+
A[User: paste awkward situation] --> B{Small talk?}
|
| 44 |
+
B -- yes --> C[Identity reply β no pipeline]
|
| 45 |
+
B -- no --> D
|
| 46 |
+
|
| 47 |
+
D[Pass 1 β Neurology of Comedy\nQwen3.5-27B extracts 10 structural fields]
|
| 48 |
+
D --> E[Archetype + Tension + Distance\nComedyMetadata schema]
|
| 49 |
+
E --> F[BGE-small embedder\n384-dim semantic vector]
|
| 50 |
+
F --> G[FAISS search\n4021 Office scene index]
|
| 51 |
+
G --> H[Top-3 precedent scenes\nwith why_it_works annotations]
|
| 52 |
+
H --> I[Pass 2 β Persona Generation\n3 candidates: Deadpan Β· Absurdist Β· Strategist]
|
| 53 |
+
I --> J[Pass 3 β Tournament Ranking\nranked by structural fit to the metadata]
|
| 54 |
+
J --> K[Pass 4 β Compression\nreduce to one sharp line]
|
| 55 |
+
K --> L[Coaching\noptional: what made this work?]
|
| 56 |
+
L --> M[Response + full debug trace]
|
| 57 |
+
|
| 58 |
+
style D fill:#1a1a2e,color:#ffd700,stroke:#ffd700
|
| 59 |
+
style G fill:#16213e,color:#4fc3f7,stroke:#4fc3f7
|
| 60 |
+
style I fill:#0f3460,color:#f8f8f8,stroke:#e94560
|
| 61 |
+
style M fill:#1a1a2e,color:#b0f4b0,stroke:#4caf50
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
---
|
| 65 |
+
|
| 66 |
+
## The Comedy Science
|
| 67 |
+
|
| 68 |
+
WitGym models comedy as three interacting structural properties:
|
| 69 |
+
|
| 70 |
+
| Property | Enum | What it captures |
|
| 71 |
+
|---|---|---|
|
| 72 |
+
| **Archetype** | `ComedyArchetype` | *Why* this moment is funny in principle β e.g. `STATUS_ASSERTION`, `SELF_DELUSION_EXPOSED`, `POWER_INVERSION` |
|
| 73 |
+
| **Tension type** | `TensionType` | *What* is at stake β e.g. `SOCIAL_EMBARRASSMENT`, `STATUS_THREAT`, `IDENTITY_EXPOSURE` |
|
| 74 |
+
| **Violation distance** | `ViolationDistance` | *How far* to push β `mild`, `moderate`, `sharp` |
|
| 75 |
+
|
| 76 |
+
These aren't vibes. They're used to:
|
| 77 |
+
1. Select the right **precedent scenes** from the index (cosine similarity on archetype + semantic embedding)
|
| 78 |
+
2. Constrain **persona generation** (each persona must violate in a structurally consistent way)
|
| 79 |
+
3. **Rank** candidates (the winner resolves the tension most cleanly)
|
| 80 |
+
|
| 81 |
+
The pipeline produces a `ComedyMetadata` object with 10 fields β including `connector` (the double-meaning word that makes a line land), `subtext` (what's actually being communicated), and `twist_potential` (comedy richness score 1β10 used to gate the full pipeline vs. quick response).
|
| 82 |
+
|
| 83 |
+
---
|
| 84 |
+
|
| 85 |
+
## The Retrieval System
|
| 86 |
+
|
| 87 |
+
4,021 indexed scenes from The Office, each annotated with:
|
| 88 |
+
- `archetype`, `tension_type`, `violation_distance` β structural labels
|
| 89 |
+
- `why_it_works` β a one-sentence explanation of the comedy mechanism
|
| 90 |
+
- `setup` + `response` β the actual scene
|
| 91 |
+
|
| 92 |
+
At query time, the user's situation is embedded with **BGE-small** (33M params) and retrieved against the index via cosine similarity. The retrieval finds scenes with the **same comedy structure** β not the same topic.
|
| 93 |
+
|
| 94 |
+
```mermaid
|
| 95 |
+
flowchart LR
|
| 96 |
+
A[User situation] --> B[BGE-small encoder\n33M params]
|
| 97 |
+
B --> C[384-dim vector]
|
| 98 |
+
C --> D[FAISS index\n4021 scenes Γ 384 dims]
|
| 99 |
+
D --> E[Top-3 scenes\nby cosine similarity]
|
| 100 |
+
E --> F[Injected as few-shot\nexamples into Pass 2 prompt]
|
| 101 |
+
style B fill:#1a3a5c,color:#4fc3f7
|
| 102 |
+
style D fill:#1a3a5c,color:#4fc3f7
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
---
|
| 106 |
+
|
| 107 |
+
## Pipeline flow
|
| 108 |
+
|
| 109 |
+
```mermaid
|
| 110 |
+
sequenceDiagram
|
| 111 |
+
participant U as User
|
| 112 |
+
participant A as app.py
|
| 113 |
+
participant E as WitGymEngine
|
| 114 |
+
participant L as LLM (Qwen3.5-27B)
|
| 115 |
+
participant I as BGE Index
|
| 116 |
+
|
| 117 |
+
U->>A: Paste situation
|
| 118 |
+
A->>E: respond(user_input)
|
| 119 |
+
|
| 120 |
+
Note over E,L: Pass 1 β Metadata extraction
|
| 121 |
+
E->>L: Extract ComedyMetadata (10 fields)
|
| 122 |
+
L-->>E: archetype + tension + distance + subtext...
|
| 123 |
+
|
| 124 |
+
Note over E,I: RAG retrieval
|
| 125 |
+
E->>I: embed(surface) β cosine search
|
| 126 |
+
I-->>E: 3 precedent scenes
|
| 127 |
+
|
| 128 |
+
Note over E,L: Pass 2 β Candidate generation
|
| 129 |
+
E->>L: Generate 3 personas (Deadpan, Absurdist, Strategist)
|
| 130 |
+
L-->>E: 3 candidate responses (streaming)
|
| 131 |
+
|
| 132 |
+
Note over E,L: Pass 3 β Tournament ranking
|
| 133 |
+
E->>L: Rank candidates by structural fit
|
| 134 |
+
L-->>E: winner + explanation
|
| 135 |
+
|
| 136 |
+
Note over E,L: Pass 4 β Compression
|
| 137 |
+
E->>L: Compress winner to one sharp line
|
| 138 |
+
L-->>E: final response
|
| 139 |
+
|
| 140 |
+
E-->>A: PipelineEvent stream
|
| 141 |
+
A-->>U: Streaming response + debug trace
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
---
|
| 145 |
+
|
| 146 |
+
## UI: Progressive Disclosure
|
| 147 |
+
|
| 148 |
+
The coaching panel uses a **progressive disclosure** architecture β the full debug trace is always computed, but revealed in layers:
|
| 149 |
+
|
| 150 |
+
- **Chips** (STATUS ASSERTION, STATUS THREAT, MODERATE) β tap to get a one-line definition of what that label means
|
| 151 |
+
- **Capsules** (SUBTEXT, POWER DYNAMIC) β tap to expand the actual analysis of your situation
|
| 152 |
+
- **Coaching notes** β expandable panel with the structural explanation of why the response works
|
| 153 |
+
|
| 154 |
+
New elements animate in with a shimmer sweep + border glow system that stops on first interaction. This mirrors how Notion and Apple iOS handle progressive discovery β purposeful discoverability signaling, not decoration.
|
| 155 |
+
|
| 156 |
+
---
|
| 157 |
+
|
| 158 |
+
## Tech Stack
|
| 159 |
+
|
| 160 |
+
| Layer | Choice | Why |
|
| 161 |
+
|---|---|---|
|
| 162 |
+
| **LLM** | Qwen3.5-27B via HF Inference Providers | β€32B constraint; best instruction-following at this size |
|
| 163 |
+
| **Embedder** | BGE-small (33M params) | Fast, accurate, runs on CPU in < 50ms |
|
| 164 |
+
| **Index** | FAISS flat cosine, 4021 scenes Γ 384 dims | No server needed; loaded at startup from Hub dataset |
|
| 165 |
+
| **UI** | Gradio 6.x on HF Spaces | Streaming SSE, custom CSS theming |
|
| 166 |
+
| **Validation** | Pydantic v2 | Schema-enforced extraction; fallback on parse failure |
|
| 167 |
+
| **Retry** | Exponential backoff on all LLM calls | Handles upstream provider flakiness gracefully |
|
| 168 |
+
|
| 169 |
+
---
|
| 170 |
+
|
| 171 |
+
## Build Small compliance
|
| 172 |
+
|
| 173 |
+
- **Model size**: Qwen3.5-27B β€ 32B β
|
| 174 |
+
- **Embedder**: BGE-small 33M β runs on CPU, no GPU needed for retrieval β
|
| 175 |
+
- **Deployed on HF Spaces**: Gradio app, streams via SSE β
|
| 176 |
+
- **Open source**: MIT licensed β
|
| 177 |
+
- No fine-tuning required β all comedy structure is in the retrieval index and prompts
|
| 178 |
+
|
| 179 |
+
---
|
| 180 |
+
|
| 181 |
+
## What makes this different
|
| 182 |
+
|
| 183 |
+
| Approach | Problem |
|
| 184 |
+
|---|---|
|
| 185 |
+
| "Respond wittily to: [situation]" | No structural understanding; generic, contextless outputs |
|
| 186 |
+
| RAG on jokes | Jokes don't transfer β the *situation structure* transfers |
|
| 187 |
+
| **WitGym** | Extracts comedy structure β retrieves same-structure precedents β generates constrained by that structure |
|
| 188 |
+
|
| 189 |
+
The insight: The Office didn't write great jokes. It wrote great **situations**, then populated them with characters who respond in structurally consistent ways. WitGym learns from the situations, not the punchlines.
|
| 190 |
+
|
| 191 |
+
---
|
| 192 |
|
| 193 |
## Run locally
|
| 194 |
|
| 195 |
```bash
|
| 196 |
# Install
|
| 197 |
+
uv sync # or: pip install -e .
|
| 198 |
|
| 199 |
+
# Build index (The Office transcripts)
|
| 200 |
witgym-index
|
| 201 |
|
| 202 |
+
# Run with HF Inference API (recommended β no local weights needed)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
export HF_TOKEN=hf_...
|
| 204 |
export LLM_BACKEND=hf_api
|
| 205 |
python app.py
|
| 206 |
+
|
| 207 |
+
# Run with local weights (MPS/CUDA)
|
| 208 |
+
python app.py
|
| 209 |
```
|
| 210 |
|
| 211 |
+
---
|
| 212 |
+
|
| 213 |
+
## HF Spaces configuration
|
| 214 |
|
| 215 |
+
Set these in Space settings β **not** in GitHub. CI only syncs code; runtime auth is separate.
|
| 216 |
|
| 217 |
| Secret | Value |
|
| 218 |
+
|---|---|
|
| 219 |
+
| `HF_TOKEN` | Write token with read access to the data dataset |
|
| 220 |
+
| `LLM_BACKEND` | `hf_api` |
|
| 221 |
+
| `WITGYM_DATA_REPO` | `build-small-hackathon/witgym-data` (default) |
|
| 222 |
|
| 223 |
+
Optional: `HF_INFERENCE_PROVIDER` (defaults to `together`), `WITGYM_INDEX_PATH`.
|
| 224 |
|
| 225 |
Do **not** set `WITGYM_SKIP_HUB` on the Space.
|
| 226 |
|
| 227 |
+
---
|
| 228 |
|
| 229 |
+
## Large data on HF Hub
|
| 230 |
|
| 231 |
+
Files over 1 MB (`office_generated.txt`, `index.npz`) live in a private org dataset, not in git. At startup the app fetches `index.npz` from the Hub; if auth fails it falls back to rebuilding from bundled transcripts.
|
| 232 |
|
| 233 |
```bash
|
| 234 |
hf upload build-small-hackathon/witgym-data \
|
| 235 |
+
data/index.npz index.npz --repo-type dataset
|
|
|
|
| 236 |
|
| 237 |
hf upload build-small-hackathon/witgym-data \
|
| 238 |
+
data/transcripts/office_generated.txt office_generated.txt \
|
| 239 |
+
--repo-type dataset --private
|
| 240 |
```
|
| 241 |
|
| 242 |
+
When transcripts change: re-run `witgym-index`, then re-upload `index.npz`. Offline dev: set `WITGYM_SKIP_HUB=1`.
|
| 243 |
|
| 244 |
+
---
|
| 245 |
|
| 246 |
+
## CI/CD
|
| 247 |
|
| 248 |
Pushes to `main` sync code to the Space via [`.github/workflows/sync-to-hub.yml`](.github/workflows/sync-to-hub.yml).
|
| 249 |
|
| 250 |
| Where | Secret | Purpose |
|
| 251 |
+
|---|---|---|
|
| 252 |
+
| GitHub repo secrets | `HF_TOKEN` | CI push to Space only |
|
| 253 |
| Space secrets | `HF_TOKEN`, `WITGYM_DATA_REPO`, `LLM_BACKEND` | Runtime Hub API + dataset + inference |
|
| 254 |
|
| 255 |
These are **two different** `HF_TOKEN` placements. Configuring GitHub does not configure the Space runtime.
|
| 256 |
|
| 257 |
+
---
|
|
|
|
|
|
|
|
|
|
| 258 |
|
| 259 |
+
Built for the [Hugging Face Build Small Hackathon 2026](https://huggingface.co/build-small-hackathon).
|