Using OpenAI's API to generate prompts for images
April 12, 2023
The advances of artificial intelligence in the last months are simply breath taking. It is now very easy to use “intelligent” APIs in your web app. In this example application the user can describe a scene in simple terms. GPT creates a fully fledged description and DALL-E 2 converts this into an image.
For the input text Shakespeare presents Macbeth
GPT created the description
A stage with a deep red curtain and ornate golden trim. On it stands a tall, imposing figure in dark clothing and a crown. His face is stern and intense, illuminated by a single spotlight. He stands with one arm raised, a symbol of power and authority. Behind him, a large group of people in period costume watch in awe.
in the first step. This description was fed to DALL-E 2 and produced the following image.
It is a pity that - at the point of writing - Midjourney has no public API, because Midjourney produced this stunning image for the same prompt - even without tuning of the prompt:
The application is written in Python using Flask. It uses langchain and the OpenAI API.
The code is available on Github.