Recent enhancements in the field of generative AI, such as media generation technologies, are rapidly changing the way enterprises create and manipulate visual content. Amazon Bedrock is a fully managed service that provides a selection of high-performance foundational models (FM) from leading AI companies, including AI21 Labs, Anthropic, Cohere, Meta, Mistral AI, Stability AI, and Amazon, through a single API. Broad feature set for building generative AI applications with security, privacy, and responsible AI. This provides features such as model customization, fine-tuning, and acquisition augmentation generation (RAG).
Businesses use these features to improve user experience, generate media content such as images, diagrams, infographics, and custom shapes, and increase the level of trust in content generated according to a different or customized model. You may want to understand. , a pre-trained evaluation model using data and parameters from your own organization.
This post shows you how to work with an Amazon Titan Image Generator G1 v2 model on Amazon Bedrock to generate images. Then, learn how to use Anthropic’s Claude 3.5 Sonnet on Amazon Bedrock to describe it, rate it on a scale of 1 to 10, explain the reasoning behind the given score, and suggest improvements to the image. Show. Amazon Titan Image Generator G1 v2 was recently released on Amazon Bedrock, bringing new capabilities to the image generation space. Anthropic’s Claude 3.5 Sonnet is also newly released, setting a new industry benchmark for improved graduate-level reasoning and comprehension of complex instructions.
Amazon Titan Image Generator G1 v2
Exclusive to Amazon Bedrock, the Amazon Titan model incorporates Amazon’s 25 years of experience innovating with AI and machine learning (ML) across its business. It allows content creators to quickly generate high-quality, realistic images using simple English text prompts, returning studio-quality images suitable for advertising, e-commerce, and entertainment.
The newly announced Amazon Titan Image Generator G1 v2 guides you through image creation using reference images, edits existing visuals, removes backgrounds, generates image variations, and maintains brand style and thematic consistency. We have extended the initial version by allowing safe customization of the model.
Human Claude 3.5 Sonnet
Anthropic Claude 3.5 Sonnet raises the bar for industry intelligence, outperforming other generative AI models in a wide range of evaluations, including Anthropic’s most intelligent model to date, Anthropic Claude 3 Opus. The Anthropic Claude 3.5 Sonnet is available from Amazon Bedrock at the speed and cost of the original Anthropic Claude 3 Sonnet model.
Solution overview
This solution is running in AWS Region us-east-1. It exposes an API endpoint through Amazon API Gateway, proxies the initial prompt request to a Python-based AWS Lambda function, and calls Amazon Bedrock twice. The following diagram shows the flow of events.
- A user or application sends a prompt as an API request.
- Prompts and parameters are passed to Amazon Bedrock using the inference API called by the Lambda function.
- Amazon Bedrock generates high-quality images based on Amazon Titan Image Generator G1 v2 prompts.
- The Lambda function sends the image bytes and the original prompt to Anthropic’s Claude 3.5 Sonnet on Amazon Bedrock.
- Anthropic’s Claude 3.5 Sonnet evaluates the generated image against the original prompt.
- The Lambda function stores the image in an Amazon Simple Storage Service (Amazon S3) bucket and generates a signed URL.
- The pre-signed URL and reputation are returned as a JSON-formatted API response.
Ultimately, this function saves the image to an S3 bucket, generates a signed URL, and returns it and the rating summary as an API response.
API Gateway proxies the request to a Lambda function that uses the Python Boto3 library, calls Amazon Titan Image Generator v2 on Amazon Bedrock to generate the image, and decodes the image bytes. It then passes the image and rating prompt through a multimodal call to Anthropic’s Claude 3.5 Sonnet, which, after receiving the score, stores the image in Amazon S3, generates a signed URL, and returns a complete response. Masu.
Prerequisites
The following prerequisites must be met:
- An AWS account to create and manage the AWS resources required for this solution
- Amazon Titan Image Generator G1 v2 and Anthropic Claude 3.5 Sonnet models now available on Amazon Bedrock in AWS Regions
us-east-1
Provision the solution
You can use AWS CloudFormation to build your solution architecture. A single YAML file contains infrastructure such as AWS Identity and Access Management (IAM) users, policies, API methods, S3 buckets, and Lambda function code. To set up solution resources, follow these steps:
- Sign in to the AWS Management Console as an IAM administrator or an appropriate IAM user.
- choose startup stack Deploy the CloudFormation template.
- choose Next.
- in parameters section, type the following:
- The name of the new S3 bucket that will receive the images, e.g.
image-gen-your-initials
) - name of existing S3 bucket where access logs are stored.
- Token used to authenticate the API (selected string)
- The name of the new S3 bucket that will receive the images, e.g.
- After entering the parameters, select Next.
- choose Next Also.
- Review and select Create IAM resource submit.
stack status is CREATE_COMPLETEMove to output Click the tabs to find API information. copy APIID, API URL and Resource ID Please move to a safe location and continue testing.
Test the solution
Once deployed, you can call and test your API in your programming language of choice (Python, React, etc.) using the console, a terminal window, or the AWS Command Line Interface (AWS CLI). In this post, we will review the console, terminal, and AWS CLI. For visual reference, the following image is a rendered representation of an image and its evaluation using Streamlit (Python) and prompts. a black cat in an alleyway with blue eyes.
Please note that your use of Amazon Bedrock is subject to the AWS Responsible AI policy. If an error occurs or if generation or evaluation is blocked, the prompt might conflict with AWS Terms of Service policies or AWS Responsible AI policies. Please try again using a different policy-compliant prompt.
Test your solution using the console
To test your solution using the console:
- In the API Gateway console, select: API in the navigation pane.
- In the API list, select:
BedrockImageGenEval.
- in resource section, select the POST method under /generate-image.
- Please select test Tab for method execution settings.
- in request body section, enter the following JSON structure:
{ “prompt”:”your prompt” }
- choose test.
Test your solution using the AWS CLI
To test your solution using the AWS CLI, make sure you have the latest version installed and configured. For instructions, see Install or Update the Latest Version of the AWS CLI. For configuration information, see Configuring the AWS CLI. Then do the following:
- get. APIID and Resource ID Information saved from the (Output) tab.
- In the environment where you are running the AWS CLI, run the following command.
Test the solution using Terminal
To test your solution using a terminal window, you need to install the curl tool. Once you have it, run the following command:
Whichever you choose, you will receive a response with the following JSON structure:
cleaning
Clean up all AWS resources that you created using CloudFormation to avoid future charges. You can delete these resources using the console or the AWS CLI. To clean up using the console:
- In the Amazon S3 console, empty and delete the S3 bucket you created.
- Select the stack in the CloudFormation console and erase.
conclusion
In this post, you will use Amazon Titan Generator G1 v2 and Anthropic’s Claude 3.5 Sonnet on Amazon Bedrock to generate and evaluate media assets (images) to create accurate, fine-grained, purpose-built content for your users or internal business cases. I explained how. Thanks to the multimodal capabilities of the Amazon Bedrock model, you can apply this solution to different types of media, such as documents, summaries, and translations.
Amazon Bedrock, including how to customize models to use your own data for generation or evaluation, and how to experiment with different models and apply security guardrails to enforce standardized safety controls on generated content. We encourage you to learn and experiment with its features.
About the author
Raul Tavares is a solutions architect specializing in gaming customers across EMEA. With a strong engineering approach, when he’s not deep into cloud architecture, he can be found converting ideas into solutions, writing code samples, or listening to Japanese heavy metal bands to relax. .