DEV Community

Cover image for Get started with Amazon Bedrock for Image Generation - Part 1 Generative AI
Wendy Wong for AWS Heroes

Posted on • Edited on

Get started with Amazon Bedrock for Image Generation - Part 1 Generative AI

Amazon Bedrock is now GA

Amazon Bedrock is a fully managed service that helps you to build generative AI applications with foundation models from AI leaders such as AI21 Labs, Anthropic, Cohere, Meta, Stability AI, and Amazon.

Amazon Bedrock is now generally available since 28 September 2023. In the latest announcement, you will now be able to access Llama 2 and Meta's large language models via Amazon Bedrock API and also use the AWS CLI.

Amazon Bedrock announced by AWS in public preview in April 2023 and also announced at AWS re:Inforce 2023 with the talk Securely build generative AI apps & control data with Amazon Bedrock (APS208).

Learning Objectives

  • Identify the features of Amazon Bedrock
  • Explore the benefits of Amazon Bedrock
  • Identify the common use cases of Amazon Bedrock
  • Understand the solution architecture of Amazon Bedrock
  • Understand pricing and AWS region support
  • Identify real world industry applications of Amazon Bedrock
  • Generate an image using AWS Management Console

Why Amazon Bedrock?

  • Amazon Bedrock is serverless which means that you do not need to manage any IT infrastructure.

  • You may experiment with foundation models without writing any code.

  • You may use your own data and customize foundation models with fine-tuning or retrieval augmented generation (RAG) and use agents to perform complex business tasks.

What are the benefits of Amazon Bedrock?

  • You may access foundation models from leading AI companies like AI21 Labs, Anthropic, Cohere, Meta, Stability AI, and Amazon to build generative AI applications using playgrounds for experiments and also use Amazon Bedrock API to make inference.

  • You may customize the foundation model using your own dataset that can be uploaded into Amazon S3 for both training and testing.

  • You may build agents to perform complex business tasks

  • HIPAA eligibility and GDPR compliance

  • Amazon Bedrock data security ensures that your data in transit and at rest is encrypted allows the use of access keys.

Amazon state that:

You can use AWS PrivateLink with Amazon Bedrock to establish private connectivity between FMs and your Amazon Virtual Private Cloud (Amazon VPC) without exposing your traffic to the Internet.

What are the features of Amazon Bedrock?

This is an overview of Amazon Bedrock below.

overview

The features are outlined in the Amazon Bedrock User Guide and include:

Text playground – A hands-on text generation application in the AWS Management Console.

Image playground – A hands-on image generation application in the console.

playground

Chat playground – A hands-on conversation generation application using the console.

Embeddings – Use the API to generate embeddings from the Titan Embeddings G1 - Text model.

Examples library

You may explore example cases from the examples library.

examplen

What are the AWS supported regions?

The supported regions to get started include US East (N. Virginia), US West (Oregon), Asia Pacific (Singapore) and Asia Pacific (Tokyo).

What is the Pricing for Amazon Bedrock?

There are two pricing models for Amazon Bedrock which are:

On Demand pricing: You pay for your usage and there is no time commitment.

You may refer to details for on-demand pricing here:

  • Text generation models: you are charged for every input token processed and every output token generated.

  • Embeddings models: you are charged for every input token processed. A token is comprised of a few characters and refers to the basic unit that a model learns to understand user input and prompt to generate results.

  • Image generation: you pay for the number of images generated.

Provisioned Throughput pricing: You pay for the time commitment with purchased throughput to run inference on models.

Amazon recommend that provisioned throughput is suited to large workloads.

With Amazon Bedrock pricing, you pay to run inference on any of the third-party foundation models. Pricing is based on the volume of input tokens and output tokens, and on whether you have purchased provisioned throughput for the model.

Provisioned Throughput is charged by the hour, you have the flexibility to choose between 1-month or 6-month commitment terms.

Foundation Models

Base Model

There are a variety of base foundation models for you to choose from that are subject to change. At the moment, you may access the following models:

Amazon Bedrock supports the following models:

  • AI21 Labs: Jurassic-2 Ultra and Jurassic-2 Mid

  • Amazon: Titan Text G1 - Express (limited preview) and Titan Embeddings G1 - Text

  • Anthropic: Claude v1.x, Claude v2.x and Claude Instant v1.x

  • Cohere: Command

  • Stability.ai: Stable Diffusion XL 0.x and Stable Diffusion XL 1.x are in limited preview and you may contact your AWS account manager for more information.

base

Custom Model

You may also bring in your own dataset to customize the models
with hyperparameters epochs, batch size, learning rate, warmup steps to fine tune the model.

  • You may build a foundation model with training data and deploy a fine-tuned model with Amazon Bedrock API.

