Skip to content

giolaq/gio-comic

Repository files navigation

Comic Generator Agent 🎨

An AI-powered comic creation system using Strands Agents and Nano Banana Pro (Gemini 3 Pro Image)

Generate professional-quality comics from natural language descriptions using Google's state-of-the-art image generation model and the Strands Agents framework.

Features

  • 🤖 Intelligent Agent: Uses Strands framework for smart task orchestration
  • 🎨 Nano Banana Pro: Powered by Gemini 3 Pro Image for high-quality visuals
  • 📚 Multi-Panel Comics: Create single panels or complete comic pages
  • 💬 Text Overlays: Add speech bubbles and captions automatically
  • 🎭 Style Customization: Choose from various art styles and formats
  • Async Support: Generate comics with streaming or async patterns

Quick Start

Prerequisites

Installation

  1. Clone and navigate to the project

    cd gio-comics
  2. Set up virtual environment

    python3 -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Configure API key

    cp .env.example .env
    # Edit .env and add your GOOGLE_API_KEY
  5. Verify installation

    python demo.py

Usage

Basic Example

from comic_agent import ComicGeneratorAgent

# Initialize the agent
agent = ComicGeneratorAgent()

# Generate a comic
result = agent.create_comic("""
    Create a 3-panel comic about a robot discovering emotions:
    Panel 1: Robot analyzing data in a sterile lab
    Panel 2: Robot encounters a friendly kitten
    Panel 3: Robot experiencing joy for the first time
    Style: Warm colors, heartwarming, clean illustration
""")

print(result)
# Comics saved to: output/panel_01.png, output/panel_02.png, etc.

Interactive Mode

python examples/interactive.py

Then enter your comic ideas:

> Create a 4-panel superhero origin story
> Make a funny comic about a cat and a laser pointer
> Generate a manga-style battle scene

Pre-built Examples

# Simple robot comic (recommended first test)
python examples/simple_comic.py

# Noir detective comic with custom panels
python examples/custom_panels.py

# Real-time streaming generation
python examples/streaming_example.py

API Reference

ComicGeneratorAgent

Initialize the comic generator with custom configuration.

agent = ComicGeneratorAgent(
    api_key="your_key",           # Optional: defaults to env var
    model_id="gemini-2.5-flash"   # Optional: Gemini model to use
)

Methods

create_comic(prompt: str) -> str

Generate a comic synchronously.

response = agent.create_comic("Create a 2-panel comic about a wizard")

create_comic_async(prompt: str) -> str

Generate a comic asynchronously.

response = await agent.create_comic_async("Create a space adventure comic")

create_comic_streaming(prompt: str)

Generate with real-time streaming updates.

async for event in agent.create_comic_streaming("Create a fantasy comic"):
    # Process streaming events
    pass

Available Tools

The agent has access to specialized comic creation tools:

Tool Description Parameters
generate_comic_panel Create a single panel panel_description, panel_number, aspect_ratio, image_size, style
create_text_overlay Add text to panels panel_path, text, position, font_size
combine_panels Merge panels into a page panel_paths, layout, output_name
generate_complete_comic Full multi-panel generation story_description, num_panels, aspect_ratio, style

Configuration

Environment Variables

Create a .env file in the project root:

GOOGLE_API_KEY=your_google_ai_api_key_here

Model Configuration

Default model: gemini-2.5-flash (recommended for best balance of quality and speed)

Available models:

  • gemini-2.5-pro - Highest quality, slower
  • gemini-2.5-flash - Best balance (default)
  • gemini-2.5-flash-lite - Fastest, most economical

Image Generation Settings

Customize in comic_tools.py:

# Aspect ratios: "1:1", "16:9", "9:16", "4:3", "3:4"
# Image sizes: "1K", "2K", "4K"

Project Structure

gio-comics/
├── comic_agent.py           # Main agent implementation
├── comic_tools.py           # Nano Banana Pro tools
├── demo.py                  # Quick test script
├── requirements.txt         # Python dependencies
├── .env                     # API keys (create from .env.example)
├── examples/                # Usage examples
│   ├── simple_comic.py      # Basic example
│   ├── custom_panels.py     # Advanced panel control
│   ├── interactive.py       # Interactive CLI
│   └── streaming_example.py # Streaming demo
├── output/                  # Generated comics (auto-created)
├── test_setup.py            # Installation validator
└── test_agent.py            # Agent tests

Examples

Different Art Styles

# Comic book style
agent.create_comic("""
    Create a 3-panel superhero comic in classic comic book style
    with bold outlines, vibrant colors, and dynamic action
""")

