ASTRALK commited on
Commit
e37f88a
Β·
verified Β·
1 Parent(s): 730ea2d

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +250 -9
README.md CHANGED
@@ -1,14 +1,255 @@
1
  ---
2
- title: Comicx
3
- emoji: πŸ“ˆ
4
- colorFrom: blue
5
- colorTo: red
6
  sdk: gradio
7
- sdk_version: 6.18.0
8
- python_version: '3.12'
9
  app_file: app.py
10
- pinned: false
11
- license: mit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  ---
13
 
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: AI Comic Studio
3
+ emoji: 🎬
4
+ colorFrom: red
5
+ colorTo: yellow
6
  sdk: gradio
7
+ sdk_version: "6.18.0"
 
8
  app_file: app.py
9
+ pinned: true
10
+ license: apache-2.0
11
+ short_description: Full comic book generated live β€” Gemma writes, FLUX draws.
12
+ tags:
13
+ - thousand-token-wood
14
+ - off-brand
15
+ - best-agent
16
+ - best-demo
17
+ - modal
18
+ - track:thousand-token-wood
19
+ - sponsor:modal
20
+ - achievement:offbrand
21
+ - achievement:sharing
22
+ - achievement:fieldnotes
23
+ models:
24
+ - google/gemma-4-26B-A4B-it
25
+ - black-forest-labs/FLUX.2-klein-9B
26
+ datasets: []
27
  ---
28
 
