CoolFace
Apppublic

ejzhu2026/video-agent-hero

sourceHugging Faceupdated 6mo agoView on Hugging Face
2likes
App README

Video Agent Hero ๐ŸŽฌ

An agentic short-form video generator with a chat-driven two-phase pipeline: Plan โ†’ Review โ†’ Generate โ†’ Modify

Powered by LangGraph + Claude + fal.ai Wan 2.2 + Google OAuth + Stripe.

๐ŸŒ Live demo: ejzhu2026-video-agent-hero.hf.space


Features

  • โ€”Chat-driven UI โ€” describe your video, then refine via conversation
  • โ€”Two-phase pipeline โ€” see and edit the storyboard before generating
  • โ€”Turbo โ†’ HD upgrade โ€” quick 480p preview first, then upgrade to 720p
  • โ€”Smart partial re-render โ€” AI classifies feedback as global (full replan) or local (re-render only affected shots), saving time and cost
  • โ€”Real-time agent steps โ€” watch each pipeline node run with live elapsed timers
  • โ€”LLM auto-naming โ€” projects are automatically named by Claude Haiku after planning
  • โ€”Brand kit โ€” consistent logo, colors, fonts, subtitles across all videos
  • โ€”Background music โ€” auto-generated via Replicate MusicGen, mixed to video
  • โ€”Memory โ€” past projects stored in ChromaDB for semantic retrieval
  • โ€”Credit system โ€” per-shot billing with Stripe top-up; new users get 10 free credits
  • โ€”Google OAuth โ€” one-click sign-in, no passwords

Architecture

POST /plan                POST /execute             POST /modify
     โ”‚                         โ”‚                         โ”‚
     โ–ผ                         โ–ผ                         โ–ผ
intent_parser          executor_pipeline         change_classifier
memory_loader          caption_agent              โ”œโ”€ local โ†’ partial_executor
clarification_planner  layout_branding            โ””โ”€ global โ†’ planner_llm
planner_llm โ—„โ”€โ”€โ”€โ”€โ”€โ”€    quality_gate                            โ”‚
plan_checker (loop)    qc_diagnose                    music_mixer
     โ”‚                 render_export              result_summarizer
     โ–ผ                 music_mixer                memory_writer โ†’ END
  Plan JSON            result_summarizer
  saved to DB          memory_writer โ†’ END

LangGraph orchestrates 4 compiled graphs:

GraphEntry โ†’ ExitUsed by
build_plan_only_graphintent_parser โ†’ plan_checker โ†’ END/plan
build_execute_only_graphexecutor_pipeline โ†’ music_mixer โ†’ memory_writer โ†’ END/execute
build_partial_rerender_graphchange_classifier โ†’ โ€ฆ โ†’ music_mixer โ†’ memory_writer โ†’ END/modify
build_replan_graphplanner_llm โ†’ โ€ฆ โ†’ music_mixer โ†’ memory_writer โ†’ END/feedback

Pipeline Nodes

NodeRoleExternal Call
intent_parserExtracts platform / duration hints from briefโ€”
memory_loaderLoads brand kit (SQLite) + similar projects (ChromaDB)SQLite, ChromaDB
clarification_plannerDetects missing fields, generates questionsโ€”
planner_llmGenerates 4-shot Plan JSON; includes existing plan on replanClaude Sonnet
plan_checkerValidates duration, shots, script; auto-fixes; loops โ‰ค3ร—โ€”
executor_pipelineRenders each shot via T2V (parallel, 6 workers)fal.ai wan/v2.2-a14b
caption_agentMaps script lines to shot durations โ†’ caption segmentsโ€”
layout_brandingConcat clips + burn subtitles + add logo watermarkFFmpeg
quality_gateProbes resolution, duration, bitrate, frame contentFFmpeg (ffprobe)
qc_diagnoseRoot-cause analysis; routes to retry / user action / proceedClaude (fallback)
render_exportFinal H.264 CRF23 + AAC 128k encodeFFmpeg
music_mixerInfers tone from brief/mood, generates music, mixes into videoReplicate MusicGen
result_summarizerBuilds human-readable summary; deducts creditsโ€”
memory_writerPersists plan + output path + vector embeddingSQLite, ChromaDB
change_classifierClassifies feedback as global/local; identifies shot indicesClaude Haiku
partial_executorRe-renders only affected shots; reuses disk clips for the restfal.ai wan/v2.2-a14b