# Manga style
agent.create_comic("""
    Create a 4-panel manga-style comic with dramatic expressions,
    speed lines, and typical manga panel layouts
""")

# Watercolor
agent.create_comic("""
    Create a 2-panel comic in soft watercolor style with
    gentle colors and flowing artistic elements
""")

Detailed Panel Control

agent.create_comic("""
    Create a 3-panel noir detective comic:

    Panel 1 (Close-up): Detective's face half in shadow,
    rain visible through window, cigarette smoke curling up,
    dramatic lighting with venetian blind shadows

    Panel 2 (Wide shot): Dark alley at night, rain pouring,
    mysterious figure in long coat under flickering streetlight,
    puddles reflecting the light

    Panel 3 (Over-shoulder): Detective looking at evidence
    photos on desk, dramatic desk lamp creating stark shadows,
    noir atmosphere

    Style: Film noir with high contrast black and white
""")

Troubleshooting

Common Issues

API Key Not Found

❌ Error: Google API key not found

Solution:

# Check .env file exists
ls -la .env

# Verify content
cat .env
# Should show: GOOGLE_API_KEY=your_key_here

Rate Limit Exceeded

❌ Error: 429 RESOURCE_EXHAUSTED

Solution:

  • Wait 1-2 minutes (free tier has rate limits)
  • Monitor usage: https://ai.dev/usage
  • Consider upgrading to paid tier

Interactive Mode EOFError

❌ EOFError: EOF when reading a line

Solution: Run in an actual terminal, not through automation:

python examples/interactive.py
# Then type your prompts

Import Errors

❌ ModuleNotFoundError: No module named 'strands'

Solution:

# Ensure virtual environment is activated
source venv/bin/activate

# Reinstall dependencies
pip install -r requirements.txt

Validation

Run the test suite to verify everything works:

# Validate installation
python test_setup.py

# Test agent functionality
python test_agent.py

# Quick demo
python demo.py

Best Practices

Writing Effective Prompts

Good:

Create a 3-panel comic:
Panel 1: Young wizard discovers ancient spellbook in dusty library
Panel 2: Wizard attempts first spell, magical energy swirling
Panel 3: Spell goes hilariously wrong, books flying everywhere
Style: Colorful fantasy art with magical effects

Less effective:

Make a wizard comic

Tips for Great Results

  1. Be specific - Describe characters, settings, emotions, and actions
  2. Use camera angles - "close-up", "wide shot", "bird's eye view"
  3. Specify mood - Lighting, weather, atmosphere
  4. Choose art style - Comic book, manga, watercolor, noir, etc.
  5. Start simple - Try 2-3 panels first, then expand

Technical Details

Architecture

┌─────────────────────────────────────┐
│   Comic Generator Agent (Strands)  │
│   - Natural language understanding  │
│   - Tool orchestration             │
│   - Story planning                 │
└────────────┬────────────────────────┘
             │
             ├─> generate_comic_panel
             ├─> create_text_overlay
             ├─> combine_panels
             └─> generate_complete_comic
                       │
                       ↓
             ┌─────────────────────┐
             │  Nano Banana Pro    │
             │  (Gemini 3 Pro)     │
             │  - Image generation │
             │  - Text rendering   │
             └─────────────────────┘

Dependencies

  • strands-agents[gemini] - Agent framework with Gemini support
  • google-genai - Google AI API client
  • pillow - Image manipulation
  • python-dotenv - Environment management

Performance

  • Generation time: 5-15 seconds per panel (varies by complexity)
  • Resolution: Up to 4K (configurable)
  • Rate limits: Free tier allows ~15 RPM (requests per minute)

Resources

Documentation

Community

  • Report issues: Create an issue in this repository
  • Feature requests: Open a discussion
  • Examples: Check the examples/ directory

Development

Running Tests

# Installation validation
python test_setup.py

# Agent functionality
python test_agent.py

# All examples
for script in examples/*.py; do
    echo "Testing $script..."
    python "$script"
done

Code Quality

The project follows these principles:

  • Clean, readable code
  • Type hints for better IDE support
  • Comprehensive error handling
  • Detailed documentation

License

MIT License - See LICENSE file for details

Acknowledgments

  • Strands Agents - Powerful agent framework
  • Google DeepMind - Nano Banana Pro (Gemini 3 Pro Image)
  • Anthropic - Claude for development assistance

Contributing

Contributions are welcome! Areas for improvement:

  • Additional art styles
  • More panel layout options
  • Enhanced text rendering
  • Character consistency across panels
  • Story template library

Made with ❤️ using Strands Agents and Nano Banana Pro

About

A Comic generator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published