Spaces:
Configuration error
οΏ½ Animetrix AI - AI Educational Animation Generator
Create professional educational animations from natural language using AI and Manim
π Overview
Animetrix AI is an intelligent animation generation platform that transforms simple text descriptions into high-quality educational videos. Powered by Google Gemini AI and Manim Community Edition, it automatically interprets concepts, generates animation code, and renders professional videos with synchronized voiceovers.
Key Features
- π€ AI-Powered Generation β Natural language to animated video pipeline
- π¬ Synchronized Narration β Step-by-step voiceover perfectly timed with animations
- π¨ Professional Quality β Clean Manim animations with smart post-processing
- π§ Self-Correcting β Automatic error detection and code sanitization
- π Production Ready β FastAPI backend with modern web interface
π Architecture
graph TD
A[User Prompt] --> B[Teacher Module]
B --> C[Gemini AI - Outline Generation]
C --> D[Structured JSON with Steps]
D --> E[Narrator - Per-Step Audio]
E --> F[Compiler - Code Generation]
F --> G[Gemini AI - Manim Code]
G --> H[Code Sanitization]
H --> I[Runner - Manim Rendering]
I --> J[Video + Audio Merge]
J --> K[Final MP4 Output]
Pipeline Stages
- Teacher (
teacher.py) - Converts prompts into structured educational outlines - Narrator (
narrator.py) - Generates per-step narration audio with gTTS - Compiler (
compiler.py) - Creates clean Manim code with audio synchronization - Runner (
runner.py) - Executes rendering and merges audio/video
π Tech Stack
Backend
- FastAPI - High-performance async API framework
- Google Gemini 2.5 Flash - AI model for outline and code generation
- Manim Community Edition - Professional animation engine
- gTTS - Text-to-speech for narration
- MoviePy - Audio/video processing
Frontend
- Tailwind CSS - Modern, responsive design
- Three.js - Animated particle background
- Vanilla JavaScript - Lightweight, no framework overhead
Infrastructure
- Python 3.8+
- FFmpeg for video encoding
- Environment-based configuration
π Project Structure
animetrix-ai/
βββ backend/
β βββ main.py # FastAPI application & pipeline orchestration
β βββ teacher.py # Outline generation (Gemini)
β βββ compiler.py # Code generation & sanitization (Gemini)
β βββ runner.py # Manim rendering
β βββ narrator.py # Audio generation & merging
β βββ requirements.txt # Python dependencies
β βββ static/
β β βββ index.html # Web interface
β βββ media/ # Generated videos & audio
βββ .env # Environment variables
βββ .gitignore
βββ README.md
π Quick Start
Prerequisites
- Python 3.8 or higher
- FFmpeg installed and in PATH
- Google Gemini API key
Installation
Clone the repository
git clone https://github.com/SayedZahur786/Animetrix_AI.git cd Animetrix_AICreate virtual environment
python -m venv venv venv\Scripts\activate # Windows # source venv/bin/activate # Linux/MacInstall dependencies
cd backend pip install -r requirements.txtConfigure environment
Create
.envfile in the root directory:GEMINI_API_KEY=your_gemini_api_key_hereUpdate FFmpeg path (Windows)
Edit main.py and set your FFmpeg path:
ffmpeg_path = r"C:\path\to\ffmpeg\bin"
Running the Application
cd backend
uvicorn main:app --reload
Open your browser and navigate to:
http://localhost:8000
π― Usage
- Enter a prompt in the text area (e.g., "Explain the Pythagorean theorem with a visual proof")
- Click Generate to start the pipeline
- Monitor progress through real-time status updates:
- Planning (outline generation)
- Coding (Manim script creation)
- Executing (animation rendering)
- Watch the result - video automatically plays when ready
Example Prompts
- "Show how compound interest grows over time"
- "Visualize the concept of derivatives with a tangent line"
- "Demonstrate bubble sort algorithm step by step"
- "Explain photosynthesis with animated diagrams"
π§ Configuration
Environment Variables
| Variable | Description | Required |
|---|---|---|
GEMINI_API_KEY |
Google Gemini API key | Yes |
FFmpeg Configuration
Update the FFmpeg path in main.py line 13:
ffmpeg_path = r"M:\Ap\ffmpeg-7.1.1-essentials_build\ffmpeg-7.1.1-essentials_build\bin"
π‘ API Reference
POST /generate
Generate an educational animation from a text prompt.
Request Body:
{
"prompt": "Explain Newton's first law of motion"
}
Response:
{
"status": "started"
}
GET /status
Check the current generation status.
Response:
{
"stage": "executing",
"message": "Rendering Animation Frames...",
"video_path": null,
"error": null
}
GET /video/{path}
Retrieve the generated video file.
π Troubleshooting
| Issue | Solution |
|---|---|
| FFmpeg not found | Ensure FFmpeg is installed and path is correctly set in main.py |
| Gemini API errors | Verify your API key is valid and has sufficient quota |
| Import errors | Run pip install -r requirements.txt in the backend directory |
| Manim rendering fails | Check that Manim CE is properly installed: pip install manim |
π Free Deployment Options
Option 1: Render.com (Recommended)
Best for: Simple, automated deployments
- β Free tier with 750 hours/month
- β Auto-deploy from GitHub
- β Built-in SSL
- β οΈ Spins down after inactivity (cold starts ~30s)
Steps:
- Push code to GitHub
- Connect to Render.com
- Create new Web Service
- Add environment variable:
GEMINI_API_KEY - Build command:
cd backend && pip install -r requirements.txt - Start command:
cd backend && uvicorn main:app --host 0.0.0.0 --port $PORT
Option 2: Railway.app
Best for: Quick deployments with generous free tier
- β $5 free credit/month
- β No sleep/cold starts
- β GitHub integration
Steps:
- Connect GitHub repo to Railway.app
- Add
GEMINI_API_KEYin Variables - Set start command:
cd backend && uvicorn main:app --host 0.0.0.0 --port $PORT
Option 3: Fly.io
Best for: Global edge deployment
- β Free tier: 3 shared VMs
- β Global CDN
- β Fast performance
Steps:
- Install Fly CLI:
curl -L https://fly.io/install.sh | sh - Login:
fly auth login - Launch:
fly launch - Set secrets:
fly secrets set GEMINI_API_KEY=your_key
Option 4: Google Cloud Run
Best for: Pay-per-use, scales to zero
- β 2 million requests/month free
- β No cold start issues
- β Integrated with Google services
Steps:
- Create
Dockerfilein project root:FROM python:3.10-slim RUN apt-get update && apt-get install -y ffmpeg && rm -rf /var/lib/apt/lists/* WORKDIR /app COPY backend/requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY backend/ . EXPOSE 8080 CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"] - Deploy:
gcloud run deploy animetrix-ai --source .
Option 5: Hugging Face Spaces
Best for: ML/AI community exposure
- β Free GPU access (limited)
- β Great for demos
- β Built-in community
Steps:
- Create new Space at huggingface.co/spaces
- Select "Gradio" or "Streamlit" SDK
- Push code to Space repository
- Add
GEMINI_API_KEYin Space secrets
Comparison Table
| Platform | Free Tier | Cold Starts | Deployment | Best For |
|---|---|---|---|---|
| Render.com | β 750h/month | Yes (~30s) | Easiest | Beginners |
| Railway.app | β $5 credit | No | Easy | Active projects |
| Fly.io | β 3 VMs | Minimal | Moderate | Performance |
| Google Cloud Run | β 2M requests | Minimal | Advanced | Scale |
| Hugging Face | β Free GPU | No | Easy | ML Community |
π‘ Recommendation: Start with Render.com for easiest setup, then migrate to Railway.app or Fly.io for production use.
π€ Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
π License
This project is open source and available under the MIT License.
π¨βπ» Author
Sayed Zahur
- GitHub: @SayedZahur786
- Repository: Animetrix_AI
Made with β€οΈ using AI and Manim