Character Consistency
The Character Consistency workflow (/character_consistency) solves one of the hardest challenges in generative media: placing a specific person or character from reference photos into brand-new cinematic scenes and videos while preserving their exact facial structure and likeness.

Source Architecture
Section titled “Source Architecture”| Layer | File Path | Responsibility |
|---|---|---|
| Mesop Page & State | pages/character_consistency.py, state/character_consistency_state.py |
Multi-photo character uploader, scene prompt input, live step-by-step progress visualizer, candidate gallery, and video showcase. |
| Workflow Engine | models/character_consistency.py (generate_character_video, FacialCompositeProfile, BestImage) |
Implements the 7-step generator pipeline combining Gemini structured analysis, Imagen 3 Subject Customization / Nano Banana, Gemini visual selection, 16:9 outpainting, and Veo video generation. |
The 7-Step Pipeline (models/character_consistency.py)
Section titled “The 7-Step Pipeline (models/character_consistency.py)”Step 1: Reference Photo Upload to GCS
Section titled “Step 1: Reference Photo Upload to GCS”- The user uploads one or more reference photographs of the target character (
character_images) and provides a natural-language Scene Prompt describing the desired setting, lighting, and action.
Step 2: Gemini Facial Composite Profile Extraction (FacialCompositeProfile)
Section titled “Step 2: Gemini Facial Composite Profile Extraction (FacialCompositeProfile)”extract_facial_profile()sends all reference photos to Gemini withresponse_schema=FacialCompositeProfile, extracting a forensic-grade structured description coveringage,gender,ethnicity,hair_color,hair_style,eye_color,eye_shape,eyebrows,nose_shape,mouth_shape,chin_shape,jawline,face_shape,facial_hair,skin_tone,skin_texture,distinctive_features, andTypical_expression.
Step 3: Natural-Language Description Synthesis
Section titled “Step 3: Natural-Language Description Synthesis”natural_language_description()converts the structuredFacialCompositeProfileJSON into a cohesive photographic character description optimized for image generation conditioning.
Step 4: Prompt Combination & Multi-Candidate Scene Generation
Section titled “Step 4: Prompt Combination & Multi-Candidate Scene Generation”generate_scene_prompt()merges the character description with the user’s target Scene Prompt.generate_images()invokes Vertex AI subject-conditioned image synthesis (imagen-3.0-capability-001withSubjectReferenceImageandControlReferenceImageface-mesh conditioning, or Nano Banana) to generate 4 candidate scene images (1:1square framing focused on character likeness).
Step 5: Gemini Best-Likeness Selection (select_best_image)
Section titled “Step 5: Gemini Best-Likeness Selection (select_best_image)”select_best_image()passes the original reference photos, the generated candidate images, and the scene prompt to Gemini (response_schema=BestImage).- Gemini compares facial geometry, expression, and scene fidelity across all candidates and selects
best_image_pathalong with a detailedreasoningexplanation displayed in the UI.
Step 6: 16:9 Cinematic Outpainting (outpaint_image)
Section titled “Step 6: 16:9 Cinematic Outpainting (outpaint_image)”- To prepare the selected
1:1portrait for widescreen video without cropping or distorting the character’s face,outpaint_image()pads the selected image to a16:9canvas (1920x1080), generates a binary expansion mask, and outpaints the surrounding environment seamlessly.
Step 7: Veo Video Synthesis (generate_video)
Section titled “Step 7: Veo Video Synthesis (generate_video)”- Gemini generates a camera and motion prompt (
generate_video_prompt()) tailored to the outpainted16:9keyframe, andgenerate_video()animates the frame via Veo (models/veo.py), logging all intermediate candidates, the outpainted frame, reasoning trace, and final MP4 as aMediaItemin Firestore.