custom

What are the common use cases?

  • Text generation e.g. write essays and blog posts
  • Virtual Assistants e.g. take user request and perform the tasks
  • Chatbot: for question and answering
  • Search e.g. Search for information from within a document
  • Text Summarization e.g. Summarize the main theme of a book or document
  • Image Generation e.g. generate real-life photos for property brochures

What are the real-world industry applications?

There are a few customer stories from AWS:

  • Adidas: Used Amazon Bedrock to create a generative AI application for helping their community search for answers to questions.

  • Booking.com: Used Amazon Bedrock to build a generative AI application to send destination and accommodation recommendations that was personalized to their customers.

  • Salesforce.com: Salesforce have partnered with AWS to bring your own large language model using Salesforce Data Cloud, this was announced at Salesforce Dreamforce on 11 September 2023.

  • Genesys: Genesys are adopting generative AI, to allow users to access a variety of large language models, such as Genesys-developed models and multiple third-party foundational models through Amazon Bedrock.

Solution Architecture

The solution architecture for image generation using Stable Diffusion on Amazon Bedrock is from the source Amazon Bedrock workshop available on Github

solution

Tutorial: Getting started with Amazon Bedrock with Image Playground

Step 1: Navigate to the AWS Management Console. Login to AWS account as an IAM Admin User.

bedrock dasn

Step 2: In this tutorial we will use AWS region N Virginia (US-east-1).

region

Step 3: Type the word 'Bedrock' into the search bar and navigate to the Amazon Bedrock console and click Get started.

BRD

Step 4: Request model access. Navigate to the third party provider of foundation models e.g. Stability AI and select edit access.
Check the box to select the foundation model and Request Access.
It will take a few minutes to have access granted. Refresh your browser.

access

I selected the foundation model from Stability AI which was Stable Diffusion XL-Preview.

Step 5: Navigate to Image to select the image playground to commence prompting.

Select the image on the left-hand pane.

navigate

Type a word in natural language which is to give a prompt. In the box you may type a few words e.g. Sydney Opera House Real Life Summer.
It will takes a few seconds to create an image.

artist

On the right-handside of the image playground, you may adjust the slider to update the inference configuration to change the output quality of the generated image.

infer

Step 6: You may also download this image that you have generated and use this for your project e.g. blog post, newsletter, post card, document, magazine etc.

Sydney

Step 7: Clean Up Resources

As a best practice, if you no longer need to generate images from your foundation model, please clean up your resources by removing model access from the third party foundation model provider by clicking edit, un-check the box e.g Stability AI and then select Save Changes.

model access

Resources

If you would like to learn more about Amazon Bedrock, I encourage
you to explore to useful resources.

AWS Skill Builder

You may subscribe for a 7-day free trial of AWS Skill Builder for a limited time and complete the 1-hour course Amazon Bedrock Foundations course.

freetrial

Amazon Bedrock Workshop - Github

You may also obtain practical hands-on knowledge of Amazon Bedrock via workshops on Github you will be able to practice with the labs.

github

Conclusion

In this lesson you have learnt how to generate images with foundation models. I hope you will continue to apply prompt engineering to your own use cases.

Until the next lesson - Happy Learning! 😀

References

This Month - AWS Innovate Modern Application - 26 October 2023

You are invited to AWS Innovate Modern Application on 26 October 2023 in the Asia Pacific and Japan regions.

This conference is FREE, register for the keynotes and sign up for various sessions to learn the latest in Generative AI and more.

You may register at this link.
Image description

Next Month - AWS re:Invent 2023 - 27th November to 1st December 2023

In-Person experience

You are invited to AWS re:Invent 2023 in Las Vegas, you may register at this link for an in-person experience. After you register you may navigate to the session catalog and start selecting your sessions and favourite the breakout sessions, chalk talks, keynotes, innovation talks, customer talks, community events and more.

AWS re:invent is also about building your networks and connecting with the AWS Community at PeerTalks

If you need more help with selecting sessions from the catalog, be sure to browse the attendee guides that were written by AWS Heroes and written for you in mind to help you find recommended sessions from generative AI, machine learning, data and analytics, containers, community, devtools, serverless, reliability engineering, storage, sustainability, introverts and enterprise leadership.

You may also browse the agenda to help plan your week.

in person

Live Stream Experience

If you can't make it to Las Vegas this year, you may register for FREE and attend the live stream so that you may also enjoy the keynotes, innovation talks and your free pass will provide you will post conference access to selected breakout sessions. You may register for live streaming.

livestream

Amazon Bedrock announcement - 29 September 2023 by Dr Swami Sivasubramanian the VP of Analytics, Database and Machine Learning

Top comments (0)