An AI-powered backend service for generating educational mathematical animation videos using Manim. This service takes a user prompt, intelligently analyzes it to create a title and subject, and then generates a complete Manim Python script with automated voice-over to produce an engaging animated video.
- REST API: Asynchronous endpoints for generating videos and checking their status.
- Dual AI Model Architecture:
- Google Gemini: Used for intelligent prompt analysis to automatically generate a video title and categorize the subject.
- OpenAI: Powers the generation of complex Manim animation scripts in Python.
- Automated Voice-over: Integrates with Azure Cognitive Services to generate high-quality text-to-speech narration synchronized with the animation.
- Job Queue: Uses Bull and Redis for robust, background processing of video generation jobs.
- Scalable Storage: Leverages Supabase for storing video metadata and the final video files.
- Flexible Input: Accepts both
application/jsonandmultipart/form-datato handle requests with or without image inputs. - Containerized: Fully containerized with Docker for consistent development, testing, and production environments.
- Deployment-Ready: Includes configurations for easy deployment to platforms like Heroku.
- A user sends a
POSTrequest to/api/video/generatewith a prompt (e.g., "Explain the Pythagorean theorem"). - Gemini API analyzes the prompt to generate a title and subject (e.g.,
title: "Understanding Pythagoras",subject: "Math"). - A new job is added to the Redis queue via Bull.
- A worker process picks up the job and calls the OpenAI API to generate a Manim Python script based on the prompt. The script includes voice-over commands using Azure TTS.
- The Manim script is executed in a sandboxed environment to render the video.
- The final video is uploaded to Supabase Storage.
- The video's metadata and URL are updated in the Supabase database.
- The user can poll the
/api/video/status/:jobIdendpoint to get the final video URL.
- Docker and Docker Compose
- Supabase Account & Project
- OpenAI API Key
- Google Gemini API Key
- Azure Account with Speech Service
-
Clone the repository and create a
.envfile from the example:git clone https://github.com/your-username/pintaru-be.git cd pintaru-be cp .env.example .env -
Fill in your API keys and configuration in the
.envfile:# API Keys GEMINI_API_KEY=your_gemini_api_key_here OPENAI_API_KEY=your_openai_api_key_here # Supabase Configuration SUPABASE_URL=your_supabase_project_url_here SUPABASE_ANON_KEY=your_supabase_anon_key_here # Redis Configuration REDIS_HOST=redis REDIS_PORT=6379 REDIS_PASSWORD= # Optional # Azure Cognitive Services for Voice-over AZURE_SUBSCRIPTION_KEY=your_azure_subscription_key_here AZURE_SERVICE_REGION=your_azure_service_region_here # Server Configuration PORT=3000 NODE_ENV=development
Start the development environment using Docker Compose:
docker-compose up --buildThe service will be available at http://localhost:3000. The code is hot-reloaded on changes.
To run in production mode, use the production-specific Docker Compose file:
docker-compose -f docker-compose.prod.yml up -d --buildThis uses optimized settings for a production environment.
Health check endpoint to verify that the server is running.
- Response
200 OK{ "status": "OK", "message": "Server is running" }
Creates a new video generation job. Accepts application/json or multipart/form-data.
-
Request Body (
application/json){ "prompt": "Show me how to calculate the area of a circle", "user_id": "user123", "image_data": "base64_encoded_image_data_here" // Optional } -
Request Body (
multipart/form-data)prompt: "Explain the concept in the image"user_id: "user123"image: [binary image file]
-
Response
202 Accepted{ "jobId": "12345", "requestId": "some-unique-request-id", "status": "queued", "message": "Video generation job queued successfully", "title": "Calculating the Area of a Circle", "subject": "Math", "has_image": true }
Retrieves the status of a specific video generation job.
- Response (Job Queued)
{ "status": "queued" } - Response (Job Completed)
{ "status": "completed", "videoUrl": "https://your-supabase-url/path/to/video.mp4" }
Lists all jobs in the queue.
.
├── src/
│ ├── app.js # Express app configuration and middleware
│ ├── config/ # Configuration loader (from .env)
│ ├── controllers/ # Route handlers and business logic
│ ├── routes/ # API route definitions
│ ├── services/ # External service integrations (AI, DB, Queue)
│ └── server.js # Server entry point
├── docker-compose.yml # Docker setup for development
├── docker-compose.prod.yml # Docker setup for production
├── Dockerfile # Dockerfile for development
├── Dockerfile.prod # Dockerfile for production
└── package.json # Project dependencies
ISC