29
+ <!--
30
+ AI Comic Studio β€” Build Small Hackathon 2026
31
+ Thousand Token Wood track Β· Best Use of Modal Β· Off Brand badge
32
+ -->
33
+
34
+ <div align="center">
35
+
36
+ # 🎬 AI Comic Studio
37
+
38
+ ### *Type an idea. Get a full comic book β€” written and illustrated live.*
39
+
40
+ **A two-model AI pipeline that generates a complete 25-page, 50-panel comic book in about a minute β€” Gemma 4 writes the story, FLUX.2 paints every panel, and you watch it happen in real time.**
41
+
42
+ </div>
43
+
44
+ ---
45
+
46
+ ## The Idea
47
+
48
+ Most AI image generators spit out one panel. AI Comic Studio generates an entire comic book β€” story bible, fixed cast with consistent character designs, 25 pages of narrative arc, and 50 illustrated panels β€” from a single sentence. The whole thing runs live on screen with a ticking stopwatch so you can see exactly how fast two small models can work together.
49
+
50
+ ---
51
+
52
+ ## What It Does
53
+
54
+ 1. **You type a story idea** β€” "A lighthouse keeper guards a secret" or "Space-pirate noodle shop"
55
+ 2. **Gemma 4 26B-A4B** (the writer) does three things in sequence:
56
+ - **Safety gate** β€” refuses only genuinely harmful requests; fictional adventure, action, mystery, horror are all allowed
57
+ - **Story bible** β€” title, logline, a fixed cast with detailed visual descriptions (reused in every panel for consistency), art style, palette, and a 25-page synopsis
58
+ - **Panel script** β€” 5 batches of 5 pages each, each batch fed a recap of the story so far for continuity
59
+ 3. **FLUX.2 Klein 9B** (the artist) renders every panel β€” character appearance text from the bible is injected into every prompt to keep Elias and his lantern looking the same from panel 1 to panel 50
60
+ 4. **The Gradio reader** shows the finished comic β€” two image+caption panels per page, with ← β†’ navigation
61
+
62
+ ---
63
+
64
+ ## The Two-Model Pipeline
65
+
66
+ ```
67
+ "Type an idea"
68
+ β”‚
69
+ β–Ό
70
+ Gemma 4 26B-A4B (Writer) FLUX.2 Klein 9B (Artist)
71
+ β”œβ”€ Safety gate β”œβ”€ Character injection
72
+ β”œβ”€ Story bible (title, cast, β”œβ”€ Deterministic seeds
73
+ β”‚ art style, 25-page synopsis) β”œβ”€ 832Γ—576 landscape panels
74
+ └─ 50 panels in 5 batches └─ Batched GPU renders
75
+ β”‚ β”‚
76
+ β–Ό β–Ό
77
+ 25-page comic book reader
78
+ (Gradio Β· live timer Β· page nav)
79
+ ```
80
+
81
+ Both models run on **Modal** (H100 GPUs, scale-to-zero with `min_containers=1` for live demos). The Gradio frontend runs on Hugging Face Spaces (CPU).
82
+
83
+ ---
84
+
85
+ ## Model Details
86
+
87
+ | Model | Role | Parameters | Runtime |
88
+ |-------|------|-----------|---------|
89
+ | `google/gemma-4-26B-A4B-it` | Writer (text only) | 26B total (4B active MoE) | vLLM on Modal H100 |
90
+ | `black-forest-labs/FLUX.2-klein-9B` | Artist (images only) | 9B | Diffusers on Modal H100 |
91
+
92
+ Both models are under the 32B parameter cap. Gemma handles ALL text; FLUX handles ALL images. Neither model does the other's job.
93
+
94
+ ---
95
+
96
+ ## Character Consistency
97
+
98
+ The hard part of a 50-panel comic is keeping characters looking the same. AI Comic Studio solves this with **verbatim appearance injection**: each character gets a detailed visual description in the story bible (species/build, age, hair, face, signature clothing, colors, props β€” ~30 words), and that exact text is injected into every FLUX prompt where the character appears. Combined with deterministic seeds per panel, this keeps the art consistent across the full comic.
99
+
100
+ ---
101
+
102
+ ## Custom UI
103
+
104
+ This is not a stock Gradio app. Every element is hand-crafted:
105
+
106
+ - **Comic book landing page** β€” halftone dot background, Anton typography, hard ink shadows, paper texture
107
+ - **Live ticking stopwatch** β€” `gr.Timer` at 100ms intervals, red while generating, green when done
108
+ - **Panel-by-panel streaming** β€” each finished panel appears as a live thumbnail during generation
109
+ - **Full comic reader** β€” two image+caption panels per page, page navigation, title card with logline
110
+ - **Comic sticker buttons** β€” example chips and nav buttons with 3D press effects
111
+
112
+ No `gr.Chatbot`, no `gr.Markdown` in the main flow β€” everything is `gr.HTML` with handwritten CSS.
113
+
114
+ ---
115
+
116
+ ## Modal β€” Where the GPUs Live
117
+
118
+ Modal powers both model backends:
119
+
120
+ | Component | Modal Config | Purpose |
121
+ |-----------|-------------|---------|
122
+ | `comic-gemma` | vLLM, H100, `min_containers=1` | Gemma 4 writer endpoint |
123
+ | `comic-flux` | Diffusers, H100, `min_containers=1` | FLUX.2 Klein renderer |
124
+
125
+ **Why Modal:**
126
+ - Scale-to-zero when not in use (no idle GPU costs)
127
+ - `min_containers=1` keeps one container hot for live demos (no cold boot mid-recording)
128
+ - H100 GPUs for fast inference (~1-2s per panel when warm)
129
+ - `scaledown_window=5min` survives between generation steps
130
+
131
+ **Cost guard:** `modal app stop comic-gemma && modal app stop comic-flux` when done.
132
+
133
+ ---
134
+
135
+ ## Running Locally
136
+
137
+ ```bash
138
+ git clone https://huggingface.co/spaces/ASTRALK/comic-book-generator
139
+ cd comic-book-generator
140
+ pip install -r requirements.txt
141
+
142
+ # Mock mode (no GPU, offline, full UI):
143
+ COMIC_BACKEND=mock python app.py
144
+
145
+ # Live mode (requires Modal deployment):
146
+ COMIC_BACKEND=modal python app.py
147
+ ```
148
+
149
+ ### Deploying the Modal backends
150
+
151
+ ```bash
152
+ pip install modal
153
+
154
+ # Cache Gemma weights (one-time, ~52GB):
155
+ PYTHONIOENCODING=utf-8 modal run serve/serve_gemma.py::download
156
+
157
+ # Deploy both backends:
158
+ PYTHONIOENCODING=utf-8 modal deploy serve/serve_gemma.py
159
+ PYTHONIOENCODING=utf-8 modal deploy serve/serve_flux.py
160
+
161
+ # Set environment:
162
+ export COMIC_BACKEND=modal
163
+ export COMIC_GEMMA_URL=https://<your-workspace>--comic-gemma-serve.modal.run/v1
164
+ export COMIC_GEMMA_MODEL=gemma-comic
165
+ ```
166
+
167
+ ---
168
+
169
+ ## Architecture
170
+
171
+ ```
172
+ HF Space (CPU, Gradio)
173
+ β”‚
174
+ β”‚ OpenAI client β†’ /v1/chat/completions
175
+ β–Ό
176
+ Modal: comic-gemma (H100)
177
+ β”‚ vLLM Β· Gemma 4 26B-A4B Β· text only
178
+ β–Ό
179
+ Panel scripts (scene + caption)
180
+ β”‚
181
+ β”‚ modal.Cls β†’ render_batch()
182
+ β–Ό
183
+ Modal: comic-flux (H100)
184
+ β”‚ Diffusers Β· FLUX.2 Klein 9B Β· images only
185
+ β–Ό
186
+ 50 JPEG panels β†’ Gradio comic reader
187
+ ```
188
+
189
+ ---
190
+
191
+ ## Tech Stack
192
+
193
+ | Layer | Technology |
194
+ |-------|-----------|
195
+ | Writer model | Google Gemma 4 26B-A4B (MoE, 4B active) |
196
+ | Artist model | Black Forest Labs FLUX.2 Klein 9B |
197
+ | Writer runtime | vLLM on Modal (H100) |
198
+ | Artist runtime | Diffusers on Modal (H100) |
199
+ | Frontend | Gradio 6 β€” fully custom HTML/CSS/JS |
200
+ | Character consistency | Verbatim appearance injection + deterministic seeds |
201
+ | JSON parsing | Robust extractor (strips thinking, fences, prose) |
202
+
203
+ ---
204
+
205
+ ## Badges Claimed
206
+
207
+ | Badge | Why |
208
+ |-------|-----|
209
+ | 🎨 **Off Brand** | Fully custom UI β€” no default Gradio chrome in the main interface. Halftone dots, paper texture, Anton typography, comic sticker buttons, 3D press effects. |
210
+ | πŸ€– **Best Agent** | Multi-step pipeline: safety gate β†’ story bible β†’ 5-batch panel scripting β†’ 50 image renders, all with continuity tracking and character consistency. |
211
+ | 🎬 **Best Demo** | Live timer, panel-by-panel streaming, full comic reader with page nav. *(Demo video coming soon)* |
212
+ | ⚑ **Modal** | Both model backends run on Modal β€” vLLM for Gemma, Diffusers for FLUX, scale-to-zero with min_containers=1 for live demos. |
213
+ | πŸ“‘ **Sharing is Caring** | Agent trace published alongside the Space. *(Trace coming soon)* |
214
+ | πŸ““ **Field Notes** | Blog post about building a 50-panel comic pipeline with two small models. *(Write-up coming soon)* |
215
+
216
+ ---
217
+
218
+ ## Demo Video
219
+
220
+ > πŸ“Ή *Demo video coming soon*
221
+
222
+ The demo will show:
223
+ 1. Typing a story idea
224
+ 2. Gemma writing the story bible live
225
+ 3. FLUX rendering panels one by one
226
+ 4. The live stopwatch ticking
227
+ 5. The finished 25-page comic with page navigation
228
+
229
+ ---
230
+
231
+ ## Social Post
232
+
233
+ > 🐦 *Social post link coming soon*
234
+
235
+ ---
236
+
237
+ ## Run Time
238
+
239
+ A warm generation (both GPUs pre-warmed) takes approximately **60-90 seconds** for the full 25-page, 50-panel comic. Cold start adds ~1-3 minutes for container spin-up.
240
+
241
+ ---
242
+
243
+ ## License
244
+
245
+ Apache 2.0
246
+
247
+ ---
248
+
249
+ <div align="center">
250
+
251
+ **AI Comic Studio Β· Build Small Hackathon 2026 Β· Thousand Token Wood**
252
+
253
+ *Gemma 4 26B Β· FLUX.2 Klein 9B Β· Modal Β· Gradio Β· 25 Pages Β· 50 Panels*
254
+
255
+ </div>