goumsss commited on
Commit
eb5e547
·
1 Parent(s): f4f474d

Fix audioop-lts for Python 3.13 + add CLAUDE.md agent guidelines

Browse files
Files changed (2) hide show
  1. CLAUDE.md +73 -0
  2. requirements.txt +1 -0
CLAUDE.md ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # NumZoo — Agent Guidelines
2
+
3
+ ## What this project is
4
+ Kids mental math app. Correct answers earn AI-generated cute animal images (FLUX.1-schnell).
5
+ Stack: Python · Gradio · diffusers · HuggingFace Spaces (ZeroGPU).
6
+
7
+ ## Mandatory dev loop — follow for EVERY change
8
+
9
+ ```
10
+ 1. CODE → edit files
11
+ 2. SYNTAX → ~/miniforge3/bin/python3 -c "import ast; [ast.parse(open(f).read()) for f in ['app.py','image_generator.py','math_engine.py']]"
12
+ 3. RUN → kill previous instance, start fresh:
13
+ pkill -f "python3 app.py"; ~/miniforge3/bin/python3 app.py > /tmp/numzoo.log 2>&1 &
14
+ sleep 10 && cat /tmp/numzoo.log # must show no errors
15
+ 4. TEST → run Puppeteer (arm64 Node):
16
+ arch -arm64 /bin/zsh -c "source ~/.nvm/nvm.sh && nvm use 20 && cd /Users/uplab/projects/puppeteer && node test_lovemath.mjs"
17
+ → take screenshots, read them, verify visually
18
+ 5. FIX → if any step fails, fix and restart from step 1
19
+ 6. PUSH → only when all steps pass:
20
+ git add -A && git commit -m "..." && git push origin main
21
+ ```
22
+
23
+ **Never push broken code.** If Puppeteer tests fail, do not proceed to push.
24
+
25
+ ## Key files
26
+
27
+ | File | Role |
28
+ |------|------|
29
+ | `app.py` | Gradio UI, game logic, panel visibility, event wiring |
30
+ | `image_generator.py` | FLUX.1-schnell pipeline, emoji→text prompt builder |
31
+ | `math_engine.py` | Question generation, level names & thresholds |
32
+ | `requirements.txt` | Python dependencies (HF Spaces uses Python 3.13) |
33
+ | `README.md` | HF Spaces config (frontmatter) + user docs |
34
+
35
+ ## Architecture
36
+
37
+ **3-panel flow:** Welcome → Emoji Picker → Quiz
38
+
39
+ **Game state dict keys:**
40
+ `name`, `level`, `score`, `streak`, `correct_since_reward`, `level_correct`,
41
+ `question`, `answer`, `selected_animals`, `selected_places`,
42
+ `future` (ThreadPoolExecutor Future), `awaiting_reward`
43
+
44
+ **Reward trigger:** every `REWARD_EVERY = 3` correct answers.
45
+ Image generation starts in background (ThreadPoolExecutor) as soon as quiz begins.
46
+
47
+ ## Gradio rules
48
+ - Use `gr.update(visible=True/False)` — never return bare `True/False` for component visibility
49
+ - Theme and CSS go in `demo.launch(css=..., theme=...)`, NOT in `gr.Blocks()`
50
+ - `gr.Group` has no `.change()` event — use explicit output returns from handlers
51
+ - HF Spaces runs Python 3.13 — watch for removed stdlib modules (`audioop` → add `audioop-lts`)
52
+
53
+ ## Python runtime
54
+ - **Local:** `~/miniforge3/bin/python3` (arm64, Python 3.13, torch 2.12, MPS)
55
+ - **HF Spaces:** Python 3.13, ZeroGPU (A100 on demand via `@spaces.GPU`)
56
+ - **DO NOT use** `/usr/local/bin/python3` — it's x64 Rosetta, torch 2.2, incompatible with latest diffusers
57
+
58
+ ## Image generation
59
+ - Model: `black-forest-labs/FLUX.1-schnell` (gated — must accept license on HF)
60
+ - Local speed: ~5 min on MPS · HF ZeroGPU: ~5 sec
61
+ - Always wrap generation in try/except → return `(None, "")` on failure
62
+ - `IS_HF_SPACE = os.environ.get("SPACE_ID") is not None` controls ZeroGPU decorator
63
+
64
+ ## HuggingFace deployment
65
+ - Space: `https://huggingface.co/spaces/Goumsss/numzoo`
66
+ - Remote: `https://huggingface.co/spaces/Goumsss/numzoo` (already set)
67
+ - Push = redeploy. Space rebuilds automatically on every push.
68
+ - ZeroGPU requires HF Pro or hackathon grant (set in Space Settings → Hardware)
69
+
70
+ ## UI/UX principles
71
+ - Text: English, minimal — **words not sentences** (kids with limited English)
72
+ - Feedback: emoji-heavy, short (`✅ Great! 🔥🔥` not `Congratulations, your answer was correct!`)
73
+ - Never crash visibly — all handlers wrapped in try/except with safe fallback returns
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  gradio>=4.40.0
 
2
  diffusers>=0.30.0
3
  transformers>=4.44.0
4
  accelerate>=0.33.0
 
1
  gradio>=4.40.0
2
+ audioop-lts
3
  diffusers>=0.30.0
4
  transformers>=4.44.0
5
  accelerate>=0.33.0