Docs: update CLAUDE.md + README for FLUX.2-klein-4B
Browse files- Reflect model switch (FLUX.1-schnell → FLUX.2-klein-4B) everywhere
- Document persistent cache behaviour + path-bump recovery pattern
- Note NUMZOO_STYLE shared constant between app and dataset generator
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
CLAUDE.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
# NumZoo — Agent Guidelines
|
| 2 |
|
| 3 |
## What this project is
|
| 4 |
-
Kids mental math app. Correct answers earn AI-generated cute animal images (FLUX.
|
| 5 |
Stack: Python · Gradio · diffusers · HuggingFace Spaces (ZeroGPU).
|
| 6 |
|
| 7 |
## Mandatory dev loop
|
|
@@ -24,7 +24,7 @@ Full loop shortcut: `bash scripts/dev.sh` (runs steps 1–4, then run test.sh ma
|
|
| 24 |
| File | Role |
|
| 25 |
|------|------|
|
| 26 |
| `app.py` | Gradio UI, game logic, panel visibility, event wiring |
|
| 27 |
-
| `image_generator.py` | FLUX.
|
| 28 |
| `math_engine.py` | Question generation, level names & thresholds |
|
| 29 |
| `requirements.txt` | Python dependencies — never include `gradio` here |
|
| 30 |
| `README.md` | HF Spaces config (frontmatter `sdk_version`) + user docs |
|
|
@@ -75,10 +75,22 @@ This is more reliable in Gradio 6 than toggling visibility on gr.HTML components
|
|
| 75 |
- Do not use system Python (`/usr/local/bin/python3`) — it's x64 Rosetta, incompatible
|
| 76 |
|
| 77 |
## Image generation
|
| 78 |
-
- Model: `black-forest-labs/FLUX.
|
| 79 |
-
-
|
|
|
|
|
|
|
| 80 |
- Always wrap in try/except → return `(None, "")` on failure
|
| 81 |
- `IS_HF_SPACE = os.environ.get("SPACE_ID") is not None` controls ZeroGPU decorator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
## HuggingFace deployment
|
| 84 |
- Space: `https://huggingface.co/spaces/Goumsss/numzoo`
|
|
|
|
| 1 |
# NumZoo — Agent Guidelines
|
| 2 |
|
| 3 |
## What this project is
|
| 4 |
+
Kids mental math app. Correct answers earn AI-generated cute animal images (FLUX.2-klein-4B).
|
| 5 |
Stack: Python · Gradio · diffusers · HuggingFace Spaces (ZeroGPU).
|
| 6 |
|
| 7 |
## Mandatory dev loop
|
|
|
|
| 24 |
| File | Role |
|
| 25 |
|------|------|
|
| 26 |
| `app.py` | Gradio UI, game logic, panel visibility, event wiring |
|
| 27 |
+
| `image_generator.py` | FLUX.2-klein-4B pipeline, persistent cache setup, emoji→text prompt builder |
|
| 28 |
| `math_engine.py` | Question generation, level names & thresholds |
|
| 29 |
| `requirements.txt` | Python dependencies — never include `gradio` here |
|
| 30 |
| `README.md` | HF Spaces config (frontmatter `sdk_version`) + user docs |
|
|
|
|
| 75 |
- Do not use system Python (`/usr/local/bin/python3`) — it's x64 Rosetta, incompatible
|
| 76 |
|
| 77 |
## Image generation
|
| 78 |
+
- Model: `black-forest-labs/FLUX.2-klein-4B` (Apache 2.0 — accept license on HF before first run)
|
| 79 |
+
- Same model local + HF Spaces. 4 steps, `guidance_scale=1.0`, 512×512
|
| 80 |
+
- Local: float16 on MPS (needs ~13GB, fits in 32GB unified mem) · HF ZeroGPU: ~fast on A100
|
| 81 |
+
- Pipeline class: `Flux2KleinPipeline` (diffusers ≥ 0.38)
|
| 82 |
- Always wrap in try/except → return `(None, "")` on failure
|
| 83 |
- `IS_HF_SPACE = os.environ.get("SPACE_ID") is not None` controls ZeroGPU decorator
|
| 84 |
+
- Logs generation time (`✅ Generated in Xs`)
|
| 85 |
+
|
| 86 |
+
## Persistent model cache (HF Spaces)
|
| 87 |
+
- `/data/hf_cache_v4` mount caches the model across restarts (set in Space Settings → Storage)
|
| 88 |
+
- Setup is **bulletproof**: poisoned/partial cache is auto-wiped & re-downloaded;
|
| 89 |
+
any `/data` failure falls back to ephemeral container cache; import never crashes
|
| 90 |
+
- If the cache tree gets poisoned again (`[Errno 20] Not a directory`), bump the
|
| 91 |
+
path suffix (`_v4` → `_v5`) to escape it — established repo pattern
|
| 92 |
+
- `NUMZOO_STYLE` constant in `image_generator.py` is the single source of truth for
|
| 93 |
+
the art style; `scripts/generate_dataset.py` imports it so training captions match
|
| 94 |
|
| 95 |
## HuggingFace deployment
|
| 96 |
- Space: `https://huggingface.co/spaces/Goumsss/numzoo`
|
README.md
CHANGED
|
@@ -38,7 +38,7 @@ A mental math app for kids — answer questions, earn cute AI-generated animal i
|
|
| 38 |
|
| 39 |
## Image model
|
| 40 |
|
| 41 |
-
Rewards generated with **FLUX.
|
| 42 |
Images start generating in the background as soon as the quiz begins.
|
| 43 |
|
| 44 |
## Run locally
|
|
@@ -49,8 +49,8 @@ Images start generating in the background as soon as the quiz begins.
|
|
| 49 |
# 1. Install dependencies
|
| 50 |
~/miniforge3/bin/pip install -r requirements.txt
|
| 51 |
|
| 52 |
-
# 2. Accept FLUX.
|
| 53 |
-
# → https://huggingface.co/black-forest-labs/FLUX.
|
| 54 |
# Then log in:
|
| 55 |
hf auth login
|
| 56 |
|
|
|
|
| 38 |
|
| 39 |
## Image model
|
| 40 |
|
| 41 |
+
Rewards generated with **FLUX.2-klein-4B** (4B params, Apache 2.0) via 🤗 Diffusers.
|
| 42 |
Images start generating in the background as soon as the quiz begins.
|
| 43 |
|
| 44 |
## Run locally
|
|
|
|
| 49 |
# 1. Install dependencies
|
| 50 |
~/miniforge3/bin/pip install -r requirements.txt
|
| 51 |
|
| 52 |
+
# 2. Accept FLUX.2-klein-4B license on HuggingFace
|
| 53 |
+
# → https://huggingface.co/black-forest-labs/FLUX.2-klein-4B
|
| 54 |
# Then log in:
|
| 55 |
hf auth login
|
| 56 |
|