Skip to content

HatmanStack/canvas-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS Nova Canvas Image Generation

canvas-demo icon

From Thought - To Concept
Nova Canvas »

An optimized, high-performance Gradio application for advanced image generation using AWS Nova Canvas. This refactored version provides comprehensive image manipulation capabilities with improved error handling, performance optimizations, and better monitoring.

📋 Capabilities

  • Text to Image: Generate images from text prompts
  • Inpainting: Modify specific image areas
  • Outpainting: Extend image boundaries
  • Image Variation: Create image variations
  • Image Conditioning: Generate images based on input image and text
  • Color Guided Content: Create images using reference color palettes
  • Background Removal: Remove image backgrounds
  • Health Monitoring: Real-time system health and performance metrics

🛠 Prerequisites

  • AWS credentials configured (AmazonBedrockFullAccess)
  • HF Token for NSFW content checking (optional)
  • Python >= 3.12
  • Docker (for containerized deployment)

📦 Installation

git clone <repository-url>
cd canvas-demo
pip install -r requirements.txt

⚙️ Configuration

Create a .env file in the root directory:

# AWS Configuration (Lambda-compatible names)
AMP_AWS_ID=<your-aws-access-key>
AMP_AWS_SECRET=<your-aws-secret-key>
AWS_REGION=us-east-1
BUCKET_REGION=us-west-2
NOVA_IMAGE_BUCKET=<your-bucket-name>

# Optional Features
HF_TOKEN=<huggingface-token>
ENABLE_NSFW_CHECK=true
RATE_LIMIT=20
LOG_LEVEL=INFO

# Lambda Configuration (auto-detected)
AWS_LAMBDA_FUNCTION_NAME=<function-name>  # Auto-set in Lambda
AWS_LAMBDA_HTTP_PORT=8080                 # Auto-set in Lambda

🚀 Running the Application

Local Development

python app.py

Docker Deployment

docker build -t canvas-demo.
docker run -p 8080:8080 --env-file .env canvas-demo

AWS Lambda Deployment

The application automatically detects Lambda environment and configures accordingly.

CloudWatch Logging

When deployed to Lambda, all application logs are automatically sent to CloudWatch:

  • Log Group: /aws/lambda/canvas-demo (auto-created by AWS)
  • Log Stream: Canvas-Stream (auto-created by application)
  • Log Format: [timestamp] message
  • Batching: Logs are batched for performance (10 logs or 30 seconds)

To view logs in AWS Console:

  1. Navigate to CloudWatch > Log groups
  2. Select /aws/lambda/canvas-demo
  3. Click on Canvas-Stream log stream

📊 Monitoring & Health Checks

Health Check Endpoint

Access /health for health status or use the "System Info" tab in the UI.

Performance Metrics

  • Request/error rates
  • Memory usage
  • Service health status
  • Rate limiting statistics

🏗 Architecture

src/
├── models/          # Configuration and data models
├── services/        # Business logic and AWS integrations
├── handlers/        # Request handlers and business operations
└── utils/           # Utilities (logging, exceptions, etc.)

Key Components

  • Config Management: src/models/config.py - Centralized configuration
  • AWS Services: src/services/aws_client.py - Optimized AWS client management
  • Image Processing: src/services/image_processor.py - Async image operations
  • Rate Limiting: src/services/rate_limiter.py - Optimized rate limiting
  • Health Monitoring: src/handlers/health.py - System health checks
  • Canvas Operations: src/handlers/canvas_handlers.py - Main business logic

🔧 Technical Details

  • Model: Amazon Nova Canvas (amazon.nova-canvas-v1:0)
  • Prompt Model: Amazon Nova Lite (us.amazon.nova-lite-v1:0)
  • Default Resolution: 1024x1024
  • Supported Formats: PNG, JPG
  • Max Image Size: 4MP (4194304 pixels)
  • Rate Limiting: Configurable (default: 20 requests/20min)

🚨 Error Handling

  • Graceful Degradation: Services continue operating even if non-critical components fail
  • User-Friendly Messages: Clear error messages without technical details
  • Automatic Retries: Intelligent retry logic for transient failures
  • Circuit Breakers: Prevent cascade failures from external services

🔒 Security

  • Input validation and sanitization
  • No credentials in logs
  • Secure error handling
  • Rate limiting protection
  • NSFW content filtering (optional)

📝 License

Apache 2.0 License

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

📞 Support

For issues and questions, please use the GitHub issue tracker.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published