DEV Community

Cover image for ''PaintByLetters... Prepping & Illuminating the Canvas of Creativity with the Power of Prompts"
salvat36
salvat36

Posted on

''PaintByLetters... Prepping & Illuminating the Canvas of Creativity with the Power of Prompts"

Introduction:
In the realm of AI, just as in coding, cooking, and various other aspects of life, the final product's quality depends heavily on the ingredients used. Interacting with AI models is no exception. This blog delves into the fascinating world of Text-To-Image (TTI) generation, where the magic of thorough prompts plays a pivotal role in enhancing the quality and creativity of AI-generated images. By providing clear instructions, context, and constraints, we unlock the full potential of AI systems to craft mesmerizing visual wonders. Through practical examples and code snippets, we'll illuminate the transformative potential of crafting precise prompts that breathe life into AI-generated art.

Getting Started:
To embark on this creative journey, let's start by setting up our environment and installing the necessary dependencies for AI communication.

Step One: Get your openai secret key necessary to access their api.
To do this: you can navigate to their website under the api-reference. You'll need to first either signup or create an account.
Upon logging in you can navigate to View API Keys under your profile menu. (Click on your username in the top-right corner to access).

In this case, you may have noticed the link above actually brings you directly to the api/reference guide as well. Please make sure to look through the documentation for the installation and AI Model that best suites your needs. In this case, we'll be using the openAI Image Models import through python.

Step Two: Import openai
import openai

Step Three: Install open ai package (Python in our case)
pipenv install openai

Step Four: We have to set our API secret key. In this case, it's best to create a .env file and store the key there for security concerns. In which case, we'd simply instantiate our app with the key from .env.
opena.api_key = environ.get('yourkeyhere')

Step Five: Defining your prompt using openai's create image method.

openai.Image.create(
prompt = 'Spill your descriptive genius here'
n=1, <Define the # of Images in the response>
size='1024x1024'  <Define the image size>
Enter fullscreen mode Exit fullscreen mode

Step Five: Wait for the magic to happen!
Right now, one of the brightest AI models is furiously painting a canvas with every stroke of your mind. What will the result look like!?

In the context of python you'll receive something resembling this:

{
  "created": 153729719727,
  "data": [
    {
      "url": "https://..."
    },
    {
      "url": "https://..."
    }
  ]
}

Enter fullscreen mode Exit fullscreen mode

However, you're able to extract that response and see the final results of your mind at artwork. (intentional pun)

I know you're probably dying to know how!
Simply save your data to an appropriately named variable.

In this case we'll go with image_url being we're specifically targeting the url of the data.

image_url=image['data'][0]['url]

We can then test the images we've created right in python by rendering the url under in and image tag.

and voilà!
<img src='https://YourMindMagicHere alt='AndDontForgetMe'>

Now... the question becomes; do the results match your expectations? If the answer is no, this is quite likely related to the description, context and details provided in your prompt.

In order to elaborate let's quickly jump into some specific techniques/examples available to enhance your output and I believe you'll get the gist!

Techniques for Enhanced Images:

Specific Scene Details: Paint a detailed picture with your prompts, describing the scene's elements, setting, and mood to guide the AI's artistic interpretation.

Example:
prompt='The water sparkles like liquid sapphires under the shimmering rays of a golden sunset'

Emotive Language: Infuse emotions into your prompts to evoke a particular ambiance in the generated image.
Example:
prompt='Amidst the crimson hues of a breathtaking sunset, a solitary figure stands on the edge of a cliff, gazing pensively at the vast expanse of the ocean below'

Spatial Relationships: Define the spatial positions and interactions between objects to compose a harmonious image that tells a story.
Example: prompt='In this enchanting scene, a young girl with a satchel slung over her shoulder stands at the threshold of the bookshop'

Sensory Imagery: Engage the reader's senses by incorporating sensory details like scents, sounds, and textures to add depth and realism to the image.
Example: prompt='As you step onto the warm, powdery sand, it cradles your feet like a gentle embrace.'

Color Palette: Experiment with color descriptions to influence the AI's choices
Example: prompt='The skyline is an orchestra of colors - majestic skyscrapers adorned in iridescent glass, reflecting the golden rays of the sun'

Symbolism and Metaphors: Incorporate symbolism and metaphors to inspire the AI's creativity.
Example: prompt='In the heart of a forgotten forest, a solitary willow tree stands tall, its cascading branches resembling a weeping veil'

Combining Concepts: Merge multiple concepts in your prompts to create intricate, multi-faceted images that transcend the ordinary.
Example:prompt='Copy and Paste any combination(s) of the examples from above plus some of your own and let's see you stretch your minds creativity!'

Conclusion
Just like we discovered in the prior post, Thorough AI prompts are the catalyst for unlocking the true potential of AI models. By providing clear instructions, context, and constraints, we empower these systems to generate remarkable outputs that resonate with our intentions. So, next time you engage with AI to paint you a picture try looking at AI as a blindfolded friend who needs directions instead of a "all knowing super-power". The results just might shock you!

Top comments (0)