How to use DALL·E 2 API in Python - AI Photo Generation for Beginners

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
it is finally here Dali API is now available in public beta open a just announced that Dali API is available even if the Sheep has sailed with a lot of stable diffusion API and demos nevertheless Dali is the first that set the tone so I'm going to show you how you can use Dali API to build your own image generation code using python so in this tutorial we're going to see how to use Dali APA to create your own image generation application using python the first thing that you have to do is read the documentation if you have not the next thing that you have to do is you have to log into the openai.com website so once you log into beta.openai.com you're going to be greeted with this playground page once you reach the playground page go click your profile name and then click view API keys at this point you will not have any APA key unless you have created something before create new secret key I'm going to show you my secret key but I I'm going to just disable the secret key after this video so never ever share your secret key just remember never ever share your secret key now create your secret key once you create it you have to copy it because if you do not copy it you won't be able to view it again so make sure you copy it and then store it somewhere safe I'm going to copy my secret key once I click OK I will never be able to see it and after this video is done I'm going to click this I can revoke my key the first step is to install open AI python Library pip3 install open AI python Library once you have python Library open AI installed and also once you have your API key now it's time for us to code the actual image generation python code the first thing is import open AI import open AI then set the openai dot API underscore key with the key that you have got make sure you do not hard code the API key just like how I have done because this is a demo I want to so to explain even even the beginners how to do it that's why I've shown with the API key on screen but ideally you have to set the environment variable that is what you should do on your machine the next thing is and again if you do not know how to set an environment variable there are lots of tutorials that will tell you either search for environment variable or search for setting um setting up say yeah just search for setting an environment variable either on Windows or Mac you'll get a tutorial very simple the next thing is openai dot model dot list is a very nice way for us to validate whether our authentication has been done so this shows all the models that are available in open AI very popular one gpt3 the Dao NC model if you want you can use that as well but we are now going to stick to Only Image generation so AI image generation how do we do it it is very very simple openai dot image dot create and give the prompt same number of images that you want to generate it and the size of the image that you want to generate it is very very important for you to specify the size because that is a very important aspect of the pricing so you can see the pricing for image models 10 24 by 2024 is 2 cents and 5 12 by 5 12 is 0.018 which is you know um slightly lesser than that and 256 by 256 is 0.016 so it is important for you to select the right resolution for your whatever you want to do and that is that is that is going to have different cost so keep that in mind the second thing is you might ask me who is going to own the image so open AI is said that the r or image that you generate you are going to own it let's see how that goes once it gets deployed but for now we have got a openai DOT image dot create the prompt number of images that we want and then we have the size and a cute panda trying to cook some noodles while drinking while in the space in the space photorealistic 4K Nikon I don't know because I've created a lot of stable diffusion at this point so my prompt style is very stable efficientness but let's see so I've created the image and it is going to give me two images at the end and let's see how the images are going to look like and you are seeing it in real time so we have got two images One image so and we get the image URL so I can copy the image go back to my browser paste it and then I can see the first image see as you can see this is a really high resolution image 10 24 by 1024 and uh the panda is trying to cook noodles not not a very beautiful Panda but it is trying to cook noodles and the second one is again let's see if the panda what is it doing hey Brenda this is it's in the space now I can see it's in this space and it is trying to cook noodles which is um it almost looks like it's sitting on the gas stove and then I'm trying but that's it so you get this object which is an open AI Json object and take this object one you can see the timestamp when it is created if you go inside this object then you can get the URL and then you can do whatever you want you want to display to your customer you want to stay store it somewhere else and I mean the the whatever you want you can do it but to quickly summarize First Step install open AI library next make sure that you have got the authentication done which means you have the API key ready next test your authentication by looking at the model list and then next open AI dot image dot create that will help you create the images that you want using open AI let me know in the comment section open AI Dali is still relevant I'm quite skeptical like how this APA is going to be received given that a lot of stable diffusion AI related products are coming out every other day but nevertheless um Dali is quite popular so let's see how open AI Dali API is going to be received in the market once again just like you said do not hard code your API key never show it to anybody people can misuse it and again when you're going to git commit your code make sure you have hidden the APA key token and all these things just make sure that otherwise this notebook will be linked in the YouTube description please check it out and read the documentation of open AI image generation that has a lot of information about how many images do we allow uh 10 images per minute or 25 images per 5 minutes and if you want to increase the limit what to do cost how to generate a good image how to write a good prompt lot of things and it is not just image generation it can do three things creating image creating edit creating variations I hope this video was helpful to you in learning how to use Dali API to generate AI photos see in the next video
Info
Channel: 1littlecoder
Views: 28,601
Rating: undefined out of 5
Keywords:
Id: S7tOW-xkhjY
Channel Id: undefined
Length: 7min 5sec (425 seconds)
Published: Thu Nov 03 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.