State (AgentState)

All nodes share a single TypedDict that flows through the graph:

python
{
  # Identity
  "project_id": "a1b2c3d4",
  "brief": "Summer promo for Tong Sui Coconut Watermelon",
  "brand_id": "tong_sui",

  # Plan (output of planner_llm)
  "plan": {
    "platform": "tiktok", "duration_sec": 10,
    "concept": { "mood": "fresh", "visual_style": "..." },
    "script": { "hook": "...", "body": [...], "cta": "..." },
    "storyboard": [{ "scene": 1, "desc": "...", "duration": 2.5 }, ...],
    "shot_list":  [{ "shot_id": "S1", "text_overlay": "...", "duration": 2.5 }, ...],
    "_quality": "turbo"          # written after execute
  },

  # Execution
  "scene_clips": [{ "shot_id": "S1", "clip_path": "...", "duration": 2.5 }],
  "branded_clip_path": "data/projects/.../branded.mp4",
  "output_path": "data/exports/a1b2c3d4_9x16_....mp4",

  # Quality
  "quality": "turbo",            # "turbo" | "hd"
  "quality_result": { "passed": true, "issues": [] },

  # Partial re-render
  "change_type": "local",
  "affected_shot_indices": [1],
  "shot_updates": { "1": { "desc": "...", "text_overlay": "..." } },

  # Control
  "needs_replan": false,
  "plan_version": 1,
  "messages": [...]
}

Credit System

ActionCost
Turbo shot (480p)1 credit
HD shot (720p)3 credits
New user signup10 free credits

1 credit โ‰ˆ $0.10. A typical 5-shot turbo video costs 5 credits (~$0.50).

Credit Packages (Stripe)

PackageCreditsPrice
Starter50$5
Pro200$15
Studio500$30

Credits are deducted after successful generation. A pre-flight check prevents generation if balance is insufficient โ€” the Approve bar stays visible so users can top up and retry.


Video Quality Tiers

TierModelFramesResolutionClip length
Turbofal-ai/wan/v2.2-a14b/text-to-video33 @ 16fps480p~2s
HDfal-ai/wan/v2.2-a14b/text-to-video81 @ 16fps720p~5s

UI Flow

idle โ”€โ”€[Send brief]โ”€โ”€โ–บ planning โ”€โ”€[done]โ”€โ”€โ–บ plan_ready
                                                โ”‚
                                    Edit storyboard cards
                                    โšก Turbo / โœฆ HD quality chip
                                    ~X credits estimate shown
                                                โ”‚
                                    [โ–ถ Approve & Generate]
                                                โ”‚
                                           executing โ”€โ”€[done]โ”€โ”€โ–บ done
                                                                   โ”‚
                                              โšก Turbo preview shown
                                              [โœฆ Upgrade to HD] button
                                                                   โ”‚
                                              [chat: "modify..."] โ”€โ”˜
                                                     smart re-render

Chat bar states:

StateInput placeholderAction
idle / errorDescribe your video...Create project + plan
plan_readyAsk to change the plan...Replan with feedback
doneModify this video...Smart partial/global re-render

Project Structure

