|
1 | | -<!-- Top-level decorative header and architecture image --> |
2 | 1 | <p align="center"> |
3 | 2 | <a href="https://github.com/pushpitkamboj/AnimAI"> |
4 | 3 | <img src="https://raw.githubusercontent.com/pushpitkamboj/AnimAI/main/arch_image.png" alt="Architecture" width="900"/> |
|
12 | 11 | <a href="https://github.com/pushpitkamboj/AnimAI/blob/main/LICENSE"><img src="https://img.shields.io/github/license/pushpitkamboj/AnimAI" alt="license"/></a> |
13 | 12 | </p> |
14 | 13 |
|
15 | | -# AnimAI — manim-app |
| 14 | +# AnimAI |
16 | 15 |
|
17 | | -An opinionated Manim-based animation generator that converts natural language prompts into Manim scenes using LangChain/LangGraph agents, a RAG index and optional HTTP API. |
| 16 | +AnimAI converts natural-language prompts into Manim videos. |
18 | 17 |
|
19 | | -> Beautiful, reproducible animations—driven by LLMs + retrieval. |
| 18 | +The active backend is a small server-side pipeline: |
20 | 19 |
|
21 | | -## Table of contents |
| 20 | +`POST /run` -> `src/api/main.py` -> `src/agent/graph.py` -> `src/agent/execute_code.py` -> `manim-worker/app.py` |
22 | 21 |
|
23 | | -- [Project summary](#project-summary) |
24 | | -- [Architecture](#architecture) |
25 | | -- [Technologies used](#technologies-used) |
26 | | -- [Deployment options](#deployment-options) |
27 | | - - [1) Langsmith / LangGraph](#1-deploy-through-langsmith--langgraph) |
28 | | - - [2) Self-host (FastAPI)](#2-self-host-fastapi) |
29 | | -- [Quickstart (local)](#quickstart-local) |
30 | | -- [Codebase overview](#codebase-overview) |
31 | | -- [Examples](#examples) |
32 | | -- [Troubleshooting & tips](#troubleshooting--tips) |
33 | | -- [Contributing](#contributing) |
34 | | -- [License](#license) |
| 22 | +The API plans and generates Manim code, submits it to a dedicated render worker, polls every 5 seconds for job status, and returns a public video URL on success. |
35 | 23 |
|
36 | | -## Project summary |
| 24 | +## Current Architecture |
37 | 25 |
|
38 | | -The app translates user prompts into Manim commands via an LLM-backed agent and RAG index, then renders animations with Manim. It is designed to be run as a local service (FastAPI) or deployed via LangGraph/Langsmith flows. |
| 26 | +- `src/api/main.py` |
| 27 | + FastAPI entrypoint with language normalization, semantic cache lookup, Langfuse tracing, and the `/run` + `/health` endpoints. |
| 28 | +- `src/agent/graph.py` |
| 29 | + Active LangGraph workflow for prompt classification, grounding, planning, retrieval, generation, execution, and recovery. |
| 30 | +- `src/agent/execute_code.py` |
| 31 | + Submit-and-poll client for the render worker. |
| 32 | +- `manim-worker/app.py` |
| 33 | + Dedicated Manim execution service with `/jobs` and `/jobs/{job_id}`. |
| 34 | +- `src/rag/` |
| 35 | + Retrieval stack and supporting chunks for Manim-aware grounding. |
| 36 | +- `src/manim_docs/` |
| 37 | + Manim reference material used for retrieval/indexing. |
39 | 38 |
|
40 | | -## Architecture |
| 39 | +## Legacy Code |
41 | 40 |
|
42 | | -- Agent layer — LangChain / LangGraph agent composes, enhances and executes prompts. See `src/agent/`. |
43 | | -- Retrieval (RAG) — document chunking and vector indexing in `src/rag/` to make Manim commands and docs searchable. |
44 | | -- API — optional FastAPI endpoint at `src/api/main.py` (commented by default; see Self-host section). |
45 | | -- Renderer — Manim scenes and helpers live under `src/manim_docs/` and are used to produce final video assets. |
46 | | -- Storage / delivery — produced videos are uploaded (example: Cloudflare R2) and returned as URLs by the API. |
| 41 | +The repository still keeps the fine-tune graph experiments under: |
47 | 42 |
|
48 | | -High-level flow |
49 | | -1. User sends a natural language prompt to the agent. |
50 | | -2. Agent enhances the prompt and issues RAG queries to the vector store. |
51 | | -3. Agent produces a Manim script or workflow; rendering is performed by a worker running Manim. |
52 | | -4. Rendered video is stored and the API returns a shareable URL or status. |
| 43 | +- `src/agent/graph_fine_tune.py` |
| 44 | +- `src/agent/generate_code_fine_tune.py` |
| 45 | +- `src/agent/regenerate_code_fine_tune.py` |
| 46 | +- `src/agent/fine_tune_agent/` |
53 | 47 |
|
54 | | -## NOTE- the code written in fe folder is not source of truth, the production frontend code is here - https://github.com/AnshBansalOfficial/v0-anim-ai |
55 | | -## Technologies used |
| 48 | +These files are legacy experimental pipelines. They are not part of the active production request flow and are kept only as reference material. |
56 | 49 |
|
57 | | -- Python 3.10+ |
58 | | -- Manim library (rendering) |
59 | | -- LangChain / langchain_core (agent logic) |
60 | | -- LangGraph (workflow orchestration) |
61 | | -- Langsmith (for tracing & deployment) |
62 | | -- FastAPI (optional REST endpoint) |
63 | | -- Chroma or other vector store (RAG) |
64 | | -- Cloudflare R2 |
65 | | -- e2b code interpreter for sandboxing the code execution |
| 50 | +## Frontend Note |
66 | 51 |
|
67 | | -Key files: `pyproject.toml`, `src/agent/`, `src/rag/`, `src/api/main.py`. |
| 52 | +The code in `src/fe/` is not the source of truth for production frontend work. |
68 | 53 |
|
69 | | -## Deployment options |
| 54 | +Production frontend repo: |
| 55 | +`https://github.com/AnshBansalOfficial/v0-anim-ai` |
70 | 56 |
|
71 | | -### 1) Deploy through Langsmith / LangGraph |
| 57 | +## Local Development |
72 | 58 |
|
73 | | -- Use LangGraph to publish the workflow/graph; Langsmith can be used for tracing and CI-based deployments. |
74 | | -- Steps (high level): |
75 | | - 1. Get `LANGSMITH_API_KEY` and set it in your CI or environment. |
76 | | - 2. Confirm `langgraph.json` or your graph module is up to date. |
77 | | - 3. Use platform-specific CLI/CI to publish the graph (CI should set `LANGSMITH_API_KEY` as secret and may set `LANGSMITH_TRACING=true`). |
78 | | - |
79 | | -See `langraph/project_langraph_platform/pyproject.toml` for compatible package versions used in examples. |
80 | | - |
81 | | -### 2) Self-host (FastAPI) |
82 | | - |
83 | | -This project contains a commented FastAPI entrypoint at `src/api/main.py` (marked "MIGRATED TO LANGGRAPH API FOR DEPLOYEMENT"). To enable self-hosting: |
84 | | - |
85 | | -1. Open `manimation/manim-app/src/api/main.py` and uncomment the FastAPI app code. The endpoints provided are `/run` (POST) and `/health` (GET). |
86 | | -2. Ensure dependencies are installed (see Quickstart below). |
87 | | -3. Run the app from the `manim-app` root: |
| 59 | +### Docker |
88 | 60 |
|
89 | 61 | ```bash |
90 | | -python -m uvicorn src.api.main:app --host 0.0.0.0 --port 8000 --reload |
| 62 | +docker compose up --build |
91 | 63 | ``` |
92 | 64 |
|
93 | | -The `/run` endpoint expects `{ "prompt": "..." }` and will return a `result` (a `video_url` on success) and `status`. |
94 | | - |
95 | | -Production notes: ensure `PYTHONPATH` includes the project root or use package-style imports. Replace permissive CORS with specific origins. Consider running the renderer as a background worker or container for heavier workloads. |
| 65 | +This starts: |
96 | 66 |
|
97 | | -## Quickstart (local) |
| 67 | +- API on `http://localhost:8000` |
| 68 | +- Manim worker on `http://localhost:8080` |
98 | 69 |
|
99 | | -1. Clone and change directory |
| 70 | +### Direct API run |
100 | 71 |
|
101 | 72 | ```bash |
102 | | -git clone https://github.com/pushpitkamboj/AnimAI |
103 | | -cd manimation/manim-app |
104 | | -``` |
105 | | - |
106 | | -2. Create and activate a venv |
107 | | - |
108 | | -```bash |
109 | | -python -m venv .venv |
110 | | -source .venv/bin/activate |
111 | | -``` |
112 | | - |
113 | | -3. Install dependencies |
114 | | - |
115 | | -```bash |
116 | | -pip install -e . |
117 | | -# or: poetry install |
118 | | -``` |
119 | | - |
120 | | -4. Environment variables (example) |
121 | | - |
122 | | -```bash |
123 | | -export OPENAI_API_KEY=sk-... |
124 | | -export LANGSMITH_API_KEY=lsv2_... |
125 | | -export LANGSMITH_TRACING=true |
| 73 | +python -m uvicorn src.api.main:app --host 0.0.0.0 --port 8000 --reload |
126 | 74 | ``` |
127 | 75 |
|
128 | | -5. Run unit tests |
| 76 | +If you run the API directly, you should also run the worker separately: |
129 | 77 |
|
130 | 78 | ```bash |
131 | | -pytest -q |
| 79 | +uvicorn app:app --app-dir manim-worker --host 0.0.0.0 --port 8080 --reload |
132 | 80 | ``` |
133 | 81 |
|
134 | | -6. Start the optional API (if uncommented) |
| 82 | +## Request Example |
135 | 83 |
|
136 | 84 | ```bash |
137 | | -python -m uvicorn src.api.main:app --reload |
| 85 | +curl -X POST http://localhost:8000/run \ |
| 86 | + -H 'Content-Type: application/json' \ |
| 87 | + -d '{"prompt":"2 squares rotating","language":"en"}' |
138 | 88 | ``` |
139 | 89 |
|
140 | | -## Codebase overview |
141 | | - |
142 | | -- `src/agent/` — agent code and prompt enhancement (`enhance_prompt.py`). |
143 | | -- `src/rag/` — chunking and indexing utilities for RAG. |
144 | | -- `src/api/main.py` — optional FastAPI endpoint (commented by default). |
145 | | -- `src/manim_docs/` — Manim helper modules and example scene code. |
146 | | -- `pyproject.toml` — dependencies and packaging metadata. |
147 | | -- `langgraph.json` — LangGraph workflow definition used for deployments. |
148 | | -- `tests/` — unit and integration tests. |
149 | | - |
150 | | -## Examples |
151 | | - |
152 | | -1) Call the API (if self-hosted) |
153 | | - |
154 | | -POST /run |
155 | | - |
156 | | -Request body: |
157 | | - |
158 | | -```json |
159 | | -{ "prompt": "Animate a circle turning into a square" } |
160 | | -``` |
161 | | - |
162 | | -Response (success): |
| 90 | +Example response: |
163 | 91 |
|
164 | 92 | ```json |
165 | | -{ "result": "https://.../generated_video.mp4", "status": "success" } |
| 93 | +{"result":"https://.../scene.mp4","status":"success"} |
166 | 94 | ``` |
167 | 95 |
|
168 | | -2) Run a quick local render (example developer flow) |
| 96 | +## Environment |
| 97 | + |
| 98 | +Common environment variables: |
| 99 | + |
| 100 | +- `OPENAI_API_KEY` |
| 101 | +- `MANIM_WORKER_URL` |
| 102 | +- `CHROMA_API_KEY` |
| 103 | +- `CHROMA_DATABASE` |
| 104 | +- `CHROMA_TENANT` |
| 105 | +- `R2_ACCOUNT_ID` |
| 106 | +- `R2_ACCESS_KEY_ID` |
| 107 | +- `R2_SECRET_ACCESS_KEY` |
| 108 | +- `R2_BUCKET` |
| 109 | +- `R2_PUBLIC_BASE_URL` |
| 110 | +- `LANGFUSE_PUBLIC_KEY` |
| 111 | +- `LANGFUSE_SECRET_KEY` |
| 112 | +- `LANGFUSE_BASE_URL` or `LANGFUSE_HOST` |
| 113 | +- `LANGFUSE_TIMEOUT` optional, defaults to `15` in this app |
| 114 | +- `LANGFUSE_FLUSH_AT` optional, defaults to `64` in this app |
| 115 | +- `LANGFUSE_FLUSH_INTERVAL` optional, defaults to `2` in this app |
| 116 | +- `LANGFUSE_TRACING_ENVIRONMENT` optional, e.g. `development` |
| 117 | +- `LANGFUSE_AUTH_CHECK_ON_STARTUP` optional, set to `true` for a startup connectivity check |
| 118 | + |
| 119 | +## Testing |
169 | 120 |
|
170 | 121 | ```bash |
171 | | -# Create a prompt payload and POST to /run, or call the agent runner directly from a script |
172 | | -python -c "from src.agent.enhance_prompt import enhance; print(enhance('Make a bouncing ball'))" |
| 122 | +pytest -q |
173 | 123 | ``` |
174 | 124 |
|
175 | | -## Troubleshooting & tips |
176 | | - |
177 | | -- Rendering slow? Use a dedicated worker or scale compute for Manim tasks. Reduce resolution for testing. |
178 | | -- Langsmith tracing failing? Confirm `LANGSMITH_API_KEY` and `LANGSMITH_TRACING=true`. |
179 | | -- Import errors after enabling API? Ensure you run from repo root and `PYTHONPATH` includes project root or run with `python -m uvicorn src.api.main:app`. |
180 | | - |
181 | | -## Contributing |
182 | | - |
183 | | -Contributions are welcome! Typical workflow: |
184 | | - |
185 | | -1. Fork the repo |
186 | | -2. Create a feature branch |
187 | | -3. Add tests and documentation |
188 | | -4. Open a pull request |
189 | | - |
190 | | -Please follow pep8 formatting and add unit tests for new features. |
191 | | - |
192 | 125 | ## License |
193 | 126 |
|
194 | | -This project includes a `LICENSE` file in the repository root. Review it for licensing details. |
195 | | - |
196 | | ---- |
197 | | - |
198 | | -If you'd like I can also: |
199 | | - |
200 | | -- add a `docker-compose.yml` for local testing (worker + API + vector DB), |
201 | | -- create a `quickstart.md` with screenshots and sample prompts, or |
202 | | -- pin dependency versions and add `requirements-dev.txt`. |
203 | | - |
204 | | -## Special thanks |
205 | | - |
206 | | -Special thanks to the Manim community for their beautiful documentation, examples, and continuous support — their work greatly inspired this project. See the official docs: https://docs.manim.community/en/stable/index.html |
207 | | -Note: Manim library and Manim Community edition are different, refer manim community docs for more details. |
| 127 | +See [LICENSE](/Users/pushpitkamboj/PersonalProjects/AnimAI/LICENSE). |
0 commit comments