Skip to content

W1neSkin/AnimatedPhoto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎬 Animated Photo - AI Video Generator

Transform static photos into short animated videos using Stable Video Diffusion, running 100% locally on your hardware with a modern microservices architecture.

Perfect for bringing vintage photos to life with smooth, natural motion!


πŸ—οΈ Architecture

This project uses a microservices architecture with separate containers:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  React Frontend β”‚ ───▢ β”‚  FastAPI Backendβ”‚ ───▢ β”‚  Model Service  β”‚
β”‚   Port: 3000    β”‚      β”‚   Port: 5000    β”‚      β”‚   Port: 5001    β”‚
β”‚                 β”‚      β”‚                 β”‚      β”‚   (GPU-powered) β”‚
β”‚  β€’ Upload UI    β”‚      β”‚  β€’ File handlingβ”‚      β”‚  β€’ SVD Model    β”‚
β”‚  β€’ Parameters   β”‚      β”‚  β€’ Job queue    β”‚      β”‚  β€’ Video gen    β”‚
β”‚  β€’ Progress     β”‚      β”‚  β€’ API routes   β”‚      β”‚  β€’ Docker       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Components:

  • Frontend: React + TypeScript for modern UI
  • Backend: FastAPI for async API with auto-documentation
  • Model Service: Flask + PyTorch running Stable Video Diffusion in Docker
  • Orchestration: Docker Compose for easy deployment

πŸš€ Features

  • Modern Tech Stack: React + FastAPI + Docker
  • Microservices: Each component runs independently
  • GPU Accelerated: Uses your RTX 5070 Ti through Docker
  • Latest AI Model: CogVideoX-5B (August 2024) - best open-source quality
  • Async Processing: Non-blocking video generation
  • Auto Documentation: FastAPI provides /docs endpoint
  • Easy Deployment: Single docker-compose up command
  • Customizable Parameters:
    • Prompt: Describe desired motion (NEW!)
    • Duration (1-6 seconds)
    • Frame rate (6-10 FPS, optimal: 8)
    • Quality (30-100 inference steps)
    • Guidance scale (prompt adherence)

πŸ“‹ Prerequisites

Required Software

  1. Python 3.11 or 3.12

  2. Node.js 20+ (LTS)

  3. Docker Desktop

Hardware Requirements

  • GPU: NVIDIA RTX 5070 Ti (or any CUDA GPU with 8GB+ VRAM)
  • RAM: 16GB+ recommended
  • Storage: ~20GB for models and cache
  • Internet: Required for initial model download (~15GB)

πŸ› οΈ Quick Setup

Automated Setup (Recommended)

# Run the setup script
.\setup.ps1

This will:

  1. Check prerequisites
  2. Create Python virtual environment
  3. Install all dependencies
  4. Prepare for deployment

Manual Setup

See SETUP.md for detailed manual installation steps.


🎯 Running the Application

Option A: Docker Compose (Recommended)

Easiest way - runs everything in containers:

# Build and start all services
docker-compose up --build

# Or run in background
docker-compose up -d --build

# View logs
docker-compose logs -f

# Stop services
docker-compose down

Access the app:

Option B: Local Development

Run each service separately (useful for development):

Terminal 1 - Model Service:

.\venv\Scripts\Activate
cd model-service
python model_service.py

Terminal 2 - Backend:

.\venv\Scripts\Activate
cd backend
python app.py

Terminal 3 - Frontend:

cd frontend
npm start

πŸ“ Project Structure

AnimatedPhoto/
β”œβ”€β”€ backend/                  # FastAPI backend
β”‚   β”œβ”€β”€ app.py               # Main API application
β”‚   β”œβ”€β”€ requirements.txt     # Python dependencies
β”‚   β”œβ”€β”€ Dockerfile           # Container definition
β”‚   β”œβ”€β”€ uploads/             # Uploaded photos (auto-created)
β”‚   └── outputs/             # Generated videos (auto-created)
β”‚
β”œβ”€β”€ model-service/           # AI model container
β”‚   β”œβ”€β”€ model_service.py     # Model inference API
β”‚   β”œβ”€β”€ requirements.txt     # ML dependencies
β”‚   β”œβ”€β”€ Dockerfile           # GPU-enabled container
β”‚   └── .dockerignore        # Exclude from build
β”‚
β”œβ”€β”€ frontend/                # React frontend
β”‚   β”œβ”€β”€ src/                 # Source code
β”‚   β”œβ”€β”€ public/              # Static files
β”‚   β”œβ”€β”€ package.json         # npm dependencies
β”‚   └── Dockerfile           # Container definition
β”‚
β”œβ”€β”€ docker-compose.yml       # Orchestration config
β”œβ”€β”€ setup.ps1                # Automated setup script
β”œβ”€β”€ SETUP.md                 # Detailed setup guide
└── README.md                # This file

