Amazon Nova Canvas: AI-Powered Image Generation with AWS Bedrock
Amazon Nova Canvas is a powerful image generation application that leverages AWS Bedrock's image generation capabilities through a user-friendly Streamlit interface. The application enables users to create, manipulate, and customize images using advanced AI models with features like text-to-image generation, color-guided generation, and image-guided generation.
The application provides a comprehensive set of controls for image generation parameters including quality settings, dimensions, and prompt adherence. It supports multiple generation modes to accommodate different creative needs - from simple text prompts to sophisticated image variations guided by reference images or color palettes. All generated images and associated metadata are automatically saved and can be downloaded directly from the interface.
Image Engineering Project Demo
Repository Structure
.
├── amazon_image_gen.py # Core image generation class using AWS Bedrock API
├── amazon_image_streamlit_app.py # Main Streamlit application interface
├── output/ # Generated images and metadata storage
│ └── [timestamp]/ # Timestamped output directories containing:
│ ├── request.json # Generation request parameters
│ ├── response_body.json # API response with generated images
│ └── response_metadata.json# AWS response metadata
└── streamlit_requirements.txt # Python package dependencies
Usage Instructions
Prerequisites
- Python 3.7 or higher
- AWS account with Bedrock access
- AWS credentials configured locally
- Required Python packages:
- boto3 >= 1.33.8
- Pillow >= 10.1.0
- ipywidgets >= 8.1.5
- streamlit >= 1.30.0
Installation
Clone the repository:
git clone https://github.com/mohamednizzad/image-engeering-with-amazon-nova-canvas.git
cd image-engeering-with-amazon-nova-canvas
Install dependencies:
pip install -r streamlit_requirements.txt
Configure AWS credentials:
aws configure
Quick Start
Launch the Streamlit application:
streamlit run amazon_image_streamlit_app.py
Select a generation feature from the sidebar:
- Simple Image Generation
- Color-Guided Generation
- Image-Guided Generation
- Instant Customization
- Background Replacement
Configure generation parameters:
- Image quality (standard/premium)
- Dimensions (width/height)
- CFG Scale (prompt adherence)
- Number of images
- Seed value
Enter your prompt and generate images
GitHub Repository
- Check GitHub Repository:- Repo
More Detailed Examples
Simple Image Generation
# Example text prompt
text_prompt = "A beautiful landscape with mountains and a lake at sunset"
negative_prompt = "clouds, people, text"
# Configure parameters
inference_params = {
"taskType": "TEXT_IMAGE",
"textToImageParams": {
"text": text_prompt,
"negativeText": negative_prompt,
},
"imageGenerationConfig": {
"numberOfImages": 1,
"quality": "standard",
"width": 1024,
"height": 768,
"cfgScale": 7.0,
"seed": 123456
}
}
Color-Guided Generation
# Example with color guidance
inference_params = {
"taskType": "COLOR_GUIDED_GENERATION",
"colorGuidedGenerationParams": {
"text": "digital painting of a landscape",
"colors": ["#81FC81", "#386739", "#C9D688"]
},
"imageGenerationConfig": {
"numberOfImages": 1,
"quality": "standard",
"width": 1024,
"height": 768
}
}
Troubleshooting
Common Issues:
-
AWS Credentials Error
- Error: "Failed to initialize AWS Bedrock client"
- Solution: Verify AWS credentials in ~/.aws/credentials
- Check region configuration in ~/.aws/config
-
Image Generation Timeout
- Error: "Read timeout error"
- Solution: Adjust the boto3 client timeout in config
- Default timeout is 300 seconds for multiple images
-
Validation Errors
- Error: "Malformed input request"
- Solution: Ensure all required parameters are provided
- Check minimum length requirements for text prompts
Debug Mode:
import logging
logging.basicConfig(level=logging.DEBUG)
Data Flow
The application processes image generation requests through AWS Bedrock's API, handling both text-to-image and image-to-image transformations. The system manages request parameters, API communication, and response processing while maintaining a persistent output structure.
[User Input] -> [Streamlit Interface] -> [BedrockImageGenerator]
|
[AWS Bedrock API]
|
[Output Directory] <- [Response Processing] <- [Generated Images]
Key Component Interactions:
- User input captured through Streamlit interface
- Parameters validated and formatted for AWS Bedrock
- BedrockImageGenerator handles AWS API communication
- Generated images saved to timestamped directories
- Response metadata logged for tracking
- Images displayed in interface with download options
- Error handling and validation at each step
@mohamednizzad Impressive work Sir, This project is a standout example of how to leverage AWS Bedrock effectively for real world image engineering. The integration with Streamlit makes the tool both powerful and accessible, especially with support for text, color, and image guided generation modes. I really appreciate the thoughtful touches like metadata logging, configurable quality settings, and seamless export functionality which show a deep understanding of both developer and user needs. This will be incredibly valuable for creatives, researchers, and developers alike. Looking forward to seeing how this evolves.