Skip to main content

Generate AI Images in Batches with Google's Imagen

Project description

Imagenation 🎨

PyPI version Python 3.7+ License: BSD-3-Clause

Generate AI Images in Batches with Google's Imagen. Transform text prompts and optional image inputs into stunning visuals, effortlessly.

Banner

Features

  • Text-to-Image: Generate images from text descriptions
  • Text+Image-to-Image: Modify existing images with text prompts
  • CLI Interface: Direct command-line usage
  • Batch Processing: Process multiple images from CSV/JSON files
  • Library Support: Import and use in your Python projects
  • Rate Limiting: Built-in rate limiting with configurable delays to prevent API quota issues

Quick Start

  1. Install dependencies:

    pip install -r requirements.txt
    
  2. Set up API key in .env:

    GOOGLE_API_KEY=your_api_key_here
    
  3. Generate an image:

    ./start.sh -it "A beautiful sunset over mountains" -o sunset.png
    

Usage

Command Line

# Text to image (with default rate limiting)
./start.sh -it "A majestic dragon in a fantasy landscape" -o dragon.png

# Text + image to image  
./start.sh -it "Add a rainbow to this landscape" -ii photo.jpg -o rainbow_photo.png

# Batch processing from CSV
./start.sh --csv batch_data.csv

# Batch processing from JSON
./start.sh --json batch_data.json

# Custom rate limiting for paid tier (faster processing)
./start.sh -it "Beautiful landscape" -o output.png --delay 0.2

# Conservative rate limiting for batch processing
./start.sh --csv large_batch.csv --delay 15.0

Rate Limiting

The tool includes built-in rate limiting to prevent hitting Google API quotas:

  • Default delay: 12 seconds between requests (5 requests/minute for free tier)
  • Custom delay: Use --delay parameter to adjust timing
  • Automatic handling: Built-in wait times and error handling for rate limit errors

Rate Limiting Recommendations

Tier Delay Requests/Minute Use Case
Free 12s (default) 5 Personal use, occasional generation
Paid 0.2s 300 High-volume processing, development
Batch 15s+ 4 Large batch processing, quota conservation

Rate Limiting Examples

# Free tier (default 12s delay)
./start.sh -it "sunset" -o output.png

# Paid tier (faster processing)
./start.sh -it "sunset" -o output.png --delay 0.2

# Batch processing with conservative delay
./start.sh --csv batch.csv --delay 15.0

# Library usage with custom rate limiting
from imagenation import ImagenationGenerator
gen = ImagenationGenerator(rate_limit_delay=0.2)  # 300 RPM

Python Library

from imagenation import ImagenationGenerator

# Initialize generator with custom rate limiting
gen = ImagenationGenerator(rate_limit_delay=0.2)  # 300 RPM for paid tier

# Generate text-to-image
gen.generate_text_to_image("A serene lake at sunset", "lake.png")

# Generate text+image-to-image
gen.generate_text_image_to_image(
    "Make this photo look vintage", 
    "input.jpg", 
    "vintage_output.jpg"
)

Alternative Usage

# Using Python module directly
python -m imagenation -it "Beautiful landscape" -o output.png

# Using original script (backward compatibility)
python imagenation.py -it "Beautiful landscape" -o output.png

File Formats

CSV Format

input_text,input_image_path,output_image_name
"A beautiful sunset","","sunset.png"
"Add a rainbow","landscape.jpg","rainbow_landscape.png"

JSON Format

[
  {
    "input_text": "A beautiful sunset",
    "input_image_path": "",
    "output_image_name": "sunset.png"
  },
  {
    "input_text": "Add a rainbow", 
    "input_image_path": "landscape.jpg",
    "output_image_name": "rainbow_landscape.png"
  }
]

Requirements

  • Python 3.7+
  • Google API key with Gemini access
  • Dependencies: google-genai, pillow, python-dotenv

Project Structure

imagenation/
├── imagenation/           # Main package
│   ├── __init__.py       # Package exports
│   ├── generator.py      # Core generation logic with rate limiting
│   ├── cli.py           # Command-line interface
│   └── __main__.py      # Module entry point
├── imagenation.py        # Backward compatibility script
├── start.sh             # Setup and run script
├── requirements.txt     # Dependencies
├── .env                # API key configuration
└── README.md           # This file

Rate Limiting Details

The tool automatically handles rate limiting to prevent API quota issues:

  • Built-in delays: Automatic wait times between requests
  • Error handling: Graceful handling of 429 rate limit errors
  • Configurable: Adjust timing via --delay parameter or constructor
  • Batch processing: Essential for processing large numbers of images without hitting daily limits

When rate limits are exceeded, the tool provides clear feedback and suggestions for adjusting the delay parameter.


🌊 Made with Good Vibes by Pedro, Claude, and Gemini 🌊

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

imagenation-1.0.1.tar.gz (1.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

imagenation-1.0.1-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file imagenation-1.0.1.tar.gz.

File metadata

  • Download URL: imagenation-1.0.1.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for imagenation-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9bbb738c61621c42d5e4fbf5b1817b1b287e9c4a31051817a79217f0fb7d6b61
MD5 c29165d4e8adce3cdb15abd3cddbd236
BLAKE2b-256 7c57ab371ba58fa9846e92e0de443bef51cc142769573e21d868e7f4c1266ffb

See more details on using hashes here.

File details

Details for the file imagenation-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: imagenation-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for imagenation-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 723df87947b92eed1146fa49c48b2390ac36ad133f3e69e4762178c87ba9bd91
MD5 2398b5a020bfb4573323913c3b45e3a3
BLAKE2b-256 7ace9d2ce27c7543196787e8835d49266c04617a6ad140640171ab85e4c7079c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page