0% found this document useful (0 votes)
11 views3 pages

Lab Manual

The lab manual provides a comprehensive guide on using OpenAI's DALL·E 2 API with Python to generate and edit AI images based on text prompts. It covers prerequisites, software requirements, and detailed procedures for installation, API setup, and script execution, including building a GUI. The manual concludes by highlighting the practical skills gained in generative AI and interactive application development.

Uploaded by

shrikant gagare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Lab Manual

The lab manual provides a comprehensive guide on using OpenAI's DALL·E 2 API with Python to generate and edit AI images based on text prompts. It covers prerequisites, software requirements, and detailed procedures for installation, API setup, and script execution, including building a GUI. The manual concludes by highlighting the practical skills gained in generative AI and interactive application development.

Uploaded by

shrikant gagare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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:

 Generate images from prompts


 Create variations of existing images
 Edit parts of an image using masks

This lab will also demonstrate building a user-friendly GUI to interact with the model
seamlessly.
Procedure:
Step 1: Install Required Libraries

Run the following command in the terminal:

bash
CopyEdit
pip install openai requests pillow

Step 2: Set Up API Key

 Obtain API key from OpenAI platform.


 Store it securely in your Python script:

python
CopyEdit
openai.api_key = "YOUR_API_KEY"

Step 3: Write Python Script

The complete Python code includes:

1. Generating images from text prompts


2. Downloading generated images
3. Creating variations of images
4. Editing images using masks
5. Building a simple GUI

Step 4: Execute and Test

 Run the script to generate images.


 Test batch image generation and image editing functionalities.
 Launch the GUI for user-friendly interaction.

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:

 Generate AI-powered images using DALL·E 2 API


 Create variations and edit images
 Build a working GUI for interactive use

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.

Write answer of the following in lab manual

What is the main function of DALL·E 2?

Explain the role of API keys in cloud services.

How does image editing with masks work in DALL·E 2

What are the advantages of using tkinter for building GUI?\

How can we handle API errors effectively in Python?

You might also like