Art Generation with DALL-E and Stable Diffusion
Ever wanted to create art like a professional artist? Struggling with creating good quality prompts for DALL-E? PromptxAI Artist library is here to help.
With PromptxAI Artist library you can generate beautiful random art without even writing a prompt! If you have an idea about a concept, you just need to come up with two or more keywords and AuthorAI Artist will generate a prompt for you. If you know exactly what you want to create, AuthorAI Artist will help you refine the prompt with the right painting style, surface, material, even painting subject and origins to add some character to your painting.
Packages and configuration¶
Let's jump right in. To start with let us import PromptAI Artist API. To render the generated art in Jupyter we need the IPython library. Then we can configure a local folder where the generated art will be saved.
from promptxai import artist
from IPython.display import Image
local = 'generated'
Random art generation¶
Let us begin by generating a random prompt.
prompt = artist.prompt_random_art()
print(prompt)
A single candle illuminates a dark, cobweb-filled room, casting eerie shadows that dance on the walls, The in abstract style on pastel medium drawn on concrete surface
If we like the description generated we continue else we can re-run the cell or for more advanced customizations we can also provide some arguments to the function.
prompt = artist.prompt_random_art(words=50, advanced=True)
print(prompt)
A painting depicting a peaceful night under a starry sky, seen through a window of a cozy cabin surrounded by luscious green fields, in mythological style on acrylic medium which is still life painting drawn on paper surface from mughal origin
Happy with this description, we go on to generate art using DALL-E model in one line of code.
filename = artist.generate_art(prompt, size='1024x1024', folder=local)
print(filename)
generated/A painting depicting a peaceful night under a starry sky, seen through a window of a cozy cabin surrounded by luscious green fields, in mythological style on acrylic medium which is still life painting drawn on paper surface 20230210155926.png
We can now display the generated art saved in our local folder.
Switching to Stable Diffusion¶
Switching models is a breeze with PromptxAI Artist. Just use another function to generate art for the same prompt using the Stable Diffusion model. Note the difference.
filename = artist.generate_art_sd(prompt, size=1024, folder=local)
Prompt engineering¶
Now we are getting inspired! With some ideas floating around in our head we provide a few keywords to our next function to generate a prompt based on these keywords.
prompt = artist.generate_prompt(['Galaxy', 'Dream', 'Planets'])
print(prompt)
An oil painting that captures the beauty of a dream-like night sky, with galaxies, planets, and stars twinkling and swirling in the velvet darkness. An ethereal sight, this captivating painting shows the wondrous beauty of the vast universe, and its seemingly infinite possibilities.
Let us capture the generated prompt in an Art object.
art = artist.Art()
art.set_description(prompt)
How would you like to paint this concept? We can lookup basic art styles, materials, and surfaces like so.
print(art.painting_basics)
{'style': ['realism', 'photorealism', 'expressionism', 'impressionism', 'abstract', 'surrealism', 'pop art', 'symbolist', 'artivism', 'religious', 'mythological', 'modernism', 'outsider'], 'medium': ['oil', 'watercolour', 'acrylic', 'gouache', 'pastel', 'encaustic', 'fresco', 'spray paint', 'digital', 'hot wax', 'ink', 'enamel', 'tempera', 'matte'], 'surface': ['walls', 'paper', 'canvas', 'wood', 'glass', 'lacquer', 'pottery', 'leaf', 'copper', 'concrete']}
Let us say we want to learn more about one of the style concepts from a professional artist. How does it go with a medium and surface?
print(artist.help(medium='surrealism'))
The best painting style and surface to paint with surrealism medium is acrylic on canvas. Acrylic paint is a versatile medium that can be used to create a variety of effects, from a realistic look to a more abstract, surrealistic style. Canvas provides a sturdy surface that is ideal for painting with acrylics, and the texture of the canvas can be used to add visual interest to the painting.
You can ask for help with any combination of medium, surface, material, subject, or origin specified. For now let us take the expert advice and refine our prompt.
art.set_basics(style='surrealism', medium='acrylic', surface='ncanvas')
We can also lookup advanced concepts.
print(art.painting_advanced)
{'subject': ['history painting', 'concept art', 'portrait painting', 'genre painting', 'landscape painting', 'still life painting'], 'origin': ['indian', 'japanese', 'chinese', 'islamic', 'indonesian', 'mughal']}
And learn more about these to add to our prompt.
print(artist.help(origin='indian'))
A traditional Indian painting style called Madhubani, which uses a medium of bright, vibrant colors and a surface of handmade paper or canvas, would be a great match for Indian origin.
art.set_advanced(origin='indian')
We are not ready to generate our prompt with the description generated earlier and the style, medium, surface, and origin stored in our Art object.
prompt = artist.prompt_art(art)
print(prompt)
An oil painting that captures the beauty of a dream-like night sky, with galaxies, planets, and stars twinkling and swirling in the velvet darkness. An ethereal sight, this captivating painting shows the wondrous beauty of the vast universe, and its seemingly infinite possibilities. in surrealism style on acrylic medium drawn on ncanvas surface from indian origin
Let us generate the art like we did before.
filename = artist.generate_art(prompt, size='1024x1024', folder=local)
print(filename)
generated/An oil painting that captures the beauty of a dream-like night sky, with galaxies, planets, and stars twinkling and swirling in the velvet darkness. An ethereal sight, this captivating painting shows the wondrous beauty of th 20230210160140.png