Upload FIELD_NOTES.md with huggingface_hub
Browse files- FIELD_NOTES.md +112 -0
FIELD_NOTES.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Field Notes β Building LLM Cinema
|
| 2 |
+
|
| 3 |
+
*A small fine-tuned model that writes, draws, and directs original ASCII films β and plays
|
| 4 |
+
them inline. Built for the Build Small Hackathon.*
|
| 5 |
+
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
## The idea
|
| 9 |
+
|
| 10 |
+
Most "AI video" demos are wrappers around a giant hosted model. We wanted the opposite: a
|
| 11 |
+
**small** model doing something genuinely creative, where the model is *load-bearing* β remove
|
| 12 |
+
it and there's nothing left. So we built **Cinema**, a fine-tuned **MiniCPM3β4B** that, from a
|
| 13 |
+
single sentence, invents an original ~90βsecond film: it writes a beat-by-beat story, casts and
|
| 14 |
+
draws every character in ASCII, picks the terrain, camera, and a feeling per character, then
|
| 15 |
+
stages and plays it frame-by-frame right in the page. No video, no sound β just a small model's
|
| 16 |
+
imagination, streamed.
|
| 17 |
+
|
| 18 |
+
The whole thesis is **small by design**: a 4B model, fine-tuned, is enough to be delightful.
|
| 19 |
+
|
| 20 |
+
---
|
| 21 |
+
|
| 22 |
+
## How it works
|
| 23 |
+
|
| 24 |
+
- **Director (the model).** A concept β a strict-JSON film script: a 9-beat, three-act arc with
|
| 25 |
+
per-shot `narration`, `cast`, `action`, `setting`, `camera`, and `mood`. The model is the
|
| 26 |
+
author, the casting director, and the cinematographer.
|
| 27 |
+
- **Artist (the model again).** Any subject named in a shot is drawn as a small ASCII sprite β
|
| 28 |
+
from a curated library of ~100, or drawn on demand by the model and cached.
|
| 29 |
+
- **Renderer (deterministic).** A Python engine turns the script into frames: textured terrain
|
| 30 |
+
(water shimmers, lava glows, snow), characters that enter and idle, subtitles that type on,
|
| 31 |
+
soft scene dips, a title card and end credits. Everything targets one canonical frame rate so
|
| 32 |
+
the GIF, the web stage, and the terminal player all match.
|
| 33 |
+
- **Stage (the app).** The film streams frame-by-frame into a charcoal, monospace, "cinema"
|
| 34 |
+
UI β left nav shelf, screen on the right β with a Gallery of pre-rendered films that replay
|
| 35 |
+
instantly (no model needed), live "Make a film," ratings, and one-click GIF export.
|
| 36 |
+
|
| 37 |
+
---
|
| 38 |
+
|
| 39 |
+
## What we learned (the engineering, honestly)
|
| 40 |
+
|
| 41 |
+
A surprising amount of the work wasn't the model β it was making a *small model + a streaming UI*
|
| 42 |
+
behave. The most useful lessons:
|
| 43 |
+
|
| 44 |
+
**1. Small models mangle JSON in three different ways.** Across runs our director would
|
| 45 |
+
(a) backslash-escape every inner quote, (b) truncate at the token cap mid-film, and (c) emit a
|
| 46 |
+
field as an array. A single strict `json.loads` failed on all three, so every live film silently
|
| 47 |
+
fell back to a generic script. The fix was a tolerant parser: un-escape stray quotes, drop
|
| 48 |
+
trailing commas, and β crucially β a **salvage pass** that recovers individual shot objects past
|
| 49 |
+
a broken tail. *Lesson: never trust a small model to emit clean JSON; design the parser to
|
| 50 |
+
salvage, not validate.*
|
| 51 |
+
|
| 52 |
+
**2. Gradio's `cancels=` doesn't reliably stop a running generator.** Our opening film auto-played
|
| 53 |
+
as a streaming generator; when a user hit "Make," the default film kept streaming *over* their
|
| 54 |
+
loading screen. `cancels` didn't stop it. We replaced it with a **per-session generation token**:
|
| 55 |
+
every playback bumps a counter and bails the instant a newer one supersedes it. *Lesson: for
|
| 56 |
+
"only one stream at a time, newest wins," own the cancellation yourself with a token β don't rely
|
| 57 |
+
on the framework.*
|
| 58 |
+
|
| 59 |
+
**3. `height: 100vh` inside Hugging Face's auto-resizing iframe is an infinite loop.** The iframe
|
| 60 |
+
sizes to content; content sized to the viewport; they fed each other and the page grew past
|
| 61 |
+
18,000px. Any viewport-relative height does it. The fix was a **fixed pixel app height** β a
|
| 62 |
+
constant the loop can't amplify. *Lesson: in an embedded Space, never size to the viewport.*
|
| 63 |
+
|
| 64 |
+
**4. The biggest lever on a small model's writing is the in-context example.** Prompt
|
| 65 |
+
instructions help, but a single high-quality 9-shot example β the exact format, length, and prose
|
| 66 |
+
we wanted β moved output quality more than paragraphs of rules. *Lesson: show, don't tell, even to
|
| 67 |
+
the model.*
|
| 68 |
+
|
| 69 |
+
**5. Keep prose and pixels in sync, mechanically.** The model would narrate "a fireplace" that
|
| 70 |
+
never appeared, because only the `cast` is drawn. Rather than hope the model behaves, we scan each
|
| 71 |
+
narration against the full sprite vocabulary (β100 sprites + ~130 aliases + common objects) and
|
| 72 |
+
**force any named drawable subject into the cast**. *Lesson: when two outputs must agree, don't
|
| 73 |
+
prompt for it β enforce it in code.*
|
| 74 |
+
|
| 75 |
+
**6. Streaming longevity matters.** A ~90s film is hundreds of frames. Building the whole frame
|
| 76 |
+
list up front, or blocking 60β90s on a cold model call with no yields, made the stream stall and
|
| 77 |
+
restart β replaying the intro forever. We made frames lazy (first frame instant) and run the model
|
| 78 |
+
call in a thread with a 1s heartbeat. *Lesson: a streaming UI must never go silent.*
|
| 79 |
+
|
| 80 |
+
---
|
| 81 |
+
|
| 82 |
+
## Design
|
| 83 |
+
|
| 84 |
+
We pushed hard past the default Gradio look: a flat **charcoal background with a faint blueprint
|
| 85 |
+
grid**, **JetBrains Mono** everywhere, a left "shelf" nav, and a glowing-bezel **screen** with a
|
| 86 |
+
`now_playing:` status bar and HUD corner brackets. Films stay contained in a fixed frame; the
|
| 87 |
+
nav never scrolls sideways.
|
| 88 |
+
|
| 89 |
+
---
|
| 90 |
+
|
| 91 |
+
## Safety
|
| 92 |
+
|
| 93 |
+
User prompts pass a content filter (profanity, slurs, hate) before anything is generated, in both
|
| 94 |
+
Make and the (now-removed) Adventure mode. Creations are **private to the maker's session** and
|
| 95 |
+
never stored or shown to anyone else.
|
| 96 |
+
|
| 97 |
+
---
|
| 98 |
+
|
| 99 |
+
## What's next
|
| 100 |
+
|
| 101 |
+
- **Off the grid:** quantize Cinema to **GGUF** and run it via **llama.cpp** inside the Space β
|
| 102 |
+
no cloud, free CPU, ~the same quality (quantization costs speed, not craft).
|
| 103 |
+
- **Better prose:** the real step-change is the training data β a few hundred excellent 9-beat
|
| 104 |
+
scripts would teach the model the *voice*, not just instruct it.
|
| 105 |
+
- **A custom frontend** via `gr.Server` for total design control.
|
| 106 |
+
|
| 107 |
+
---
|
| 108 |
+
|
| 109 |
+
## Credits
|
| 110 |
+
|
| 111 |
+
Model: fine-tuned **MiniCPM3β4B** (OpenBMB base). App: Gradio + a custom ASCII render engine.
|
| 112 |
+
Built by **Conductor AI Labs** for the Build Small Hackathon.
|