The Inspiration

Every parent knows the feeling. It is 7:42 PM. You have read Goodnight Moon for the forty-third time. Your toddler knows every word. The spine is held together by love and tape.

Then your child looks up and says: "Mommy, can we make a story about a penguin who wants to fly?"

That question is pure magic. But turning it into a real, illustrated, narrated storybook — in minutes — has always been impossible. Until now.

Imaginate exists to answer that question. One prompt. A complete storybook with illustrations, narration, and exports. No design skills. No writing. No recording. Just imagination.


What It Does

Imaginate turns a single sentence into a complete, professional storybook:

  1. Script Generation — Qwen3.7-max writes a complete story with 8-10 scenes, character bible, and narrative arc
  2. Character References — Qwen Image 2.0 Pro generates reference images for each character
  3. Scene Illustrations — Each scene gets a full-color illustration with character consistency
  4. Narration — Qwen3-tts-instruct-flash voices every page with natural English narration
  5. Export — Download as interactive HTML, printable PDF, or Kindle-compatible EPUB

How I Built It

Architecture

The system is a 6-phase sequential pipeline:

User Prompt → Script Generator → Character References → Scene Illustrations → Narration → Export

Each phase writes its output to disk as JSON, so the pipeline can resume from any completed phase.

Tech Stack

Component Technology
Frontend Vanilla HTML/CSS/JS
Backend Python 3.12, FastAPI
LLM Qwen3.7-max
Image Gen Qwen Image 2.0 Pro
TTS Qwen3-tts-instruct-flash
PDF weasyprint
EPUB ebooklib
Deployment Alibaba Cloud

The Challenges

Challenge 1: Image Reference Rejection

The workspace multimodal endpoint rejects reference images alongside text prompts. Every time we tried passing a character reference image, we got HTTP 400.

Fix: Embedded character appearance descriptions from the bible directly into each scene's text prompt. Character consistency is maintained through detailed visual descriptions — no reference images needed.

Challenge 2: Rate Limiting

The Token Plan endpoint throttles at roughly 4 images per minute. With 10 scenes and 3 character references, that is 13 image generations. Without rate limiting, we got constant HTTP 429 errors.

Fix: Added a 15-second mandatory delay between image calls, plus exponential backoff on 429 responses (3x normal backoff). The pipeline takes longer but completes reliably.

Challenge 3: TTS Endpoint Discovery

The CosyVoice v3-plus model required WebSocket access that our account did not support via HTTP. We tried the dashscope-intl endpoint (404), the native API (400), and the OpenAI-compatible audio endpoint (404).

Fix: After listing all available models, we discovered qwen3-tts-instruct-flash works perfectly through the multimodal-generation endpoint — the same one used for images. It returns an audio URL in output.audio.url.

Challenge 4: DNS Intermittency

From our environment, the dashscope-intl domain randomly failed DNS resolution. Python's requests library threw getaddrinfo failed errors even though curl worked fine.

Fix: Added download retries (3 attempts with 5s backoff) to both image and audio download functions. Transient failures now resolve automatically.


What I Learned

  1. Qwen Cloud's OpenAI-compatible SDK makes migration trivial — just change the base_url
  2. Character consistency through text is viable with a detailed visual bible
  3. Rate limiting is your friend on shared API plans — build it in from day one
  4. Alibaba Cloud's Token Plan gives full model access for a fixed monthly cost
  5. Build for resume — failed API calls mid-pipeline should not waste prior progress

Built With

Share this project:

Updates