iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🐷

Let AI Create Thumbnails for Your Event Pages

に公開

Hello.
How are you doing?
I am Ryo Yoshii, a huge fan of the phrase "No human labor is no human error."

I run a community called OpsJAWS.
When organizing events, I create event pages to recruit participants. For these pages, I put effort into themes that resonate, persuasive speakers, a schedule that isn't too long or too short, and the venue location to pique the interest of potential attendees.
Most importantly, you need an eye-catching thumbnail image. While I always thought it was necessary, I never used one for past events. The reason? "I have no artistic sense."
I felt it was a shame, but I had given up. However, as it turns out, we live in an era where AI can generate images for us. Knowing this, I had no choice but to use it, so I created thumbnails for the last two events with the help of Stability AI.
Here they are.

Since it's JAWS, I used a shark as the motif. I think they turned out pretty well. I'd like to say "self-praise," but it's not my own handiwork. It's "AI-praise."

Giving it a try

This time, I used AWS Bedrock. Pre-setup is required. Please follow the official user guide below to get everything configured.
Set up Amazon Bedrock

Sample Python code is provided in Stability.ai Diffusion 1.0 text to image. I will use this.

Define the parameters in the body below def main():.
height and width represent the image dimensions. You cannot just specify them arbitrarily. The combinations are listed in the Stability.ai Diffusion 1.0 text to image documentation, so choose from those.
I changed cfg_scale to take a random integer. A higher value is better if you want it to strictly follow the prompt, but I did this because I wanted to enjoy the randomness.
seed is commented out; I'm enjoying the randomness here as well.
style_preset specifies the style of the generated image. Try various settings to get the image you desire.

    # Create request body.
    body=json.dumps({
        "text_prompts": [
        {
        "text": prompt
        }
    ],
    "height": 640,
    "width": 1536,
    "cfg_scale": random.randint(0, 35),         # 0 to 35. Determines how much the final image portrays the prompt. Use a lower number to increase randomness in the generation.
    #"seed": 0,                                 # 0 to 4294967295. The seed determines the initial noise setting. Use the same seed and the same settings as a previous run to allow inference to create a similar image. If you don't set this value, or the value is 0, it is set as a random number.
    "steps": 30,                                # 10 to 50. Generation step determines how many times the image is sampled. More steps can result in a more accurate result.
    "samples" : 1,
    "style_preset" : "3d-model"                 # 3d-model analog-film anime cinematic comic-book digital-art enhance fantasy-art isometric line-art low-poly modeling-compound neon-punk origami photographic pixel-art tile-texture
    })

There is a prompt variable just above the body. Enter your prompt here to instruct what kind of image to generate.

prompt="""Sri lanka tea plantation."""

What about Japanese prompts?

I was curious, so I tried it out. Does Japanese work in the prompt?
I instructed "The horizon with the rising sun" in both Japanese and English and compared the generated images.

prompt="""朝日が昇る地平線."""

img

prompt="""The horizon with the rising sun."""

img

I tried several times, but the Japanese prompt did not yield the intended image.
It was somewhat sun-like and a decent image, but it felt a bit off. Therefore, let's do our best to write prompts in English.

How to write prompts

The output changes depending on how you write your prompt. Giving specific instructions will generate the images you expect.
The first question I had was whether sentences or keywords work better. I tried both.

prompt="""The muscular man wears a white tank top and a smlie. He holds his arms in an L-shape in front of his body, bragging about his well-developed biceps, and loudly shouts Power!."""

img

prompt="""A muscular man, smile, white tank top, arms in an L-shape, well-developed biceps, shouts Power!."""

img

As a result, there was no difference. It seems that either sentences or keywords are fine as long as they are specific.

Unwanted images

Depending on the prompt, images that you don't want might be generated.
Since these images are used in public, I want to avoid unwanted images. Examples include sexual, violent, or ethically problematic images.

When I generated images several times with the prompts introduced in this blog, I sometimes encountered unwanted images. To prevent this, I decided to include negative words in the prompt.
Specify negative words in negative_promt. I modified the body to add weighting. Setting the weight to less than 0 makes it negative.

    prompt="""The muscular man, a white tank top ,smlie, arms in an L-shape, well-developed biceps, shouts Power!"""
    negative_promt="""Not safe for work, missing limb, bad hands, missing fingers, bad anatomy"""

    body=json.dumps({
        "text_prompts": [
        {
            "text": prompt,
            "weight": 1.0
        },
        {
            "text": negative_promt,
            "weight": -1.0
        }
    ],

Summary

While image generation seems easy, I realized that you need to master certain points to generate the exact images you want.
It seems AI also has areas where it struggles, and on rare occasions, images that cannot be published are generated. I prevented these unwanted images by specifying a negative prompt.

After trying it out, I also learned that when using the Bedrock SDK to generate images, the service seems to have filters in place to prevent the output of "inappropriate images."

References

Stability.ai Diffusion 1.0 text to image
API Reference

Discussion