sush0401 commited on
Commit
a2ce6f2
·
verified ·
1 Parent(s): 1cc29fa

Detailed judge-facing README with honest badge claims + corrected Field Notes blog

Browse files
Files changed (2) hide show
  1. README.md +154 -292
  2. 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
- Draw a character, upload it, and DoodleBook turns it into a narrated six-page picture book plus a matching printable coloring book.
29
-
30
- The project was built for the Build Small Hackathon 2026. The core idea is to keep the reasoning stack small, use a strong image renderer only where it matters, and make the whole flow feel like a child-facing product instead of a model demo.
31
-
32
- ## What it does
33
-
34
- - Takes a doodle photo from upload or webcam.
35
- - Generates a six-page children's story with a consistent hero.
36
- - Renders six full-color story pages with FLUX.
37
- - Generates narration audio for the whole book.
38
- - Exports a story PDF.
39
- - Generates a matching black-and-white coloring book as a second output.
40
-
41
- ## Current architecture
42
-
43
- There are two runtime modes in this repo.
44
-
45
- ### 1. Local Modal-backed app
46
-
47
- Use [run_modal.py](run_modal.py) for the real end-to-end flow during development.
48
-
49
- - UI: Gradio 5 custom Blocks layout
50
- - Story: local generator by default, optional Modal MiniCPM route
51
- - Images: Modal FLUX pipeline
52
- - TTS: Modal VoxCPM pipeline
53
- - PDFs: local export
54
- - Coloring book: direct FLUX line-art render, with traced fallback
55
-
56
- Start it with:
57
-
58
- ```bash
59
- python run_modal.py
60
- ```
61
-
62
- The default local URL is:
63
-
64
- ```text
65
- http://127.0.0.1:7880
66
- ```
67
-
68
- ### 2. HF Spaces / ZeroGPU-oriented app
69
-
70
- Use [app.py](app.py) for the official Hugging Face Gradio Space target.
71
-
72
- - `app.py` is the Space entrypoint declared in the repo metadata.
73
- - `app_zerogpu.py` is the alternate experimental path kept for local ZeroGPU-focused iteration.
74
-
75
- ## Stack used in the hackathon
76
-
77
- This project deliberately mixes a small-model reasoning stack, a stronger dedicated image renderer, a custom Gradio presentation layer, and remote inference infrastructure that is cheap enough to demo but strong enough to feel like a real product.
78
-
79
- The important distinction is:
80
-
81
- - the app "brain" is small
82
- - the renderer is specialized
83
- - the UX is product-shaped, not notebook-shaped
84
- - the deployment path is built around a Gradio Space front-end
85
-
86
- ### Full stack at a glance
87
-
88
- | Layer | Stack | Role in the product |
89
- |---|---|---|
90
- | Product UI | Gradio 5 Blocks + custom CSS/HTML/JS | Child-facing scrapbook interface, status streaming, downloads |
91
- | Story engine | MiniCPM5-1B + local structured fallback | Writes the six-page narrative and scene plan |
92
- | Image engine | FLUX.2-klein-4B on Modal | Draws consistent full-color pages and dedicated coloring pages |
93
- | Voice engine | VoxCPM2 on Modal | Narrates the full storybook |
94
- | Coloring engine | Direct FLUX line-art pass + cleanup fallback | Produces printable black-and-white pages |
95
- | Export layer | Pillow + FPDF | Builds printable story and coloring PDFs |
96
- | Hosting target | Hugging Face Spaces | Gradio app shell and user entrypoint |
97
- | Remote compute | Modal | GPU execution for heavy image and TTS work |
98
- | Observability | Heartbeat streaming + stage timing in trace panel | Keeps long runs visible and debuggable |
99
-
100
- ### Frontend and product shell
101
-
102
- - Gradio 5
103
- - Custom scrapbook-style UI in [ui/layout.py](ui/layout.py)
104
- - HTML-based book rendering in [book_builder.py](book_builder.py)
105
- - Fixed-position PDF downloads under the status panel
106
- - Streaming progress heartbeats to keep long jobs alive in the browser
107
- - File-backed page rendering instead of giant inline base64 payloads
108
-
109
- ### Story generation stack
110
-
111
- - `openbmb/MiniCPM5-1B`
112
- - Local fast fallback story generator in [services/story.py](services/story.py)
113
- - Optional Modal story worker in [modal_workers/modal_story_gen.py](modal_workers/modal_story_gen.py)
114
-
115
- Why it matters:
116
- - The story model is the small-model "brain" of the app.
117
- - It keeps the narrative stack small and hackathon-aligned.
118
- - The story system outputs both prose and scene prompts, so downstream image generation stays structured.
119
- - The local structured fallback means the Space can still produce a valid book if the remote story path is unavailable.
120
-
121
- ### Image generation stack
122
-
123
- - `black-forest-labs/FLUX.2-klein-4B`
124
- - Modal deployment for image generation in [modal_workers/modal_image_gen.py](modal_workers/modal_image_gen.py)
125
- - Parallel canonical-character plus per-page render flow in [services/images.py](services/images.py)
126
- - One canonical character render from the child doodle, then scene-specific page renders
127
- - Separate direct line-art render path for the coloring book
128
-
129
- Why it matters:
130
- - The app needs high visual quality and character consistency.
131
- - FLUX is used as the renderer, not as the reasoning engine.
132
- - The character consistency pipeline is what makes the book feel authored rather than randomly reimagined on every page.
133
- - The line-art renderer is separate because tracing finished crayon pages produced bad coloring results.
134
-
135
- ### TTS stack
136
-
137
- - `openbmb/VoxCPM2`
138
- - Modal TTS worker in [modal_workers/modal_tts.py](modal_workers/modal_tts.py)
139
- - Service wrapper in [services/tts.py](services/tts.py)
140
- - Parallelized with image generation in the real Modal-backed app
141
-
142
- Why it matters:
143
- - Narration is part of the child-facing experience, not a side feature.
144
- - TTS runs in parallel with image generation in the real local pipeline.
145
- - Overlapping TTS with illustration time reduces total wait without degrading output quality.
146
-
147
- ### Coloring-book stack
148
-
149
- - Direct FLUX line-art rendering for the same scenes
150
- - Cleanup and fallback pipeline in [services/coloring.py](services/coloring.py)
151
- - Modal `render_coloring_page` for dedicated line-art scene generation
152
- - Local cleanup for thresholding, despeckling, and printable black-on-white output
153
-
154
- Why it matters:
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*