Detailed judge-facing README with honest badge claims + corrected Field Notes blog
Browse files- README.md +154 -292
- docs/blog.md +103 -0
README.md
CHANGED
|
@@ -1,292 +1,154 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: DoodleBook
|
| 3 |
-
emoji: 📚
|
| 4 |
-
colorFrom: yellow
|
| 5 |
-
colorTo: red
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version: "6.18.0"
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
tags:
|
| 11 |
-
- hackathon
|
| 12 |
-
- build-small
|
| 13 |
-
- adventure-in-thousand-token-wood
|
| 14 |
-
- gradio
|
| 15 |
-
- flux
|
| 16 |
-
- minicpm
|
| 17 |
-
- voxcpm
|
| 18 |
-
- storybook
|
| 19 |
-
- coloring-book
|
| 20 |
-
models:
|
| 21 |
-
- black-forest-labs/FLUX.2-klein-4B
|
| 22 |
-
- openbmb/MiniCPM5-1B
|
| 23 |
-
- openbmb/VoxCPM2
|
| 24 |
-
---
|
| 25 |
-
|
| 26 |
-
# DoodleBook
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
-
|
| 51 |
-
-
|
| 52 |
-
|
| 53 |
-
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
- the
|
| 82 |
-
- the
|
| 83 |
-
- the
|
| 84 |
-
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
##
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
-
|
| 106 |
-
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
- The main bug fixed in this version was that the coloring book used to trace finished crayon-textured images.
|
| 156 |
-
- The improved pipeline renders dedicated line-art pages instead of trying to strip color out after the fact.
|
| 157 |
-
- This is the main quality improvement that separates the current version from the earlier broken coloring-book output.
|
| 158 |
-
|
| 159 |
-
### Infrastructure stack
|
| 160 |
-
|
| 161 |
-
- Modal for remote GPU inference
|
| 162 |
-
- Hugging Face Spaces as the target host
|
| 163 |
-
- Python 3.11 / 3.13 local development
|
| 164 |
-
- `diffusers`, `transformers`, `torch`, `accelerate`
|
| 165 |
-
- `Pillow`, `OpenCV`, `FPDF`
|
| 166 |
-
- Gradio client-compatible API surface for testing and debugging
|
| 167 |
-
- Hugging Face org deployment target: `build-small-hackathon`
|
| 168 |
-
|
| 169 |
-
### Sponsor and hackathon alignment
|
| 170 |
-
|
| 171 |
-
This app directly reflects the hackathon sponsor/tool stack:
|
| 172 |
-
|
| 173 |
-
- `OpenBMB`: MiniCPM5-1B and VoxCPM2
|
| 174 |
-
- `Black Forest Labs`: FLUX.2-klein-4B
|
| 175 |
-
- `Modal`: remote GPU inference
|
| 176 |
-
- `OpenAI Codex`: debugging, architecture fixes, deployment preparation, README/release work
|
| 177 |
-
- `Hugging Face Spaces`: final Gradio app surface
|
| 178 |
-
|
| 179 |
-
For hackathon judging, the main narrative is:
|
| 180 |
-
|
| 181 |
-
- Tiny Titan reasoning stack
|
| 182 |
-
- Off-brand custom UI
|
| 183 |
-
- Real multimodal product loop
|
| 184 |
-
- Remote GPU orchestration with a Gradio user experience
|
| 185 |
-
- Child-usable output artifacts: storybook PDF, audio, coloring book PDF
|
| 186 |
-
|
| 187 |
-
## Key engineering fixes in this version
|
| 188 |
-
|
| 189 |
-
- Added direct Modal coloring-page rendering with `render_coloring_page`.
|
| 190 |
-
- Fixed the live app to keep the Gradio stream alive during long coloring generation.
|
| 191 |
-
- Added stage timing so story, image, PDF, TTS, and coloring costs are visible.
|
| 192 |
-
- Reduced final-page payload size by replacing giant inline base64 book HTML with file-backed image URLs.
|
| 193 |
-
- Fixed download serving through Gradio temp-file paths.
|
| 194 |
-
- Removed port confusion between the local test app and the real Modal-backed app.
|
| 195 |
-
|
| 196 |
-
## Measured performance
|
| 197 |
-
|
| 198 |
-
Measured against the real local Modal-backed app flow:
|
| 199 |
-
|
| 200 |
-
- Story-only stage: about `0.3s`
|
| 201 |
-
- Full-color book, warm: about `75s to 80s`
|
| 202 |
-
- Full-color book + coloring book, warm: about `200s`
|
| 203 |
-
- Slowest stage: coloring-book generation
|
| 204 |
-
|
| 205 |
-
The current bottleneck is still the coloring-book path, even after the direct line-art fix.
|
| 206 |
-
|
| 207 |
-
## Repository layout
|
| 208 |
-
|
| 209 |
-
```text
|
| 210 |
-
app.py Main Gradio app variant
|
| 211 |
-
app_zerogpu.py ZeroGPU-oriented app variant
|
| 212 |
-
run_modal.py Real local Modal-backed app
|
| 213 |
-
book_builder.py HTML and PDF assembly
|
| 214 |
-
services/ Orchestration and fallbacks
|
| 215 |
-
modal_workers/ Modal remote workers
|
| 216 |
-
ui/ Custom Gradio layout
|
| 217 |
-
assets/ Sample doodles and sample book pages
|
| 218 |
-
docs/ Specs and notes
|
| 219 |
-
```
|
| 220 |
-
|
| 221 |
-
## Local setup
|
| 222 |
-
|
| 223 |
-
```bash
|
| 224 |
-
pip install -r requirements.txt
|
| 225 |
-
python run_modal.py
|
| 226 |
-
```
|
| 227 |
-
|
| 228 |
-
If you want the real Modal-backed app, use `run_modal.py`, not `app.py`.
|
| 229 |
-
|
| 230 |
-
## Hugging Face Space deployment target
|
| 231 |
-
|
| 232 |
-
The intended hosted version is a Gradio Space in the `build-small-hackathon` org.
|
| 233 |
-
|
| 234 |
-
Target format:
|
| 235 |
-
|
| 236 |
-
```text
|
| 237 |
-
build-small-hackathon/DoodleBook
|
| 238 |
-
```
|
| 239 |
-
|
| 240 |
-
Official target configuration:
|
| 241 |
-
|
| 242 |
-
- Hugging Face Space SDK: `gradio`
|
| 243 |
-
- Space entrypoint: `app.py`
|
| 244 |
-
- Hardware target: `ZeroGPU`
|
| 245 |
-
- Space frontend and API live on Hugging Face
|
| 246 |
-
- Local or Spaces-managed inference path should be preferred for the official org deployment
|
| 247 |
-
|
| 248 |
-
Important distinction:
|
| 249 |
-
|
| 250 |
-
- `run_modal.py` is the best local development and debugging path.
|
| 251 |
-
- `app.py` is the correct Hugging Face Space entrypoint.
|
| 252 |
-
- Do not point the Space metadata at `run_modal.py`, because that is the Modal-backed dev runtime rather than the official hosted Gradio runtime.
|
| 253 |
-
|
| 254 |
-
If you choose the Modal-backed hosted variant later, that becomes a different deployment shape and requires secrets.
|
| 255 |
-
|
| 256 |
-
Required secrets only for the Modal-backed hosted variant:
|
| 257 |
-
|
| 258 |
-
- `MODAL_TOKEN_ID`
|
| 259 |
-
- `MODAL_TOKEN_SECRET`
|
| 260 |
-
- any Hugging Face token needed by Modal workers for model pulls
|
| 261 |
-
|
| 262 |
-
Why the Gradio Space + ZeroGPU shape is preferred for the hackathon org:
|
| 263 |
-
|
| 264 |
-
- keeps the user-facing app as a normal Gradio Space
|
| 265 |
-
- matches the official hackathon org publishing model
|
| 266 |
-
- keeps the demo easy to judge, share, and run from the org page
|
| 267 |
-
- avoids depending on a separate private frontend host
|
| 268 |
-
|
| 269 |
-
Tradeoff:
|
| 270 |
-
|
| 271 |
-
- The pure ZeroGPU path is easier to host in the official org.
|
| 272 |
-
- The Modal-backed path currently gives stronger image and TTS quality.
|
| 273 |
-
- The repo keeps both because local quality validation and official hosting have different constraints.
|
| 274 |
-
|
| 275 |
-
## Hackathon fit
|
| 276 |
-
|
| 277 |
-
This project targets the hackathon stack in a deliberate way:
|
| 278 |
-
|
| 279 |
-
- Small-model reasoning for story generation
|
| 280 |
-
- Strong but scoped rendering model for visuals
|
| 281 |
-
- Distinct multimodal outputs: story, illustrations, narration, coloring book
|
| 282 |
-
- Real product UX instead of a bare prompt box
|
| 283 |
-
- Clear deployment story for Hugging Face Spaces plus Modal GPU workers
|
| 284 |
-
|
| 285 |
-
## Contributors
|
| 286 |
-
|
| 287 |
-
- Sushruth S.
|
| 288 |
-
- OpenAI Codex: debugging, architecture fixes, rendering pipeline fixes, README and release preparation
|
| 289 |
-
|
| 290 |
-
## License
|
| 291 |
-
|
| 292 |
-
Apache-2.0. See [LICENSE](LICENSE).
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: DoodleBook
|
| 3 |
+
emoji: 📚
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: red
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: "6.18.0"
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
tags:
|
| 11 |
+
- hackathon
|
| 12 |
+
- build-small
|
| 13 |
+
- adventure-in-thousand-token-wood
|
| 14 |
+
- gradio
|
| 15 |
+
- flux
|
| 16 |
+
- minicpm
|
| 17 |
+
- voxcpm
|
| 18 |
+
- storybook
|
| 19 |
+
- coloring-book
|
| 20 |
+
models:
|
| 21 |
+
- black-forest-labs/FLUX.2-klein-4B
|
| 22 |
+
- openbmb/MiniCPM5-1B
|
| 23 |
+
- openbmb/VoxCPM2
|
| 24 |
+
---
|
| 25 |
+
|
| 26 |
+
# DoodleBook 📚🖍️
|
| 27 |
+
|
| 28 |
+
**A child draws a character → DoodleBook turns it into a narrated, hand-drawn crayon storybook *and* a matching printable coloring book.**
|
| 29 |
+
|
| 30 |
+
Built for the **Build Small Hackathon 2026 · Adventure in Thousand Token Wood**. The bet: keep the *reasoning* brain tiny (a ~3B small-model stack writes and narrates the story), use a strong image model only as the *renderer*, and wrap it all in a UI that feels like a children's product — not a model demo.
|
| 31 |
+
|
| 32 |
+
> Open the Space and a real sample book loads instantly. Then draw your own character, upload it, and watch your hero come to life across six pages.
|
| 33 |
+
|
| 34 |
+
---
|
| 35 |
+
|
| 36 |
+
## ✨ What it does
|
| 37 |
+
|
| 38 |
+
1. **Draw & upload** a character (upload or webcam).
|
| 39 |
+
2. **Story** — a small model writes a complete six-page story with a consistent hero.
|
| 40 |
+
3. **Illustrations** — FLUX renders six crayon pages where **your character stays the same on every page** (it's built from *your* drawing).
|
| 41 |
+
4. **Narration** — the whole book is read aloud in a child-friendly voice.
|
| 42 |
+
5. **Coloring book** — a matching black-and-white line-art version to print and color.
|
| 43 |
+
6. **Downloads** — one-tap **Story PDF** and **Coloring PDF** (works on mobile too).
|
| 44 |
+
|
| 45 |
+
---
|
| 46 |
+
|
| 47 |
+
## 🧠 Models & the "Tiny Titan" argument
|
| 48 |
+
|
| 49 |
+
| Role | Model | Size | Sponsor |
|
| 50 |
+
|---|---|---|---|
|
| 51 |
+
| 📖 Story (the brain) | `openbmb/MiniCPM5-1B` | **1B** | OpenBMB |
|
| 52 |
+
| 🔊 Narration (the brain) | `openbmb/VoxCPM2` | **2B** | OpenBMB |
|
| 53 |
+
| 🎨 Illustration (the printer) | `black-forest-labs/FLUX.2-klein-4B` | 4B | Black Forest Labs |
|
| 54 |
+
|
| 55 |
+
**The product's *reasoning* is a ~3B small-model stack.** MiniCPM5-1B authors the narrative and per-page scene plan; VoxCPM2 performs it. FLUX is not the "intelligence" — it's the renderer that prints what the small models decided. That's the Tiny Titan story: the small models drive the experience.
|
| 56 |
+
|
| 57 |
+
---
|
| 58 |
+
|
| 59 |
+
## 🎨 The hard part: cross-page character consistency
|
| 60 |
+
|
| 61 |
+
Generate six pages independently and you get six different characters. DoodleBook keeps **one** hero — *the one the child drew* — with **no per-user training**:
|
| 62 |
+
|
| 63 |
+
1. **Canonical-character pass** — the doodle is sent through FLUX **img2img once** to become a single clean "model-sheet" hero.
|
| 64 |
+
2. **Every page is conditioned on that canonical image**, so the same creature appears in each scene.
|
| 65 |
+
3. **Seed-locking** (deterministic per page) + a **fixed character description** anchor identity and reproducibility.
|
| 66 |
+
|
| 67 |
+
Identity comes from the child's drawing, carried by image conditioning — a cat doodle becomes a cat hero, a robot becomes a robot. Full write-up in **[Field Notes →](docs/blog.md)**.
|
| 68 |
+
|
| 69 |
+
---
|
| 70 |
+
|
| 71 |
+
## 🖍️ Coloring book: redraw, don't trace
|
| 72 |
+
|
| 73 |
+
Tracing finished crayon pages turned textured backgrounds into speckle. Instead, DoodleBook hands each color page back to FLUX as img2img with a *"clean coloring-book line art"* prompt — it **redraws** clean, colorable outlines that match the story page, then a tiny local pass crisps them to pure black-on-white.
|
| 74 |
+
|
| 75 |
+
---
|
| 76 |
+
|
| 77 |
+
## 🔍 Open Trace — every book is reproducible
|
| 78 |
+
|
| 79 |
+
Open **"Behind the magic → Trace"** on any generated book and you get the full, reproducible record:
|
| 80 |
+
|
| 81 |
+
- the locked **seed**
|
| 82 |
+
- the **per-page prompts** and scene plan
|
| 83 |
+
- the exact **model IDs** used
|
| 84 |
+
- **stage timings** (story / images / narration / PDF / coloring)
|
| 85 |
+
- any fallback reasons (surfaced, never silent)
|
| 86 |
+
|
| 87 |
+
Same inputs → same book.
|
| 88 |
+
|
| 89 |
+
---
|
| 90 |
+
|
| 91 |
+
## 🏗️ How it runs (Hugging Face ZeroGPU)
|
| 92 |
+
|
| 93 |
+
- **Gradio 6** Space, **ZeroGPU** hardware. `app.py` is the entrypoint.
|
| 94 |
+
- All three models load **on CUDA at module scope** (the ZeroGPU-recommended pattern); each generation stage is a `@spaces.GPU` call.
|
| 95 |
+
- Narration runs **in parallel** with illustration and is surfaced the moment it's ready.
|
| 96 |
+
- A real, pre-generated **sample book loads instantly** on open (no GPU needed to be impressed).
|
| 97 |
+
|
| 98 |
+
---
|
| 99 |
+
|
| 100 |
+
## 🏅 Hackathon badges
|
| 101 |
+
|
| 102 |
+
We only claim what we can show. Every claim below points to a real, inspectable artifact.
|
| 103 |
+
|
| 104 |
+
| Badge | Status | Evidence |
|
| 105 |
+
|---|---|---|
|
| 106 |
+
| **Off-Brand** | ✅ Claimed | A fully custom scrapbook UI — crayon fonts (Gaegu/Caveat), paper textures, hand-drawn SVG frames, light-locked theme. **Zero Gradio defaults.** See [`ui/layout.py`](ui/layout.py). |
|
| 107 |
+
| **Open Trace** | ✅ Claimed | Every book exposes a full reproducible trace (seed, per-page prompts, model IDs, timings) in the in-app **Trace** panel. |
|
| 108 |
+
| **Field Notes** | ✅ Claimed | Engineering write-up on cross-page character consistency without per-user training: **[docs/blog.md](docs/blog.md)**. |
|
| 109 |
+
| **Tiny Titan** | ✅ Argued | The reasoning stack (MiniCPM5-1B + VoxCPM2 ≈ **3B**) is the product brain; FLUX is the renderer. |
|
| 110 |
+
| **Sponsor — OpenBMB** | ✅ | `MiniCPM5-1B` writes the story; `VoxCPM2` narrates it. |
|
| 111 |
+
| **Sponsor — Black Forest Labs** | ✅ | `FLUX.2-klein-4B` renders every page and the coloring line art. |
|
| 112 |
+
| **Well-Tuned** | 🔜 Roadmap (not claimed) | A crayon-style FLUX LoRA is the planned next step. **No LoRA is trained or published yet**, so we make no Well-Tuned claim — consistency today is achieved by the canonical-character + seed + description stack. |
|
| 113 |
+
|
| 114 |
+
---
|
| 115 |
+
|
| 116 |
+
## 🧩 Architecture (Space)
|
| 117 |
+
|
| 118 |
+
| Layer | What | Where |
|
| 119 |
+
|---|---|---|
|
| 120 |
+
| Product UI | Custom scrapbook Gradio 6 Blocks + CSS/JS | [`ui/layout.py`](ui/layout.py) |
|
| 121 |
+
| Book/PDF assembly | HTML book + printable PDFs | [`book_builder.py`](book_builder.py) |
|
| 122 |
+
| Story | MiniCPM5-1B + deterministic structured fallback | [`app.py`](app.py) |
|
| 123 |
+
| Images | FLUX.2-klein canonical + per-page render | [`app.py`](app.py) |
|
| 124 |
+
| Voice | VoxCPM2 narration (parallel) | [`app.py`](app.py) |
|
| 125 |
+
| Coloring | FLUX img2img line art + crisp/threshold cleanup | [`services/coloring.py`](services/coloring.py) |
|
| 126 |
+
| Config | Models, seeds, voices, palette | [`config.py`](config.py) |
|
| 127 |
+
|
| 128 |
+
> The source repo also includes a **Modal-backed** development path (story/image/voice as deployed Modal functions) used for local quality validation; the hosted Space runs the self-contained ZeroGPU path in `app.py`.
|
| 129 |
+
|
| 130 |
+
---
|
| 131 |
+
|
| 132 |
+
## ▶️ Run locally
|
| 133 |
+
|
| 134 |
+
```bash
|
| 135 |
+
pip install -r requirements.txt
|
| 136 |
+
python app.py
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
The example doodle (`assets/sample_doodle.jpg`) and the instant sample book are included.
|
| 140 |
+
|
| 141 |
+
---
|
| 142 |
+
|
| 143 |
+
## 🤝 Sponsor & tool stack
|
| 144 |
+
|
| 145 |
+
- **OpenBMB** — MiniCPM5-1B (story) + VoxCPM2 (voice)
|
| 146 |
+
- **Black Forest Labs** — FLUX.2-klein-4B (illustration + line art)
|
| 147 |
+
- **Hugging Face Spaces / ZeroGPU** — hosting + GPU
|
| 148 |
+
- **Gradio 6** — the product shell
|
| 149 |
+
|
| 150 |
+
---
|
| 151 |
+
|
| 152 |
+
## License
|
| 153 |
+
|
| 154 |
+
Apache-2.0. See [LICENSE](LICENSE).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docs/blog.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Field Notes: Cross-Page Character Consistency in DoodleBook
|
| 2 |
+
|
| 3 |
+
*How we keep the same hand-drawn hero across all six pages of a storybook — from a single child's doodle, with no per-user training — using FLUX.2-klein, a canonical-character pass, seed-locking, and a fixed character description.*
|
| 4 |
+
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
## The Challenge
|
| 8 |
+
|
| 9 |
+
The core problem in AI-generated storybooks is **character consistency**. Generate six pages independently and you get six different characters — different colors, proportions, and style on every page. The magic is gone.
|
| 10 |
+
|
| 11 |
+
We needed: **the same character, in the same crayon style, across all six pages — and it has to look like the picture the child actually drew.**
|
| 12 |
+
|
| 13 |
+
A tempting answer is "train a LoRA per child." That is infeasible at demo time (LoRA training is minutes-to-hours on a real GPU), so we deliberately did **not** rely on per-user training. Instead, character identity comes from the child's own drawing, carried through the book by image conditioning.
|
| 14 |
+
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
## Our Approach: The Consistency Stack
|
| 18 |
+
|
| 19 |
+
We layer four complementary techniques. None solves it alone; together they're reliable.
|
| 20 |
+
|
| 21 |
+
### 1. The canonical-character pass (the real secret sauce)
|
| 22 |
+
|
| 23 |
+
This is the key idea. We do **two stages**:
|
| 24 |
+
|
| 25 |
+
1. **Stage 1 — build the canonical hero.** The child's doodle is sent through FLUX.2-klein **img2img** once, turning the rough drawing into one clean, full-body crayon character on a plain background. This is the "model sheet" for the whole book.
|
| 26 |
+
2. **Stage 2 — render every page from that canonical.** Each of the six scenes is rendered with the **canonical image itself as the reference** (`image=canonical`), plus the scene description. Because every page is conditioned on the *same* reference image, the hero stays recognizably the same creature the child drew.
|
| 27 |
+
|
| 28 |
+
```python
|
| 29 |
+
canonical = build_canonical(doodle) # doodle -> one clean hero (img2img)
|
| 30 |
+
pages = [render_page(canonical, scene, seed+i) # every page references the SAME hero
|
| 31 |
+
for i, scene in enumerate(scenes)]
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
Identity comes from the **child's drawing**, not from a trained checkpoint — so a cat doodle becomes a cat hero, a robot becomes a robot, with no training step.
|
| 35 |
+
|
| 36 |
+
### 2. Seed locking
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
BASE_SEED = 42
|
| 40 |
+
# page i uses BASE_SEED + i + 1 -> reproducible, slight per-page variation
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
Deterministic seeds make a book reproducible (same inputs → same outputs) while still letting each page differ.
|
| 44 |
+
|
| 45 |
+
### 3. A fixed character description
|
| 46 |
+
|
| 47 |
+
The same `character_description` string is reused on every page as a text anchor (and is the fallback identity when no doodle is uploaded, via text2img).
|
| 48 |
+
|
| 49 |
+
### 4. Style in the prompt
|
| 50 |
+
|
| 51 |
+
A consistent crayon art-style suffix ("hand-drawn crayon storybook illustration, waxy crayon texture…") keeps the medium uniform across pages.
|
| 52 |
+
|
| 53 |
+
---
|
| 54 |
+
|
| 55 |
+
## The Coloring Book: redraw, don't trace
|
| 56 |
+
|
| 57 |
+
A matching coloring book is the second output. Our first attempt **traced** the finished crayon pages with classical edge/region detection — but crayon texture shattered busy backgrounds into speckle, producing pages no child could color.
|
| 58 |
+
|
| 59 |
+
The fix: hand each finished color page back to FLUX as **img2img** with a "clean black-and-white coloring-book line art" prompt. FLUX understands the scene semantically and redraws clean shape outlines that *match* the story page, instead of tracing texture. A tiny local pass then thresholds it to crisp black-on-white.
|
| 60 |
+
|
| 61 |
+
---
|
| 62 |
+
|
| 63 |
+
## Key Learnings
|
| 64 |
+
|
| 65 |
+
1. **Seed alone isn't enough.** Same seed + different prompt still drifts. You need an identity anchor.
|
| 66 |
+
2. **Image conditioning beats per-user training.** Feeding the child's actual drawing (as a canonical reference) gives per-character identity *without* training a LoRA per user — the decisive call for a live demo.
|
| 67 |
+
3. **For line art, redraw beats trace.** Generating coloring pages with a model that understands the scene is far cleaner than stripping color out of a finished texture.
|
| 68 |
+
4. **4B is the right renderer.** FLUX.2-klein-4B runs fast enough for a live book with strong storybook quality.
|
| 69 |
+
|
| 70 |
+
---
|
| 71 |
+
|
| 72 |
+
## Technical Details
|
| 73 |
+
|
| 74 |
+
**Model stack**
|
| 75 |
+
- Image / renderer: `black-forest-labs/FLUX.2-klein-4B`
|
| 76 |
+
- Story / brain: `openbmb/MiniCPM5-1B` (1B)
|
| 77 |
+
- Voice: `openbmb/VoxCPM2` (2B)
|
| 78 |
+
|
| 79 |
+
**Inference (storybook pages)**
|
| 80 |
+
```yaml
|
| 81 |
+
guidance_scale: 1.0
|
| 82 |
+
num_inference_steps: 6
|
| 83 |
+
width: 768
|
| 84 |
+
height: 768
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
**Coloring pages**: FLUX img2img from the color page, `strength≈0.85`, then threshold/despeckle.
|
| 88 |
+
|
| 89 |
+
---
|
| 90 |
+
|
| 91 |
+
## Roadmap: a crayon-style LoRA (not yet trained)
|
| 92 |
+
|
| 93 |
+
A natural next step is a **crayon art-style LoRA** on FLUX.2-klein to make the medium even more uniform and reduce prompt sensitivity. The training pipeline is scaffolded, but **no LoRA has been trained or published yet**, so we make no "Well-Tuned" claim — current consistency is achieved entirely by the canonical-character + seed + description stack above.
|
| 94 |
+
|
| 95 |
+
---
|
| 96 |
+
|
| 97 |
+
## Conclusion
|
| 98 |
+
|
| 99 |
+
Character consistency in AI storybooks doesn't require per-user fine-tuning. A canonical-character pass (drive every page from one img2img render of the child's own drawing), a locked seed, and a fixed description together turn a single crayon doodle into a consistent, narrated, illustrated book — the child's character, their style, brought to life.
|
| 100 |
+
|
| 101 |
+
---
|
| 102 |
+
|
| 103 |
+
*Built for Build Small Hackathon 2026 · Adventure in Thousand Token Wood*
|