video-agent-hero/
โ”œโ”€โ”€ web/
โ”‚   โ”œโ”€โ”€ server.py              # FastAPI + SSE streaming + inline HTML/JS frontend
โ”‚   โ”œโ”€โ”€ auth/                  # Google OAuth (router, models, deps)
โ”‚   โ””โ”€โ”€ billing/               # Stripe checkout + credit operations
โ”œโ”€โ”€ agent/
โ”‚   โ”œโ”€โ”€ graph.py               # 4 LangGraph compiled graphs
โ”‚   โ”œโ”€โ”€ state.py               # AgentState TypedDict
โ”‚   โ”œโ”€โ”€ deps.py                # DB + VectorStore singletons
โ”‚   โ””โ”€โ”€ nodes/                 # 15 node functions (one file each)
โ”œโ”€โ”€ render/
โ”‚   โ”œโ”€โ”€ fal_t2v.py             # fal.ai T2V wrapper (turbo/hd quality tiers)
โ”‚   โ”œโ”€โ”€ ffmpeg_composer.py     # concat, subtitles, watermark, trim/scale, music mix
โ”‚   โ”œโ”€โ”€ caption_renderer.py    # SRT/ASS subtitle file writer
โ”‚   โ””โ”€โ”€ frame_generator.py     # PIL placeholder frames (no-key fallback)
โ”œโ”€โ”€ memory/
โ”‚   โ”œโ”€โ”€ db.py                  # SQLite (projects, brand_kits, user_prefs, feedback)
โ”‚   โ”œโ”€โ”€ vector_store.py        # ChromaDB semantic search
โ”‚   โ””โ”€โ”€ schemas.py             # Pydantic v2 models
โ”œโ”€โ”€ cli/main.py                # Typer CLI (vah init/new/run/feedback/demo)
โ”œโ”€โ”€ assets/                    # Brand assets (auto-generated on startup)
โ”œโ”€โ”€ data/                      # Runtime data โ€” gitignored
โ”‚   โ”œโ”€โ”€ vah.db                 # SQLite (projects + users + billing)
โ”‚   โ”œโ”€โ”€ chroma/                # ChromaDB
โ”‚   โ”œโ”€โ”€ projects/{id}/clips/   # Per-shot MP4s (reused on partial re-render)
โ”‚   โ””โ”€โ”€ exports/               # Final deliverable MP4s
โ”œโ”€โ”€ Dockerfile                 # HuggingFace Spaces deployment
โ””โ”€โ”€ requirements.txt

Quick Start (Local)

Prerequisites

bash
brew install ffmpeg        # macOS
# sudo apt install ffmpeg  # Ubuntu
python3.11 -m venv .venv && source .venv/bin/activate

Install & Run

bash
git clone https://github.com/ejzhu2025/video-agent-hero
cd video-agent-hero
pip install -r requirements.txt
uvicorn web.server:app --host 0.0.0.0 --port 7860 --reload
# Open http://localhost:7860

Environment Variables

VariableRequiredDescription
ANTHROPIC_API_KEYFor AI planningClaude Sonnet planner + Haiku classifier/namer
FAL_KEYFor video generationfal.ai Wan 2.2 T2V
GOOGLE_CLIENT_IDFor authGoogle OAuth app client ID
GOOGLE_CLIENT_SECRETFor authGoogle OAuth app client secret
STRIPE_SECRET_KEYFor billingStripe API secret key
STRIPE_WEBHOOK_SECRETFor billingStripe webhook signing secret
REPLICATE_API_TOKENOptionalReplicate MusicGen background music
VAH_DATA_DIROptionalData directory (default: ./data)
SESSION_SECRETOptionalCookie signing secret (auto-generated if unset)

Without ANTHROPIC_API_KEY / FAL_KEY: mock planner + PIL placeholder frames (useful for UI development).


CLI Reference

bash
pip install -e .   # installs `vah` command

vah init           # seed DB with Tong Sui brand kit
vah new --brief "..." [--brand X] [--user Y]
vah run --project ID [--yes]
vah feedback --project ID --text "..."
vah list
vah demo           # full end-to-end Tong Sui demo

Output Spec

PropertyValue
Resolution1080 ร— 1920 (9:16 vertical)
CodecH.264 (libx264), CRF 23
Frame rate30 fps
AudioAAC 128kbps
CaptionsBurned-in SRT, branded box style
LogoWatermark in configurable safe area
MusicMixed at โˆ’18 dB under original audio

HuggingFace Spaces Deployment

Set these as Space Secrets (Settings โ†’ Repository secrets):

ANTHROPIC_API_KEY
FAL_KEY
GOOGLE_CLIENT_ID
GOOGLE_CLIENT_SECRET
STRIPE_SECRET_KEY
STRIPE_WEBHOOK_SECRET
REPLICATE_API_TOKEN   # optional, for background music
SESSION_SECRET        # any random string

Data is stored in /data (Docker volume). The app auto-seeds the brand kit on startup.