File size: 8,590 Bytes
a2ce6f2 3375ac7 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 0df3422 8d51e7b 0df3422 a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b ef904db 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 8d51e7b a2ce6f2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 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 82 83 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | ---
title: DoodleBook
emoji: π
colorFrom: red
colorTo: yellow
sdk: gradio
sdk_version: "6.18.0"
app_file: app.py
pinned: false
license: apache-2.0
tags:
- hackathon
- build-small
- adventure-in-thousand-token-wood
- gradio
- flux
- minicpm
- voxcpm
- storybook
- coloring-book
- voice-cloning
- children
models:
- black-forest-labs/FLUX.2-klein-4B
- openbmb/MiniCPM5-1B
- openbmb/VoxCPM2
---
# DoodleBook πποΈ
**A child draws a character β DoodleBook turns it into a narrated, illustrated crayon storybook *and* a matching printable coloring book β with their own voice if they want.**
Built for the **Build Small Hackathon 2026 Β· Adventure in Thousand Token Wood**. Every model is under 32B; the reasoning stack (story + voice) is just ~3B.
> 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 6β10 pages.
---
## β
Pre-flight Checklist
| Requirement | Status | Notes |
|---|---|---|
| **Stay under 32B** | β
| MiniCPM5-1B (1B) + VoxCPM2 (2B) + FLUX.2-klein-4B (4B) = **7B total** |
| **Ship a Gradio app** | β
| Gradio 6 Space in the Build Small org |
| **Record a demo** | πΉ | *(link to be added)* |
| **Post on social media** | π¦ | *(link to be added)* |
| **GPU limit (β€10 ZeroGPU)** | β
| 1 ZeroGPU Space |
---
## π Links
| | |
|---|---|
| π **Live Space** | [huggingface.co/spaces/build-small-hackathon/DoodleBook](https://huggingface.co/spaces/build-small-hackathon/DoodleBook) |
| π¬ **Field Notes** (technical deep-dive) | [docs/blog.md](docs/blog.md) |
| π» **Source code** | [github.com/Sushruths04/Doodle-book](https://github.com/Sushruths04/Doodle-book) |
| π€ **MiniCPM5-1B** | [huggingface.co/openbmb/MiniCPM5-1B](https://huggingface.co/openbmb/MiniCPM5-1B) |
| π **VoxCPM2** | [huggingface.co/openbmb/VoxCPM2](https://huggingface.co/openbmb/VoxCPM2) |
| π¨ **FLUX.2-klein-4B** | [huggingface.co/black-forest-labs/FLUX.2-klein-4B](https://huggingface.co/black-forest-labs/FLUX.2-klein-4B) |
---
## β¨ What it does
1. **Draw & upload** a character (upload or webcam snap).
2. **Story** β MiniCPM5-1B writes a complete 6β10-page story with a consistent hero and a real emotional arc.
3. **Illustrations** β FLUX.2-klein renders each page where **your character stays consistent** across all pages (built from *your* drawing via img2img).
4. **Narration** β VoxCPM2 reads the whole book aloud in the child's choice of voice β kid, storyteller, grandpa, or **their own cloned voice** (record 5β60 s).
5. **Coloring book** β a matching black-and-white line-art version to print and color.
6. **Downloads** β one-tap **Story PDF** and **Coloring PDF** (works on mobile too).
### What makes a story good
DoodleBook uses a structured prompting system to guarantee quality:
- **Few-shot exemplar**: A full 6-page story is shown as a gold example so MiniCPM learns the exact format and richness required.
- **Story arc rules**: Pages 1β2 introduce the hero and challenge; middle pages build it; final pages resolve and teach a clear lesson.
- **2β3 rich sentences per page**: Every page uses sensory detail β colours, sounds, textures, feelings β not just plot.
- **10 diverse themes** covering kindness, imagination, friendship, courage, identity, and adventure.
- **Continuity rules**: Each page flows from the one before β the story reads as one coherent arc, not isolated scenes.
- **Variable page count (6β10)**: More pages = longer story and longer narration.
---
## π§ Models & the "Tiny Titan" argument
| Role | Model | Params | Sponsor | What it does |
|---|---|---|---|---|
| π Story writer | `openbmb/MiniCPM5-1B` | **1B** | **OpenBMB** | Writes the full story as structured JSON β title, character description, per-page text and scene descriptions |
| π Voice narrator | `openbmb/VoxCPM2` | **2B** | **OpenBMB** | Reads the story aloud with voice design prefixes; optionally clones the user's own voice via reference audio |
| π¨ Illustrator | `black-forest-labs/FLUX.2-klein-4B` | **4B** | **Black Forest Labs** | Renders each page + the coloring line-art as FLUX img2img; keeps the child's drawn character consistent |
**Total parameter count: 7B.** Each individual model is well below the 32B cap.
**The product's reasoning is a ~3B small-model stack.** MiniCPM5-1B writes the narrative and scene plans; VoxCPM2 performs it. FLUX is not the "intelligence" β it's the renderer. That's the Tiny Titan story: the small models drive the experience.
---
## ποΈ Voice Cloning β the "My Voice" option
When a parent selects **"ποΈ My Voice"**, they record 5β60 seconds of clear speech. VoxCPM2 uses this as a `reference_wav_path` to clone the voice and narrate the book in it β so children hear their parent's actual voice reading their story, even on demand.
The reference audio is processed locally (never stored). Sentences are capped at 15 for the ZeroGPU budget.
---
## π¨ Cross-page character consistency
Generate pages independently and you get six different characters. DoodleBook keeps **one** hero β *the one the child drew* β with **no per-user training**:
1. **Canonical-character pass** β the doodle goes through FLUX **img2img once** to produce a clean "model-sheet" hero.
2. **Every page is conditioned on that canonical image**, so the same creature appears in every scene.
3. **Seed-locking** (deterministic per page) + a **fixed character description** anchor identity.
A cat doodle becomes a cat hero across all pages. Full write-up: **[Field Notes β](docs/blog.md)**.
---
## ποΈ Coloring book: redraw, don't trace
Tracing finished crayon pages turned textures into speckle. Instead, DoodleBook passes each color page back to FLUX as img2img with a *"clean coloring-book line art"* prompt β it **redraws** clean outlines, then a local pass crisps them to pure black-on-white.
---
## π Open Trace β every book is reproducible
Open **"Behind the magic β Trace"** on any generated book:
- locked **seed** (same inputs β same book)
- per-page prompts and scene plan
- exact **model IDs** and stage timings
- fallback reasons (surfaced, never silent)
---
## ποΈ Architecture
| Layer | What | File |
|---|---|---|
| Product UI | Custom scrapbook Gradio 6 Blocks | [`ui/layout.py`](ui/layout.py) |
| Book / PDF | HTML book + printable PDFs | [`book_builder.py`](book_builder.py) |
| Story | MiniCPM5-1B + deterministic arc fallback | [`app.py`](app.py) |
| Images | FLUX.2-klein canonical + per-page img2img | [`app.py`](app.py) |
| Voice | VoxCPM2 narration (parallel) + voice cloning | [`app.py`](app.py) |
| Coloring | FLUX line art + crisp/threshold cleanup | [`services/coloring.py`](services/coloring.py) |
| Config | Models, seeds, voices, palette | [`config.py`](config.py) |
### How it runs (ZeroGPU)
- **Gradio 6** Space, **ZeroGPU** hardware β free T4 GPU per request.
- All three models load **on CUDA at module scope** (ZeroGPU pattern); each stage is a `@spaces.GPU` call.
- Narration runs **in parallel** with illustration and surfaces the moment it's ready.
- A real, pre-generated **sample book loads instantly** on open β no GPU required.
---
## π
Hackathon badges
| Badge | Status | Evidence |
|---|---|---|
| **Off-Brand** | β
| Fully custom scrapbook UI β Gaegu/Caveat fonts, paper textures, hand-drawn SVG frames, light-locked. Zero Gradio defaults. See [`ui/layout.py`](ui/layout.py). |
| **Open Trace** | β
| Every book exposes seed, per-page prompts, model IDs, and timings in the in-app Trace panel. |
| **Field Notes** | β
| Engineering write-up on cross-page consistency: **[docs/blog.md](docs/blog.md)**. |
| **Tiny Titan** | β
| MiniCPM5-1B + VoxCPM2 β **3B reasoning stack**; FLUX is the renderer. |
| **Sponsor β OpenBMB** | β
| `MiniCPM5-1B` writes every story; `VoxCPM2` narrates and clones voices. |
| **Sponsor β Black Forest Labs** | β
| `FLUX.2-klein-4B` renders every page illustration and coloring line art. |
---
## βΆοΈ Run locally
```bash
pip install -r requirements.txt
python app.py
```
The example doodle (`assets/sample_doodle.jpg`) and the instant sample book are included.
---
## π€ Sponsor & tool stack
- **OpenBMB** β MiniCPM5-1B (story) + VoxCPM2 (voice + cloning)
- **Black Forest Labs** β FLUX.2-klein-4B (illustration + line art)
- **Hugging Face Spaces / ZeroGPU** β hosting + GPU
- **Gradio 6** β the product shell
---
## License
Apache-2.0. See [LICENSE](LICENSE).
|