Back to Projects

AI Image Generator

A powerful image generation tool using stable diffusion models with an intuitive UI for creating stunning artwork.

January 15, 2024
React TypeScript AI/ML Python
AI Image Generator

AI Image Generator

A powerful web application that leverages Stable Diffusion models to generate stunning AI artwork from text prompts. Built with a modern tech stack focusing on performance and user experience.

Features

  • Text-to-Image Generation: Transform your ideas into visual art
  • Style Transfer: Apply artistic styles to your images
  • Image Enhancement: Upscale and enhance generated images
  • Gallery Mode: Browse and save your creations
  • Batch Processing: Generate multiple variations at once

Architecture

The application follows a microservices architecture:

Latency=i=1n(Tprocess+Tnetwork)\text{Latency} = \sum_{i=1}^{n} (T_{\text{process}} + T_{\text{network}})

Where TprocessT_{\text{process}} represents the processing time for each request and TnetworkT_{\text{network}} accounts for network overhead.

Tech Stack

Frontend

  • React 18 - UI framework
  • TypeScript - Type safety
  • Tailwind CSS - Styling
  • Zustand - State management

Backend

  • Python FastAPI - API server
  • Stable Diffusion - Image generation model
  • Redis - Job queue management
  • PostgreSQL - Data persistence

Model Details

The image generation uses a diffusion process:

xt=αˉtx0+1αˉtϵx_t = \sqrt{\bar{\alpha}_t} x_0 + \sqrt{1 - \bar{\alpha}_t} \epsilon

Where x0x_0 is the original image, ϵ\epsilon is Gaussian noise, and αˉt\bar{\alpha}_t controls the noise schedule.

Screenshots

Dashboard

Main dashboard with generation controls

Gallery

Generated image gallery

Video Demo

Installation

# Clone the repository
git clone https://github.com/yourusername/ai-image-generator.git

# Install dependencies
npm install

# Set up environment variables
cp .env.example .env

# Start the development server
npm run dev

Configuration

The application requires the following environment variables:

OPENAI_API_KEY=your_api_key
DATABASE_URL=postgresql://localhost:5432/ai_images
REDIS_URL=redis://localhost:6379

Performance Optimization

We implemented several optimizations:

  1. Model Quantization: Reduced model size by 4x
  2. Batch Inference: Process multiple prompts simultaneously
  3. Caching: Redis-based caching for repeated prompts
  4. CDN: Image delivery via CloudFlare CDN

Results

After optimization, we achieved:

MetricBeforeAfter
Generation Time12s3.5s
Memory Usage8GB4GB
API Latency500ms120ms

Future Plans

  • Support for video generation
  • Fine-tuning capabilities
  • Mobile app release
  • API for third-party integration

This project was built as part of my exploration into generative AI. Feel free to check out the source code or try the live demo!