You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: openai-dalle/README.md
+6-5Lines changed: 6 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,14 @@
1
-
# Generate Images With DALL·E 2 and the OpenAI API
1
+
# Generate Images With DALL·E and the OpenAI API
2
2
3
-
Learn to use the OpenAI Python library to create images with DALL·E, a state-of-the-art latent diffusion model. In the associated tutorial on [generating images with DALL·E 2 and the OpenAI API](https://realpython.com/generate-images-with-dalle-openai-api/), you explore image creation and generating image variations. You learn how to interact with DALL·E using API calls and incorporate this functionality into your Python scripts.
3
+
Learn to use the OpenAI Python library to create images with DALL·E, a state-of-the-art latent diffusion model. In the associated tutorial on [generating images with DALL·E and the OpenAI API](https://realpython.com/generate-images-with-dalle-openai-api/), you'll explore image creation and generating image variations. You'll learn how to interact with DALL·E using API calls and incorporate this functionality into your Python scripts.
4
4
5
5
## Setup
6
6
7
7
Create and activate a virtual environment, then install the `openai` package:
8
8
9
9
```console
10
10
$ python --version
11
-
Python 3.11.0
11
+
Python 3.12.5
12
12
$ python -m venv venv
13
13
$ source venv/bin/activate
14
14
(venv) $ python -m pip install openai
@@ -22,14 +22,15 @@ Follow the instructions in [the tutorial](https://realpython.com/generate-images
22
22
23
23
You can find the code for each of these steps in dedicated scripts:
24
24
25
-
-`create.py`: Create an image from a text prompt and save the image data to a file.
25
+
-`create_dalle3.py`: Create an image from a text prompt using DALL·E 3 and display the URL to the image.
26
+
-`create.py`: Create an image from a text prompt using DALL·E 2 and save the image data to a file.
26
27
-`convert.py`: Convert a Base64-encoded PNG image delivered in a JSON response to a PNG image file.
27
28
-`vary.py`: Read Base64-encoded image data and make an API request to receive variations of that image.
28
29
29
30
In the tutorial, you'll walk through each of these scripts and their functionality and output in more detail.
30
31
31
32
## Edit Images (Inpainting and Outpainting)
32
33
33
-
The OpenAI Image API also allows you to [edit parts of an image](https://beta.openai.com/docs/guides/images/edits) using text prompts. For this, you need to create a mask with transparent image data in the area where you want to edit the image.
34
+
The OpenAI Image API also allows you to [edit parts of an image](https://platform.openai.com/docs/guides/images/edits-dall-e-2-only) using text prompts. For this, you need to create a mask with transparent image data in the area where you want to edit the image.
34
35
35
36
You can run `edit.py` to give this functionality a try.
[Web Scraping With Scrapy and MongoDB](https://realpython.com/web-scraping-with-scrapy-and-mongodb/) is an example project for building a robust web scraper for static sites leveraging Scrapy and MongoDB.
4
+
5
+
## Installation and Setup
6
+
7
+
1. Create a Python virtual environment
8
+
9
+
```sh
10
+
$ python -m venv ./venv
11
+
$ source venv/bin/activate
12
+
(venv) $
13
+
```
14
+
15
+
2. Install the requirements
16
+
17
+
```sh
18
+
(venv) $ pip install -r requirements.txt
19
+
```
20
+
21
+
You'll also need to [set up a MongoDB collection](https://realpython.com/web-scraping-with-scrapy-and-mongodb/#set-up-a-mongodb-collection-on-your-computer) like described in the tutorial.
22
+
23
+
## Run the Scraper
24
+
25
+
Navigate into the `books/` project directory.
26
+
27
+
Then you can start crawling the site:
28
+
29
+
```sh
30
+
(venv) $ scrapy crawl book
31
+
```
32
+
33
+
If set up correctly, this will populate your MongoDB collection with the book information scraped from the example site.
0 commit comments