🎨 Using the App

  1. Upload Photo

    • Click or drag & drop your image
    • Supports PNG, JPG, JPEG (max 16MB)
  2. Adjust Parameters

    • Duration: Length of video (1-5 seconds)
    • Frame Rate: Smoothness (7 FPS recommended)
    • Quality: Inference steps (25 = good balance)
    • Motion: Low/Medium/High animation strength
  3. Generate Video

    • Click "Generate Video"
    • Wait 1-3 minutes (varies by settings)
    • First generation loads model (~30 sec extra)
  4. Download Result

    • Preview video in browser
    • Download MP4 file

βš™οΈ API Endpoints (FastAPI)

The backend provides these REST API endpoints:

GET /api/health

Check backend and model service status

POST /api/upload

Upload photo and start generation

  • Form data: photo, duration, fps, quality, motion_strength
  • Returns: job_id for tracking

GET /api/status/{job_id}

Get job progress and status

  • Returns: status, progress, download_url

GET /api/download/{filename}

Download generated video

GET /api/jobs

List all jobs (debugging)

GET /docs

Auto-generated API documentation (FastAPI feature!)


πŸ› Troubleshooting

Python Not Found

# Verify Python installation
python --version

# If not found, reinstall and add to PATH

Docker GPU Not Working

# Check NVIDIA Docker runtime
docker run --rm --gpus all nvidia/cuda:12.1.0-base-ubuntu22.04 nvidia-smi

# If error, reinstall Docker Desktop and NVIDIA drivers

Model Download Fails

  • Check internet connection
  • Ensure ~20GB free disk space
  • Downloads resume automatically if interrupted

Port Already in Use

# Check what's using the port
netstat -ano | findstr :3000
netstat -ano | findstr :5000
netstat -ano | findstr :5001

# Kill process or change ports in docker-compose.yml

Out of Memory

  • Close other GPU-intensive apps
  • Lower quality/FPS settings
  • Ensure 8GB+ VRAM available

πŸ”§ Development

Backend Development

# Activate venv
.\venv\Scripts\Activate

# Run with auto-reload
cd backend
uvicorn app:app --reload --host 0.0.0.0 --port 5000

# View API docs at http://localhost:5000/docs

Frontend Development

cd frontend
npm start  # Auto-reloads on changes
npm run build  # Production build

Model Service Development

.\venv\Scripts\Activate
cd model-service
python model_service.py  # Runs on port 5001

πŸ” Technical Details

Backend (FastAPI)

  • Framework: FastAPI 0.109+ with async/await
  • Server: Uvicorn ASGI server
  • Features: Background tasks, CORS, file uploads, prompt control
  • Storage: In-memory job queue (use Redis for production)

Model Service (Flask + PyTorch)

  • Model: CogVideoX-5B-I2V (THUDM/Tsinghua University) - Latest 2024 model!
  • Framework: PyTorch 2.3+ with CUDA 12.1
  • Features: Prompt-controllable animation, 6-second videos, high quality
  • Optimization: Model CPU offload, VAE slicing & tiling
  • Container: NVIDIA CUDA runtime for GPU access

Frontend (React)

  • Framework: React 18+ with TypeScript
  • Styling: CSS-in-JS with modern gradients
  • Features: Drag-drop, progress tracking, video preview
  • Build: Create React App (can migrate to Vite)

πŸš€ Performance Tips

Faster Generation

  • Use quality=20 (instead of 25-30)
  • Lower FPS (6-7 instead of 8-10)
  • Shorter duration (2s instead of 3-4s)

Better Quality

  • Use quality=35-50 (slower!)
  • Higher FPS (9-10)
  • Lower motion strength for portraits

First Run

  • Model download: ~10-20 minutes
  • Model loading: ~30 seconds
  • First generation: ~2-3 minutes
  • Subsequent: ~1-2 minutes

πŸ“ Environment Variables

Backend (.env)

MODEL_SERVICE_URL=http://model-service:5001  # Docker
# MODEL_SERVICE_URL=http://localhost:5001  # Local

Frontend (.env)

REACT_APP_API_URL=http://localhost:5000

🀝 Credits


πŸ“„ License

This project is for educational and personal use.

Stable Video Diffusion model has its own license from Stability AI.


πŸŽ“ Learn More


Enjoy bringing your photos to life with modern microservices! 🎬✨

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published