Lab Manual
Lab Manual
Title:
Generating AI Images Using DALL·E 2 API with Python
Objective:
To learn how to integrate OpenAI’s DALL·E 2 API with Python to generate AI-powered
images based on text prompts, create image variations, perform image editing with masks,
and build a simple GUI for image generation.
Prerequisites:
Basic Python programming knowledge
OpenAI account and API key
Python installed on the system
Libraries: openai, requests, Pillow, tkinter
Software Requirements:
Software Version
Python 3.8 or higher
openai Python package Latest
requests Latest
Pillow (PIL) Latest
tkinter Included in Python Standard Library
Theory:
DALL·E 2 is an advanced deep learning model developed by OpenAI that generates images
from natural language descriptions (prompts). It uses a combination of techniques, including
GPT-based language understanding and CLIP (Contrastive Language–Image Pretraining)
models to convert text to image formats.
Using the OpenAI API, developers can interact with DALL·E 2 to:
This lab will also demonstrate building a user-friendly GUI to interact with the model
seamlessly.
Procedure:
Step 1: Install Required Libraries
bash
CopyEdit
pip install openai requests pillow
python
CopyEdit
openai.api_key = "YOUR_API_KEY"
Observations:
Test
Prompt Result
Case
Generated AI image of a cityscape with
Test 1 "A futuristic city at sunset with flying cars"
flying cars
Test 2 Image variation of cityscape New artistic variations created
Test 3 Image editing with mask: "Add fireworks" AI edited image by adding fireworks
GUI prompt: "A magical forest with
Test 4 Images successfully generated via GUI
glowing mushrooms"
Result:
Successfully implemented Python scripts to:
Conclusion:
This lab demonstrates the capabilities of generative AI using DALL·E 2 and Python. It
equips learners with practical skills to work with AI-powered image generation, automate
batch processing, and build interactive applications.