A sophisticated AI-powered image editing platform that combines conversational AI with advanced image generation capabilities. Transform your images through natural language interactions with an intelligent assistant.
AI Image Editor is a full-stack application consisting of a modern Next.js frontend and a powerful Python FastAPI backend. The frontend provides an intuitive chat interface for image editing, while the backend handles AI processing, image generation, and intelligent prompt refinement.
Live Demo: img-edit-agent-flax.vercel.app/ π
β οΈ Note: The agent might take time to boot up if unused for an extended period of time.
Video Demo: Google Drive
I created this project with a clear and simple motivation: to build a genuinely easy-to-use, high-quality AI image editor that puts convenience first. Existing tools like ChatGPT or Gemini are powerful, but they are primarily designed for conversations rather than image editing. My goal was to focus entirely on the editing experience β prioritizing simplicity, a smooth user flow, and removing unnecessary complexity. This project is my attempt to make AI-driven image editing more accessible, direct, and enjoyable.
- Conversational Interface: Chat with Pablo, your AI assistant, to describe image edits in natural language
- Multi-Image Support: Select and reference multiple images for complex editing tasks
- Smart Prompt Refinement: AI automatically enhances your prompts for better results
- Real-time Generation: Get instant feedback and generated images during conversations
- Responsive Design: Beautiful, adaptive interface with glassmorphism effects that works seamlessly on both desktop and mobile
- Image Gallery: Upload, organize, and manage your image collection
- Image Upload: Seamless image upload with AWS S3 integration
- Secure Access: Time-limited presigned URLs for secure image access
- Real-time Chat: Interactive chat interface with markdown support
- Sample Images: Curated collection of example images to get started
- Auto-scroll Navigation: Smooth image gallery navigation with arrow controls
- LLM Integration: Advanced language model for understanding and processing requests
- Image Generation: Powered by Replicate's state-of-the-art models
- Prompt Engineering: Sophisticated prompt optimization and enhancement techniques
- PostgreSQL Managed Database: Robust connection management with Neon optimization
- Rate Limiting: Built-in usage controls and IP-based generation limits
- Connection Management: Automatic reconnection and health monitoring for database
- Health Monitoring: Comprehensive health checks and status reporting
- Modular Architecture: Clean separation of concerns with dedicated LLM tools
- Auto-Deployment: CI/CD pipelines for both frontend and backend
- Cloud Storage: AWS S3 integration for secure image storage
- Scalable Architecture: Designed for high availability and performance
- Environment Management: Proper configuration for development and production
- User uploads image β Next.js β AWS S3 (direct upload)
- User sends chat message β Next.js β Python API β PostgreSQL
- AI processes request β Python API β LangChain Agent β Replicate API Call β AWS S3
- Image displayed β Next.js β AWS S3 (direct download)
- Chat response β Python API β Next.js (with image URL)
img-edit-agent/
βββ src/ # Next.js Frontend Application
β βββ app/ # App Router pages and layouts
β βββ lib/ # Server actions and utilities
β βββ ui/ # Reusable UI components
β βββ types.ts # TypeScript type definitions
βββ api/ # Python FastAPI Backend
β βββ server/ # FastAPI application
β βββ llm/ # LLM agent and tools
β βββ tests/ # Comprehensive test suite
β βββ Dockerfile # Container configuration
βββ public/ # Static assets
βββ .github/workflows/ # CI/CD pipelines
βββ README.md # This file
- Node.js 20+ and pnpm (for frontend)
- Python 3.12+ (for backend)
- AWS S3 bucket (for image storage)
- Replicate API key (for image generation)
- PostgreSQL database (Neon recommended for free tier)
# Install dependencies
pnpm install
# Start development server
pnpm dev
The frontend will be available at http://localhost:3000
# Navigate to API directory
cd api
# Install dependencies
pip install -e .[dev]
# Start the API server
uvicorn server.main:app --host 0.0.0.0 --port 8000
The API will be available at http://localhost:8000
-
For the Next.js app, create
.env
in the root directory following the example from.env.example
:HF_API_URL=YOUR_HF_API_URL AWS_REGION=us-east-1 AWS_ACCESS_KEY_ID=your_access_key_here AWS_SECRET_ACCESS_KEY=your_secret_key_here AWS_S3_BUCKET_NAME=your-bucket-name-here
-
For the Python API, create
.env
in theapi
directory following the example fromapi/.env.example
:REPLICATE_API_TOKEN=YOUR_REPLICATE_API_TOKEN GOOGLE_API_KEY=YOUR_GOOGLE_API_KEY DATABASE_URL=YOUR_DATABASE_URL AWS_REGION=us-east-1 AWS_ACCESS_KEY_ID=your_access_key_here AWS_SECRET_ACCESS_KEY=your_secret_key_here AWS_S3_BUCKET_NAME=your-bucket-name-here
# Run tests
pnpm test
# Lint code
pnpm lint
# Build for production
pnpm build
cd api
# Run tests
python -m pytest tests/ -v
# Run tests with database
python -m pytest tests/ -v -m 'database'
# Run all tests
python -m pytest tests/ -v -m 'not database'
The Next.js application is automatically deployed to Vercel via GitHub Actions:
- Trigger: Push to
main
branch with changes tosrc/
directory - URL: img-edit-agent-flax.vercel.app/
- Features: Automatic builds, preview deployments, and analytics
The Python API is deployed to Hugging Face Spaces using Docker automatically via GitHub Actions:
- Trigger: Push to
main
branch with changes toapi/
directory - URL: huggingface.co/spaces/codinglabsong/img-edit-agent-api
- Features: Containerized deployment, automatic scaling, and health monitoring
See DEPLOYMENT.md
for detailed deployment instructions.
POST /chat
Send a message to the AI assistant with optional image references.
{
"message": "Make this image more vibrant and colorful",
"selected_images": [
{
"id": "image_123",
"url": "https://...",
"title": "My Photo",
"description": "A beautiful landscape"
}
],
"user_id": "user_456"
}
Response:
{
"response": "I'll enhance the vibrancy and colors in your image...",
"status": "success",
"generated_image": {
"id": "gen_789",
"url": "https://...",
"title": "Enhanced Image",
"description": "Vibrant and colorful version"
}
}
GET /health
Returns the API status and database connectivity.
- Unit Tests: Component testing with Vitest
- Integration Tests: API integration testing
- E2E Tests: User workflow testing
- API Tests: Endpoint testing with pytest
- LLM Tests: Agent and tool testing
- Database Tests: Data persistence testing
- Rate Limiting: IP-based generation limits (10 images/week)
- Input Validation: Comprehensive request validation
- Error Handling: Graceful error handling and fallbacks
- CORS Configuration: Secure cross-origin requests
- Environment Variables: Secure configuration management
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under a custom Non-Commercial MIT-Style License - see the LICENSE file for details.
- Replicate for powerful image generation models
- Hugging Face for hosting infrastructure
- Vercel for frontend deployment
- AWS for cloud storage services
Built with β€οΈ using Next.js, FastAPI, and AI