Skip to content

learnwithparam/image-generation-provider-pattern

Repository files navigation

Image-to-Image Generation with FLUX and Provider Pattern

learnwithparam.com

Transform photos into coloring book pages using FLUX and GPT Image APIs. Implement the provider pattern for easy model swapping, and optimize with image pre/post-processing pipelines.

Start learning at learnwithparam.com. Regional pricing available with discounts of up to 60%.

What You'll Learn

  • Image-to-image generation models (FLUX Kontext, GPT Image)
  • Provider pattern for multi-model support
  • Image pre/post-processing pipelines
  • Async polling workflows for long-running generation tasks

Tech Stack

  • FastAPI - High-performance async Python web framework
  • FLUX Kontext Pro - Image-to-image generation via Fireworks AI
  • GPT Image - OpenAI's image generation API
  • LLM Provider Pattern - Supports Fireworks, OpenRouter, Gemini, OpenAI
  • Pillow - Image processing and optimization
  • Docker - Containerized development

Getting Started

Prerequisites

  • Python 3.11+
  • uv (installed automatically by make setup)
  • An API key from any supported LLM provider

Quick Start

# One command to set up and run
make dev

# Or step by step:
make setup          # Create .env and install dependencies
# Edit .env with your API key
make run            # Start the FastAPI server

With Docker

make build          # Build the Docker image
make up             # Start the container
make logs           # View logs
make down           # Stop the container

API Documentation

Once running, open http://localhost:8000/docs for the interactive Swagger UI.

Challenges

Work through these incrementally to build the full application:

  1. The "Echo" API - Return an uploaded image as-is to verify the upload pipeline
  2. The First Conversion - Call FLUX to convert an image to a coloring page
  3. The Refactored Provider - Extract image generation into the provider pattern
  4. The Alternative Provider - Add GPT Image as a second provider option
  5. The Optimizer - Add image pre/post-processing (resize, compress, enhance contrast)
  6. The Developer (Bonus) - Build a simple frontend to upload and preview results
  7. The Enhancer (Bonus) - Add prompt engineering for different art styles

Makefile Targets

make help           Show all available commands
make setup          Initial setup (create .env, install deps)
make dev            Setup and run (one command!)
make run            Start FastAPI server
make build          Build Docker image
make up             Start container
make down           Stop container
make clean          Remove venv and cache

Learn more

About

Image-to-Image Generation with FLUX and Provider Pattern - Workshop by learnwithparam.com

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors