From the course: Building a Project with the ChatGPT API
Solution: Generate images using images API - ChatGPT Tutorial
From the course: Building a Project with the ChatGPT API
Solution: Generate images using images API
(upbeat music) - [Instructor] Time to solve our challenge. Let's look at how I solved our prompt of generating a custom image based on the summarized website. You're familiar with the code that installs the needed libraries, pulls the API key from the environment variable, collects the messages of the multi-turn conversation, and gets the completion. This code manages the multi-turn conversation, allowing the user to enter a website to summarize. I've added a new function called generate_image that takes in the summary and passes it into the prompt parameter. I also use the n parameter to indicate that I want one image generated. For the size parameter, I'm passing the value of 1024 by 1024. I'm storing the URL in the image_url variable here on line 15. I've started the multi-turn conversation already, so let me enter the website to summarize. So, it's off thinking, summarizing the website, we have our response. Now I'm going to ask it to shorten the summary, and that was fast. It came back with a shorter summary. And lastly, I'm going to ask it to describe an image that represents that summary in five words or less. And it came up with "Skills for career growth." Let's exit this. After the multi-turn conversation completes, I call the generate_image function and I store the response in the url variable. I use Python's Image Library to display the image in line, and here is the image that was generated. I think this is a really cool image, and it works perfectly for the use case. My version of the solution is pretty straightforward. Yours probably look similar to mine, but don't worry if it didn't. There are always multiple ways to solve the same problem. Now, let's learn about what comes next for our application, integrating with the Twitter or X API. I'll see you in the next video.