Nano Banana is a tutorial project demonstrating how to use Google Gemini API for AI image generation. Through a Discord bot interface, users can:
- 🎨 Text-to-Image - Create images from text descriptions
- 🔄 Image Transformation - Modify existing images based on prompts
- 💬 Discord Integration - Interact via slash commands or messages
- Clean modular architecture (config, API, Discord layers separated)
- Full async programming implementation
- Configuration management with Pydantic
- Complete test coverage (pytest + pytest-asyncio)
- Fast dependency management with uv
- Python 3.13+
- Google Gemini API Key
- Discord Bot Token
# Install uv package manager
pip install uv
# Clone the repository
git clone https://github.com/GDG-NTUST/course-1141-9.git
cd course-1141-9
# Install dependencies
uv syncCreate a .env file:
GOOGLE_API_KEY=your_google_api_key
DISCORD_TOKEN=your_discord_bot_token
DISCORD_GUILD_ID=your_server_id
# Optional settings
LOG_LEVEL=INFO
MODEL_NAME=gemini-2.5-flash-image
SYSTEM_PROMPT=You are a helpful AI assistant.# Start the Discord bot
cd src/
uv run nano_bananaSlash Command:
/draw a cat wearing a hat
Message Interaction:
- Send text messages directly to generate images
- Attach images with text prompts for image transformation
- Reply to messages containing images
cd src/
# Text-to-Image
uv run nano_banana_cli -p "beautiful sunset"
# Image Transformation
uv run nano_banana_cli -p "make it more vibrant" -i image.png
# Multiple Images
uv run nano_banana_cli -p "combine these styles" -i img1.png img2.pngGenerated images are saved in src/nano_banana/api/demo/outputs/
nano_banana/
├── core/
│ └── config.py # Pydantic configuration management
├── api/
│ ├── client.py # Google Gemini API client
│ └── demo/
│ └── demo.py # Command-line demo
└── discord/
├── bot.py # Discord bot
└── utils.py # Utility functions
config.py- Environment variable loading, logging configuration, settings validationclient.py- Async Gemini API client supporting text-to-image and image transformationbot.py- Discord bot handling slash commands and message eventsutils.py- Image download and response handling utilities
# Install development dependencies
uv sync
# Run all tests
uv run pytest
# Run tests with coverage report
uv run pytest --cov=nano_banana --cov-report=html
# Run specific tests
uv run pytest tests/api/test_client.pyTest Coverage:
- ✅ Configuration management (environment variables, validation, defaults)
- ✅ API client (text-to-image, image transformation, error handling)
- ✅ Discord bot (command handling, message listening, image attachments)
- ✅ Utility functions (image download, response formatting)
# Format code
uv run ruff format .
# Run linter
uv run ruff check . --fix- Ruff - Code linting and formatting
- pytest - Testing framework
- pytest-asyncio - Async testing support
- pytest-cov - Test coverage
See pyproject.toml for detailed configuration
| Model Name | Max Images |
|---|---|
gemini-2.5-flash-image |
3 |
gemini-3-pro-image-preview |
14 |
Set MODEL_NAME in .env to switch models.
API Key Error:
- Verify
.envfile exists and is properly formatted - Check if API key is valid and has quota
Discord Bot Not Responding:
- Confirm bot is online
- Check if Discord Token is correct
- Ensure Message Content Intent is enabled
- Verify DISCORD_GUILD_ID is set correctly
Enable Debug Logging:
LOG_LEVEL=DEBUGThis project is licensed under the MIT License
Pull requests and issues are welcome!
Made with ❤️ by GDG NTUST
