Guys.
Here is an amazing crash course on Amazon.
Bedrock.
Uh, many people were requesting for this.
Uh, now, what exactly is Amazon bedrock?
It is the easiest way to build and scale generative AI applications within your AWS platform itself,
right?
Right.
Now many companies are using this.
They are using this because understand one thing that there are so many different, different companies
who are providing LLM models for or LLM models for different different text generation and image generation
task.
Right there is open eye, there is cloudy two.
There is Google, there is even.
Amazon also has its own LM model which is named as Titan.
And similarly there is also Facebook which is like llama two model.
So understand each and every thing is that.
What is the main problem right now if you want to use these APIs, if you want to use these models,
everybody has a different, different setup right now.
What Amazon Bedrock actually provides you.
It provides you one AWS platform where all the models will be available, and through their API calls.
You can probably use any of this kind of models.
Right now, OpenAI is not there, but other than that, I could see almost each and every model that
was available in Amazon bedrock.
Now, why this is important because a single platform here, you don't have to worry about scalability.
You don't have to worry about other things.
Uh, with respect to the cost, that is, uh, uh, in the Amazon bedrock, right?
It is slightly more than the OpenAI.
And probably in the future it may also get reduced, but at the end of the day, you should know what
exactly Amazon Bedrock is.
And probably I'll show you in this particular video different, different tasks.
I will try to code it, and I'll try to show you how you can use these APIs itself.
So here is what is Amazon Bedrock and easiest way to build and scale generative AI application with
Foundation model.
I'll also discuss about what are this foundation models.
As I said, so many different different companies are coming up with some LLM models instead.
So that is the foundation model.
You can do the fine tuning here itself.
You can use any of these models, perform any task, and even directly you can use it in your application
wherever it is required.
Okay, so if I talk about, uh, Amazon Bedrock, it is fully managed service that makes FMS.
That is foundation models from leading AI startup and Amazon available via an API.
So you can choose from a wide range of FMS to find the model that is best suited for your case.
So with bedrock serverless experience, you can start quickly.
Privately customize a FME Foundation model with your own data and easily integrate and deploy them in
your application using AWS tools.
So here you don't have to even worry about the deployment, the scalability, and everything as such.
So, uh, let me just go ahead and click on Get Started.
So this is how it looks like now what all companies it specifically support.
Because I'm also going to show you the entire coding also.
Right how you can use all these models right now in this foundation model.
Uh, there are different different models like from AI 21 labs.
You can see Jurassic two series is there from Amazon.
You have Titan models.
From cloudy you have this cloudy models by Andrew Anthropic.
Uh, you have llama two.
You have stable diffusion by stability AI you have this command by cohere.
So this through this you will be able to perform different different use cases like chat text image.
Right.
And it also provides you hands on lab.
Uh along with that some kind of learning curves, some basic learning course, which you can probably
get started to.
Now here are some of the examples.
Here you can see what all, uh, different different use cases you can solve with respect to different
different models.
Right.
So with the help of Titan text G1, you can see action items from a meeting.
Transcript.
Advanced Q&A with citation.
Uh with llama two chat 13 B right.
This 13 billion parameters you have you can create chain of thoughts.
Then here also you have with 70 billion parameters with cloud you can have character load, role play,
code generation, content generation, contract entity extraction.
Create an image, create an image.
Here you can see creating a table of product description.
Uh, then you have debug code with llama 230 uh 13 billion parameters llama two chat.
Then you have Jurassic, then you have this right.
So as soon as you probably click on anything, let's say I want to go and see that how it is going to
create an image.
So here it is, what it looks like, right?
This is the entire API request that you have to probably call.
And with the help of this this image will be generated let's say I will probably let's see here okay
I can open this in playground and I can give my own.
So HD image of a beach.
So this is the playground where you can with a sunset.
With sunrise, I can basically write like this.
Right.
So as soon as I give this prompt and if I run it, you will be able to see that I'll be able to see
this entire image.
So it actually creates this.
This is from the stable diffusion itself.
Right.
So here you'll be able to see once we wait, it, uh, we'll be able to run it.
And now here you can see this is an amazing image that is created.
And you can use HD image, cinematic display, all different, different things you can probably put
over here.
Uh, I still go with respect to the overviews.
So as I showed all this is there are there examples.
You can probably see all these things are there.
You can go ahead and check out in the playground.
Let's say there is something called as creating table or product description.
Here you can see this is the prompt right.
Sunglasses keywords polarized is this is there.
Let's say this is your table.
You can probably ask any kind of questions and get with respect to the answers also over here right.
So different different use cases is there.
At the end of the day I'll just not show you this APIs.
Now let's go ahead and implement all these things right.
And there steps, some steps which uh we will be seeing completely from scratch again.
Uh, you can use any of these services as such.
Yes.
There is some pricing because at the end of the day you're using some cloud services, right?
It always depends on the tokens that you are specifically getting.
So based on that, Amazon bedrock basically charges you.
So if you want to see the pricing you can probably go ahead over here and right Amazon Bedrock.
And you can click on pricing right.
So bedrock pricing here is the link.
Here you'll be able to see the pricing overview.
Different different pricing is there.
And this is 4000 input tokens right.
Price per thousand.
Output tokens, input tokens output tokens.
So all these prices is there.
You can compare it with OpenAI models and all.
But still this pricing will get reduced as we go ahead.
More custom solutions will probably come up.
Right.
So this is they're all good things.
And you'll also be able to understand uh, see Titan is also having this multi model embeddings.
But at the end of the day we should know that how we can actually create entirely, completely from
scratch.
So let me go ahead and start, uh, this let's see whether I've opened any VSCode or not.
So I will go ahead and start my VSCode.
Um, so let's see over here.
Here is our folder that I've created over here.
Let me rename this to, uh, AWS bedrock.
Okay.
And let me show you.
Okay.
Um, bedrock.
Okay.
And, uh, let me just quickly show you how you can probably start it.
Okay?
So I'll show you the entire setup from starting and all what all things is basically required over here.
And, uh, you also require an IAM key over here itself.
Right.
So first of all, I will open the terminal.
Now after opening the terminal over here, I will open the command prompt.
As usual.
We will go ahead and create a new environment.
That is always a good idea.
Okay.
So for creating a new environment I'll write conda create minus p v n v python double equal to 3.10
with y.
Okay.
So I hope everybody knows about this.
So this will basically create my V and v environment.
And once that environment is created I will activate it.
Till then I will also go ahead and install requirements dot txt.
Okay so once I install requirement dot txt I will be requiring some libraries like Boto3.
So Boto3 is a library which will actually help me to connect all the services that we have in Amazon
bedrock.
Right.
Uh, AWS bedrock also.
So this is some of the things, uh, along with this, uh, I will also go ahead and import or install
AWS CLI.
Right.
So guys, now after creating the environment I will go ahead and activate the environment.
So V and V.
So my environment has been activated.
Now what I'm actually going to do over here I'll save this requirement dot txt.
And then we will go ahead and install these two libraries.
One is pip install pip install minus our requirement dot txt.
So once I specifically install all these requirements one is two two only libraries are required Boto3
and aws cli.
Now the next thing till this requirement is getting installed, we also need to create and IAM user
so that we will be able to configure it with the AWS itself.
Right.
So what I'm actually going to go I'll go and click on the home page okay I will sign into the console
again.
And here I will search for IAM user okay.
So once you go to the IAM user you will be able to see that I will go ahead and create a user itself.
So right now there are multiple users.
So let me do one thing.
Let me go and see the user already.
Krish is created but I will just create one more user let's say test test admin okay so this is the
user that I will specifically create and I will click on.
Next I will say attach policies directly.
I will select this option and I will give the administrator access okay.
So administrator access basically means that we are giving the administrator access itself.
Right.
But again when you are working in the company you will definitely not get this access.
Uh, instead, uh, based on the services that you are specifically using, that access you will get.
Okay.
Um, I will go ahead and create the policy.
So let's see, once I go over here, then it will ask for some permission.
So okay, forget about policies.
Then I will go ahead.
And here you will be able to see that I'll select the next button okay.
After selecting the next button you can see I'm getting the administrator access along with this.
What I will go I'll do.
Go ahead and create the user itself.
Now this is the user that you can see over here test admin right.
And now let me click on this Create access key.
Right.
So I definitely require an access key.
So for that I will go ahead and create this.
Over here you can select Command Line interface.
Since we are going to use it for CLI I will go ahead and click on this I understand and then I will
go ahead and click on the next.
Once I click on the next, you will be able to see that some description value it will ask for.
I will say test key okay.
And let me go ahead and create the access key.
So here you can see I have the access key I have the secret access key.
Now what you can do is that in this particular case you can download this.
Right.
So that later on you will not be able to see this.
So it is a good idea that you download this in the form of CSV file.
So I'll download this in the form of CSV file.
And inside this CSV file I'll get this two values.
One is access key, one is the secret access key.
So let me quickly go ahead and copy this.
And now I will go ahead and configure it.
Right.
We need to configure it over here.
So already you know that we have also made sure that this AWS CLI is available over here.
And it is installed.
Now what we are going to do quickly is that we will go ahead and configure it from the command line.
So let me go ahead and write AWS configure.
Right.
So here you will be able to see it is asking for AWS key ID.
So I will copy and paste it over here.
So I will copy this and I will paste it over here.
Okay.
So once I probably paste it you will be able to see that it will also ask for secret access key.
So here I will copy it.
And let me quickly go ahead and paste it over here.
So here is what I see right now.
You are able to see the access key.
But don't worry, I will delete this as soon as I complete this video.
Now the default region it is basically asking.
So right now it is US East one.
So if I go ahead and see my Amazon bedrock right now where I am pointing to.
So please make sure that you point it to us East one.
If you are not pointing over here, you can basically whatever region you are pointing, you have to
write it over there.
But right now, according to me, I'm going to point it over here, right?
That is with respect to us East one.
Now, one more additional setting you really need to do is that go to the model access.
Because see, initially when you are in this US East one, this model access will not be given.
Right.
So over here you have to access you need to have the status of access granted.
Then only you'll be able to use this specific models.
Now for that when you click on Manage Model access right automatically the selection will come.
And here you will be able to just save the changes here.
One option off activate changes will come.
See in the bottom side like save changes is over here.
So here I've enabled it.
And this access is granted right now.
If it is not granted then this all will be disabled right now.
Right.
So what I will do, just to show you an example, let me just reload this page.
Let me show you whether I have granted some other.
See let's say with respect to Singapore if I'm in Asia Pacific, Singapore region right now, inside
the Singapore region, you will be able to see that.
See, something is not available over here.
Right.
Like this.
Two are not available.
So I will skip Singapore.
Let's go to Tokyo.
Okay.
Just to show you an idea, because I have already activated in US East one.
So if I probably see with this region here, you you'll be able to see this much excess you have available
to a request available to request.
So if I probably click on manage model and if I probably just click on this, let's say these are available
right.
I just need to click on Request Model access.
So for this region only this three models are available.
This two models are available.
So my always suggestion would be that you go to US East one right in US US East one You will be able
to see multiple models like this, right?
Multiple models, you'll be able to see it.
Okay.
So you have to request for the access right.
If I probably you can select us East one also.
Or you can also select US West.
It is up to you.
US West two.
So here also they provide you the access of all the models.
Right.
So understand one thing why I'm showing you all these things.
Because initially you really need to request access.
And this is also what I have requested already.
So here you'll be able to find out more use cases.
Right.
So everything is available right.
But by default I will go ahead and use this US east of N Virginia okay.
So right now again my access is granted.
So you if your access is not granted you have to request for it okay.
So once this is done I will go back to my command prompt here.
The default region is US East one.
So I'll press enter.
This is what I really want.
And default output format I want in the form of JSON.
So I will go ahead and write JSON.
Okay.
So this is the initial setup you really need to do.
Now let's start working on different different models.
So so guys now once we have actually configured now we will go ahead and use any of these models as
an example and we'll try to perform various tasks.
So in this example uh, let me do one thing.
Uh, let me take an example of content generation in cloud.
Okay.
So cloudy cloudy one we can specifically take or uh, let's say I want llama two, you can actually
take llama two.
So it's it's up to you.
So let's first of all start start with this llama two itself.
And for this I'm going to specifically use my Lama 270 billion parameters okay.
The chain of thoughts okay.
And with respect to every model you will be getting some model ID content type.
So this is how is the API request needs to go.
So we'll form this entire API request through our code.
And then we will go ahead and hit this okay.
So let me quickly go ahead and start my coding okay.
So here I will rename this to llama two.
The llama two.
So here is the file guys llama 2.py.
So I will start my code over here.
So first of all let me go ahead and write import Boto3 I'm going to import Boto3 along with it.
I'm also going to import JSON.
Uh the first thing as usual you will be able to see that whenever I see this file writes a chain of
thought over here, I have to create my API request with the help of model name model ID.
Then I need to also put content type, then apply accept.
Then my body should look something like this prompt with all this information.
See uh in lambda two.
So basically your uh your uh prompt uh intro will start with or prompt.
First character will probably start with first word will start with this okay.
It's just like an instruction okay I insist then here you have multiple options.
You can probably see this right here.
Uh you have options like max gen length then temperature, then top P 0.9, something like this okay.
So top P basically means I think it is with respect to the probability.
So let's quickly go ahead and set up that entire command prompt.
So what I will do is that I will copy this entirely okay.
And I will create one JSON okay.
I will write test dot JSON so that I have that format over here.
So this is the JSON.
I have to make sure that I have to put all my API requests in this form.
Okay.
For using Lambda two.
Now quickly I will go ahead and write one prompt underscore data.
I will say, hey, uh, this prompt data, I want to do something like this.
I'll act.
I'll say act as this as, uh, Shakespeare and write a poem on machine learning.
Let's say I this is my prompt that I specifically want to use.
Okay.
Now, the most amazing thing is that Amazon AWS bedrock is quite good.
You know, it provides you easy APIs.
The APIs request, you just need to use it and, uh, start serving it.
Start using it in your application.
So I will first of all go ahead and use this bedrock.
So I will write bedrock is equal to Boto3 dot client.
And then I will specifically use my service underscore name.
Uh service underscore name is equal to.
And I have to give the service name as bedrock or dash runtime.
So this is the first thing that we really need to do.
This is the client name.
Like this is the service name that we really need to use.
And with the help of Boto3, we'll be able to connect to the bedrock itself.
So this is my bedrock over here.
Now the next thing is that I need to form the payload.
Right.
So this will basically be my payload structure as a dictionary.
I will try to find give the values in key value pair.
As usual, if I probably see the test duration.
This is what is my body.
So I need to have in the form of key value pairs.
Prompt is equal to some value.
Then you'll be able to see max gen length, some value temperature, some value top underscore p some
value.
So similarly I will also give my payload in this format.
So here I will write prompt colon.
And here I will go ahead and write I honestly since this is my intro right.
And uh, this intro will be concatenated with my prompt underscore data.
Right.
So this I'm concatenating with my prompt underscore data.
And in the end I have to probably also end this instruction okay.
So this is how my prompt this this prompt body has got created right.
This this is what it has got created.
Right.
Because the prompt will get inserted over here.
Now along with this prompt I need to provide some more different different values.
Right.
What all values I need to provide.
One example is that I'm getting from my API max gen underscore length okay.
And this will also be in the form of key value pairs.
And here I will mention phi to L okay.
And then the next thing is that I will go ahead and write temperature with colon 0.5 comma.
Top underscore p colon 0.9 okay.
So these are my initial values that I've actually set up.
And this is not thing but this is my payload the payload that is specifically going over here.
So once we do this the next thing what I will do this is basically my body.
So I will write body json.dumps I will basically convert this into a JSON and I will use my payload
over here.
Okay.
So once my body is basically created the next thing what I'm actually going to do over here, I'm going
to basically write my model ID and your model ID name.
As usual, the model ID name is this one meta.
This one version one something.
Okay.
So I'll paste it over here.
So this basically becomes my model ID itself.
Now I'll go ahead and create my response.
Now in that response what I need to do I just need to write bedrock, the bedrock object that is created
over here dot invoke invoke underscore model okay.
Now inside this I will give my first parameter.
The first parameter is nothing but body.
The body will be initialized to this specific body itself.
Uh, whatever body we have actually created, the second parameter is nothing but my model ID, so model.
Oops, just a second bedrock.
So I have to use this model id okay.
So this will basically be my second parameter that I really need to give model ID.
And this I will initialize to what we need to initialize to this model ID, right?
So my second parameter is also done.
Body is done.
Model ID is done.
After model id I need to give my accept token as usual.
What is the accept token in test.js on it is nothing but application slash JSON, so I'll paste it over
here.
Oops.
I'll paste it over here.
Done.
The next parameter after this will be nothing, but let me see.
Content type okay, so I have to also give my content type over here.
This will also be my application slash JSON I guess.
Again I'm just seeing this API, so whatever values are there my body is ready.
My accept model ID content type, everything is ready.
These are the four parameters I need to give in my invoke model, right?
What model I'm specifically invoking.
Now, once I get this, uh, you will be able to see that once.
I probably go ahead and write response underscore.
This will basically be my response inside this response.
Understand?
Once I get this specific response, I'll write.
I'll take the body part okay.
So inner part, uh, because there'll be a lot many different different contents that will be coming
up.
So if I write JSON dot loads I will take this value and I will say response dot get.
So inside this there will be a key which will be called as body okay.
Inside that body you will find out entire information of the response that you are able to get.
In this particular case, whatever text I'm writing, act as a secretary and write a poem on machine
learning.
So this is basically my prompt and it will give that specific text inside this body.
Okay.
So I will write this.
Okay.
Um, this body dot read this is done.
Now I will go ahead and print.
I can also print it, but I don't want it.
So let me go ahead and write response underscore text.
Now inside this one thing that you will be able to see that whenever we use llama two.
If you don't know, I've also created videos with respect to llama two, the open source model.
If I use this response underscore body, they will also be a key.
See, inside this body there'll be a body key.
Inside that there will be another key which will be called as generation which will have the entire
text of the response that we want.
Okay.
So I will just go ahead and print this response.
Underscore text.
Done.
Now let's see if everything is working fine or not and whether we will be able to see each and everything.
So this is very simple.
A prompt is over here.
We have invoked the bedrock.
Then there is a payload.
Then here you have this entire body, uh, body I've created in the form of JSON.
Then model ID accept content type.
The main thing is understand this test JSON right.
And then you will be able to do it.
So perfect.
Let's execute this now and let's see whether everything is working fine or not okay.
So I will just go ahead and write Python Llama two.
Oops.
Clear the screen.
Okay.
Python llama 2.py.
Okay.
So it'll take some time again.
Uh, as you all know, uh, some response time it will take with respect to the APIs that we have.
Uh, and again, now we are hitting the specific API from the cloud, uh, from the AWS server itself,
right.
In AWS bedrock.
So, so here is the entire text.
Here you'll be able to see in the fair digital rain where data dot flows free.
A wondrous art dot.
RAR is called machine learning.
You see this is a this is a science, a craft, a mystic spell.
The dot enable machine to learn and tell with algorithm sharp and data set vast.
Our computers do not don't gain wisdom and their insights do not.
Last.
And again based on the token size it will be charging.
Okay, so all the information see you know whatever prompt you want to give over here.
Right.
Let's say I'll go ahead and write what is generative AI like.
Um write a poem on generative AI.
You'll be able to see this.
You'll get some response over here.
So I'll save this.
Now I will go ahead and run it okay.
Now similarly you can actually do it with cloudy too.
You can do it with the stable diffusion.
I'll also show you an example with respect to stable diffusion.
And then you can also explore that uh as said uh now let's go ahead.
Uh, you know, we will try to do it with the help of cloudy two.
And again, uh, with respect to that also, we'll try to see okay.
So this is one text generation.
So here also you can see um, in the realm of code and circularity, a marvel of man's ingenuity, a
creation that not rival the generative.
I wonder to see so all the information are specifically coming over here.
Now let's try another API.
And then after this we will go ahead and try, uh, you know, the image generation with the help of
stable diffusion.
So cloudy.
Uh, let's see where is cloudy.
Cloudy content generation.
Okay.
So so here is my API.
I will copy this.
Um, um.
It is always good to keep a test JSON like this.
Okay, now almost each and everything is same okay I will tell talk about like what?
All changes will basically happen.
Okay, so llama two uh, let me just copy this.
Four lines of code will be almost same.
Then I have my payload.
I will also copy this and then we'll change the payload.
Okay, so we'll change the payload.
So inside this payload you have prompt is equal to human.
You are an expert social media generation.
So whatever prompt basic prompt data right.
So here I don't have to probably create this I don't want this okay.
So this will basically be my prompt data done.
Then let's go with the next parameter.
So what are the next parameter.
La la la la la la la.
Baba baba baba.
Come on guys.
Till then.
Hit like I'm working so much hard here.
Come on.
We we we will.
Okay.
Anthropic version is there.
Stop sequence.
Is there temperature?
Uh, this is there.
Max tokens is there say max token to sample is there?
So let me just quickly go ahead and write what all things I require over here.
So I will go ahead and write.
Max.
Uh, tokens.
Okay.
So this will be 5 to 12, uh, max tokens.
Then I have my temperature.
Then I have my the stop parameter looks something like this.
Okay.
Power point top P will be point eight.
Okay.
Something I'm putting some values.
Temperature.
Let's keep it 2.8.
Let it be more creative okay.
So this is basically my payload okay.
Now everything almost looks same.
Uh, you'll be able to see that I will uh mhm.
Mhm.
Okay.
I think uh there is another one.
Let's see.
Content generation is also there.
This is also there.
Okay fine.
No worries.
Okay.
So I will I think I've used another version.
Let me use another one also which I have already tried.
So it will be looking good okay.
So cloudy two.
So let's quickly go ahead and create my body.
So here you have this one.
So body JSON dumps payload model ID will be this one right.
Bedrock this everything is there body model ID application and content type.
So once we get the response this time when we get the response body okay.
Like this.
When we get this specific body now inside this body you will be able to see that they're in the case
of llama two.
Inside this body we have generation.
But here inside this body we will be having some more steps okay.
So that will be some more, uh, key value pairs.
So here I've written it.
So it will be nothing but completions of zero.
Get data and then get text.
So in completions there it is just like a list of key value pairs.
So I will just take the first one and then probably display the data inside that whatever text is basically
coming.
And then we will go ahead and response underscore text okay.
So now everything works fine I think I've used this model or other model.
So this is version two okay.
In cloudy let's say in cloudy.
Some other version is also there.
Um I don't know from where I found out, but it was available here only.
Advanced Q&A.
Yes, I used I used this one, I guess.
Yeah.
Advanced Q&A.
I used this model ID, I guess.
Okay, perfect.
So once we do this, uh, let's go ahead and run it now.
Now I'll go to my terminal.
Now let's see whether each and every thing will run fine or not.
Once I tried with llama two.
Now I'm tried with cow two.
Right?
So I will write Python cloudy to cloudy.py.
Okay, so here also you'll be able to see the print statement how this was quite fast right.
So here you can see O gentle AI with your boundary power to think and create with no efforts.
So you are specifically getting this specific output also.
So this was with respect to cloudy.
Again you can try anything that you want.
Just take this JSON.
Just try to play with it.
Uh, let's say I take this information only and use this model.
Let's see I will paste it over here.
I will take this entire thing and paste this model.
So here itself I'll change it.
I think cloudy, I may get an error because I don't know whether we are able to manage it or not.
So I sold Access denied.
See?
So this model is not available.
The version one is available I guess.
I think I, I explored this earlier find it somewhere.
If I probably search this you will be able to find it I guess.
Let's see.
But anyhow, you try it out from your end I any I'll be giving you the code Like this.
We are not able to search advanced Q and A and all.
Okay, fine.
Uh, let's start with, uh, I think, uh, c in US why that is not working.
Right.
Because if I go ahead and see the model access, the cloudy model is not available.
C cloudy instant is not available.
So that is the reason that version one was available.
And I was still exploring things.
Right.
And I probably got in that, But no worries, I will now go ahead with stable diffusion.
So let's go to the base model, see version 2.1.
This is all models are specifically there.
If I go to examples uh let's see with respect to stable diffusion.
So 1.2 is there 0.8 is there.
We'll go with the recent one.
And again I will go ahead and copy this okay.
So this will basically be my next text JSON okay.
So I will keep all these things over here itself.
Now let me quickly create one more file.
Save this one more file stable diffusion.
Now here we will try to create an image in AWS itself from AWS dot Pi.
Okay now for stable diffusion.
Also almost all the things will be same.
I've already created the code, but here what I will do, I will just show you what all things I will
do.
See, stable diffusion basically means I have written a prompt data.
See?
Provided me a 4k HD image of beach.
Also use blue sky, rainy season and cinematic display.
Okay, now with respect to this text JSON here you can see body has something called as text prompt.
And then you have text information.
And with respect to the text information this is basically my prompt.
Along with this you have parameters like weight cfg, scale seed, this, this, this is there.
So what I do first of all I will set in that format only.
So first of all I create my prompt template where I have my text my prompt data with weight.
Okay.
So this becomes my entire this information.
Understand this thing right.
You just need to set it.
That's that's it.
Text is equal to this information with weight.
So I've kept it in the form of list with key value pairs.
So that is what I am getting it over here inside this prompt template.
Now I have used butter client I've used the service name runtime.
Now remaining is all my payload.
So inside this whatever payload you require.
See first of all I require text prompt.
The second thing that I require is seed steps width height right.
Width height.
So let me do one thing.
I will change this to 1024.
I will also change it to 1024.
So these are all the parameters I've set.
Step size is nothing but 50.
Width is 1024.
Height is 1024.
So this becomes my entire payload.
I have converted this into JSON.
I've used this model ID because this is the same model id I'm able to get it over here right.
Stability dot stable diffusion X1V1.
It's very simple.
Once you do one right everything will be able to use it.
So here I've used that.
Then I have invoked this model with content type model ID body everything.
Once I get the response.
Now see what response you will get in this format right?
When you probably see the response body there, you'll be getting key value pairs with something called
as artifacts.
Inside that you will find a base 64 encoded response of the images.
So what we did is that we took this particular artifact of zero.
We took that base 64.
We encoded it with UTF eight.
And this is how you read any encoded image right from that encoded image.
We have converted that into bytes.
And then we have saved that particular image to some output directory.
So output directory output folder will get created.
And I am creating one image over here.
Right.
So uh that is what we are specifically doing with respect to this.
Right.
So uh file name will be nothing but inside that particular output directory.
And then we can open that specific image if you want.
Okay.
We are writing that image.
Sorry.
We are writing that image inside this particular PNG.
That is same.
See whatever things we did over here, only the thing that is changing how you converting that bytes
information that we are getting into an image and saving that in our folder.
Okay.
So let me quickly execute and run it and show it to you.
And then you will be able to understand okay.
So here I will be showing you Python stable diffusion dot pi.
So once I execute it here you know okay request steps 400 generation error.
What is this error?
Let's see.
Uh, so okay, there is an error.
Let's see what is the error.
So bedrock invoke invoke model.
Let me see.
I think there was a small minor mistake.
Which one version.
This this this slight entry.
Okay.
And also let me see here.
Yeah.
So now it is working.
I did some minor mistake over there which I have fixed it.
Okay.
So this is the byte information that we are getting.
See the image bytes.
Now if I see my output folder this is my image okay.
So if I go ahead and see find in folder okay sorry I will go ahead and preview in folder reveal in File
Explorer.
So if I go ahead and create this image see this image.
This is how the image is basically created.
And it's look good right.
But what is the prompt I've used over here?
If you see uh, with respect to this, uh, my stable diffusion dot p y here, we have basically created
something like this.
Provide me a 4k HD image of a beach.
So I hope you got an idea with respect to this.
Now in the upcoming videos, what I'll do is that I'll create some amusing projects by using this specific
APIs.
But in short, once I deploy these projects, I can deploy it any way I want, right?
Hugging face spaces anywhere itself.
So my suggestion would be that try as many as you can see different different like character role play.
What is the input prompt you really need to give based on that?
Try to create use cases which will be amazing for you.
Right?
So this was it from my side.
I hope you liked this particular.