DEV Community

Cover image for Amazon Nova Canvas : opening up new canvases
Rini Susan V S for AWS Community Builders

Posted on • Edited on

Amazon Nova Canvas : opening up new canvases

Background

Amazon Nova is a new generation of foundation models available on Amazon Bedrock. Nova includes four understanding models, two creative content generation models, and one speech-to-speech model. The content generation models include Amazon Nova Canvas for image generation and Amazon Nova Reel for video generation.

Amazon Nova Canvas

Amazon Nova Canvas is an image generation model that creates professional-grade images from text and image inputs. Amazon Nova Canvas is ideal for various applications such as marketing and reporting. It supports features like:

  • Text-to-image generation – Input a text prompt and generate an image as output.
  • Image editing options – inpainting, outpainting, generating variations, and automatic editing.
  • Color-guided content – input a list of hex color codes with a text prompt.
  • Background removal – identifies multiple objects in the input image and removes the background.

Nova Canvas in Amazon Bedrock Playground

It was a fun experience to try out the Nova Canvas model in the Amazon Bedrock playground. Being interested in photography, I wanted to evaluate how realistic the Nova model images were and know if the quality was similar to what Amazon claims.

Below is an image of Yosemite National Park, which I have taken near the Tunnel View point.

Image description

I tried to generate a similar image in Amazon Bedrock Playground, using the Nova Canvas model.

Image description
I was amazed to see how easily we could generate quality images using a few prompts. Yes, the experience of viewing the natural wonder in person is definitely rewarding. But time, effort, and cost factors are low in this option. The Amazon Canvas model can come in handy in case of weekly or monthly newsletters that need to have catchy cover pages or images related to a topic.

Image description

Nova Canvas in Python Notebook

Amazon Nova also provides the option for image generation using Python notebooks, apart from the Bedrock playground. One method of invoking the Amazon Nova models is via the Invoke API. Provided below is the Python code to generate the above image programmatically.

# Install libraries !pip install boto3 # Import necessary libraries import base64 import json import random import boto3 from PIL import Image import io import os # Get AWS Credentials from secrets AWS_ACCESS_KEY_ID=os.getenv('AWS_ACCESS_KEY_ID') AWS_SECRET_ACCESS_KEY=os.getenv('AWS_SECRET_ACCESS_KEY') AWS_DEFAULT_REGION=os.getenv('AWS_DEFAULT_REGION') # Create a Bedrock Runtime client client = boto3.client( "bedrock-runtime", region_name=AWS_DEFAULT_REGION, aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY ) # Set the model ID for Nova Canvas model_id = "amazon.nova-canvas-v1:0" # Define the image generation prompt prompt = "Generate a realistic-looking image of Yosemite from the tunnel view. The picture was taken during the summer season at noon." # Generate a random seed seed = 12 # Format the request payload request_body = { "taskType": "TEXT_IMAGE", "textToImageParams": {"text": prompt}, "imageGenerationConfig": { "seed": seed, "quality": "standard", "height": 1024, "width": 512, "numberOfImages": 1, "cfgScale": 8.0 } } # Invoke the model response = client.invoke_model( body=json.dumps(request_body), modelId=model_id, contentType="application/json", accept="application/json" ) # Parse the response response_body = json.loads(response["body"].read()) image_data = base64.b64decode(response_body["images"][0]) # Save the image output_dir = "generated_images" os.makedirs(output_dir, exist_ok=True) output_path = os.path.join(output_dir, f"nova_canvas_image_{seed}.png") image = Image.open(io.BytesIO(image_data)) image.save(output_path) print(f"Image saved to: {output_path}")` 
Enter fullscreen mode Exit fullscreen mode

Security Guardrails in Amazon Nova

The Nova Canvas model available through Amazon Bedrock comes with integrated security guardrails. Guardrails help evaluate user inputs and model responses based on specific policies and provide safeguards to help build generative AI applications securely.

For example, if you try a non-safe prompt in Nova Canvas, the image won’t be generated, and a warning text message will be displayed as shown below.

Image description

Areas of Improvement

The following are some features of Amazon Nova Canvas model, that needs enhancement

  • Input text size limit [ 1024 characters]
  • Input image size limit [ longest side not exceeding 4096 pixels]
  • No 3D image generation [ currently 2D image generation]

Closing Thoughts

The Amazon Nova Canvas model is an excellent content generation model that can aid in prototyping, social media marketing, and advertising campaigns. It can be easily integrated into Generative AI applications. The security guardrails can ensure that the input prompt and the generated response don’t violate any safety policies. The foundation models are evolving rapidly, and the Amazon Nova Canvas model also has scope to improve.

References

Top comments (0)