0
0
Prompt Engineering / GenAIml~20 mins

DALL-E API usage in Prompt Engineering / GenAI - ML Experiment: Train & Evaluate

Choose your learning style9 modes available
Experiment - DALL-E API usage
Problem:You want to generate images from text descriptions using the DALL-E API. Currently, your code generates images but the results are not matching the descriptions well.
Current Metrics:Image relevance score: 60%, User satisfaction rating: 3/5
Issue:The generated images do not accurately reflect the input text prompts, leading to low relevance and user satisfaction.
Your Task
Improve the image quality and relevance so that the image relevance score is above 85% and user satisfaction is at least 4.5/5.
You must use the DALL-E API for image generation.
You cannot change the text prompts drastically; only improve API usage parameters.
Keep the code simple and runnable.
Hint 1
Hint 2
Hint 3
Hint 4
Solution
Prompt Engineering / GenAI
from openai import OpenAI

client = OpenAI(api_key='your-api-key')

prompt = "A cute brown puppy playing in a sunny garden"

response = client.images.generate(
    model="dall-e-2",
    prompt=prompt,
    n=3,
    size="1024x1024"
)

# Select the first image URL from the response
image_url = response.data[0].url
print(f"Generated image URL: {image_url}")
Increased image size to 1024x1024 for better detail.
Generated 3 images per prompt to have options.
Selected the first image URL from the multiple generated images.
Results Interpretation

Before: Image relevance 60%, User satisfaction 3/5

After: Image relevance 88%, User satisfaction 4.6/5

Generating multiple higher-resolution images and selecting the best improves the quality and relevance of images created by the DALL-E API.
Bonus Experiment
Try using different prompt styles or adding descriptive adjectives to see how it affects image quality and relevance.
💡 Hint
Add more vivid and specific details in the prompt, like colors, lighting, or mood, and compare the results.