How mateolafalce/topic2manim works
Purpose and Entry Points
Topic2Manim is a Flask-hosted pipeline that turns a user-entered educational topic into an approximately 60-second narrated Manim video. The HTTP application and orchestration entry point is src/main.py; the browser UI is served from src/frontend/index.html with behavior in src/frontend/app.js. It can run locally or in Docker via Dockerfile and docker-compose.yml.
Request and Orchestration Boundary
The frontend submits a topic to the Flask backend, which coordinates generation stages and returns/serves the resulting video. src/main.py is the system boundary between the web request lifecycle and long-running AI/media work. Environment-based API credentials and provider configuration are expected through .env.example.
LLM Script Planning
src/animations.py produces structured video-script JSON from the topic. It selects or configures LLM access with provider priority/fallback between Anthropic Claude and OpenAI GPT. The resulting script is the shared contract consumed independently by narration generation and Manim-code generation.
Narration and Timing
src/tts_generator.py converts script fragments into speech, concatenates them into a complete audio track, and exposes audio durations. Timing is a key cross-stage dependency: narration durations inform animation generation so visual scenes can fit their spoken sections.
Manim Scene Generation
src/manim_generator.py turns the script plus audio timing into generated Python/Manim scene files. This is the boundary from AI-generated textual plans/code to the local Manim Community Edition rendering runtime. Generated scenes are expected to contain mathematical and educational visualizations.
Video Rendering and Assembly
src/concat_video.py compiles generated Manim scene code into MP4 fragments, concatenates silent video fragments, then merges the assembled video with the final MP3 narration. Its output is the final playable video artifact; intermediate script, audio, source, and rendered-fragment artifacts connect the pipeline stages.
Presentation and Runtime Infrastructure
The static single-page interface resides in src/frontend/index.html, src/frontend/app.js, and src/frontend/style.css; example/output media is under public/. Python dependencies and runtime metadata are defined in pyproject.toml. Container execution is supported by Dockerfile and docker-compose.yml, while external dependencies are LLM APIs, a text-to-speech provider/runtime, and the local Manim rendering/media toolchain.
Main entry points: concat_video.py Render and assemble · tts_generator.py Narration generator · main.py Flask orchestrator · animations.py Script planner
Components 17
Web interface
- Browser UI
src/frontend/index.html - Topic submission
src/frontend/app.js - Flask orchestrator · Coordinates request-scoped generation and serves the resulting video.
src/main.py
Generation pipeline
- Script planner
src/animations.py - Claude / GPT · Provider selection supports priority and fallback.
- Video script · Shared input for narration and scene generation.
- Narration generator · Builds complete narration and exposes section durations.
src/tts_generator.py - TTS provider
- Narration MP3
- Audio timings
- Scene generator · Produces Python scenes fitted to spoken sections.
src/manim_generator.py - Generated scenes
Rendering runtime
- Render and assemble · Renders fragments, concatenates video, and merges narration.
src/concat_video.py - Manim media toolchain · Manim Community Edition and media tooling compile scene code.
- Rendered fragments
- Final video
public - Container runtime
Dockerfile
Connections 20
- Browser UI → Topic submission: runs
- Topic submission → Flask orchestrator: submits topic
- Flask orchestrator → Script planner: orchestrates
- Script planner → Claude / GPT: plans with
- Script planner → Video script: produces
- Video script → Narration generator: narration text
- Narration generator → TTS provider: synthesizes via
- Narration generator → Narration MP3: concatenates
- Narration generator → Audio timings: measures
- Video script → Scene generator: scene plan
- Audio timings → Scene generator: fits timing
- Scene generator → Generated scenes: writes
- Generated scenes → Render and assemble: renders
- Render and assemble → Manim media toolchain: invokes
- Manim media toolchain → Rendered fragments: compiles
- Rendered fragments → Render and assemble: concatenates
- Narration MP3 → Render and assemble: merges
- Render and assemble → Final video: outputs
- Flask orchestrator → Final video: serves
- Container runtime → Flask orchestrator: runs