Skip to content

Commit 0a85ce5

Browse files
authored
Merge pull request #247663 from GitHubber17/141588-refresh-2
Azure OpenAI Freshness Pass - User Story: 141588
2 parents be27ac9 + aed2ca9 commit 0a85ce5

File tree

5 files changed

+114
-94
lines changed

5 files changed

+114
-94
lines changed

articles/ai-services/openai/dall-e-quickstart.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: 'Quickstart - Generate an image using Azure OpenAI Service'
2+
title: 'Quickstart: Generate images with Azure OpenAI Service'
33
titleSuffix: Azure OpenAI
4-
description: Walkthrough on how to get started with Azure OpenAI and make your first image generation call.
4+
description: Learn how to get started generating images with Azure OpenAI Service by using the Python SDK, the REST APIs, or Azure OpenAI Studio.
55
services: cognitive-services
66
manager: nitinme
77
ms.service: cognitive-services
@@ -10,11 +10,11 @@ ms.custom: devx-track-python
1010
ms.topic: quickstart
1111
author: PatrickFarley
1212
ms.author: pafarley
13-
ms.date: 04/04/2023
13+
ms.date: 08/08/2023
1414
zone_pivot_groups: openai-quickstart-dall-e
1515
---
1616

17-
# Quickstart: Get started generating images using Azure OpenAI Service
17+
# Quickstart: Generate images with Azure OpenAI Service
1818

1919

2020
::: zone pivot="programming-language-studio"
Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,53 @@
11
---
2-
title: 'Quickstart: Use the OpenAI Service image generation REST APIs'
2+
title: 'Quickstart: Generate images with the Python SDK for Azure OpenAI Service'
33
titleSuffix: Azure OpenAI Service
4-
description: Walkthrough on how to get started with Azure OpenAI image generation using the REST API.
4+
description: Learn how to generate images with Azure OpenAI Service by using the Python SDK and the endpoint and access keys for your Azure OpenAI resource.
55
services: cognitive-services
66
manager: nitinme
77
ms.service: cognitive-services
88
ms.subservice: openai
99
ms.topic: include
10-
ms.date: 06/04/2023
10+
ms.date: 08/08/2023
1111
keywords:
1212
---
1313

14-
Use this guide to get started calling the image generation APIs using the Python SDK.
14+
Use this guide to get started calling the Azure OpenAI Service image generation APIs by using the Python SDK.
1515

1616
> [!NOTE]
17-
> The image generation API creates an image from a text prompt. It does not edit existing images or create variations.
17+
> The image generation API creates an image from a text prompt. It doesn't edit existing images or create variations.
1818
1919
## Prerequisites
2020

21-
- An Azure subscription - <a href="https://azure.microsoft.com/free/cognitive-services" target="_blank">Create one for free</a>
22-
- Access granted to DALL-E in the desired Azure subscription
23-
Currently, access to this service is granted only by application. You can apply for access to Azure OpenAI by completing the form at <a href="https://aka.ms/oai/access" target="_blank">https://aka.ms/oai/access</a>. Open an issue on this repo to contact us if you have an issue.
24-
- <a href="https://www.python.org/" target="_blank">Python 3.7.1 or later version</a>
25-
- The following Python libraries: os, requests, json
26-
- An Azure OpenAI resource created in the East US region. For more information about model deployment, see the [resource deployment guide](../how-to/create-resource.md).
21+
- An Azure subscription. <a href="https://azure.microsoft.com/free/ai-services" target="_blank">Create one for free</a>.
22+
- Access granted to DALL-E in the desired Azure subscription.
23+
- <a href="https://www.python.org/" target="_blank">Python 3.7.1 or later version</a>.
24+
- The following Python libraries: `os`, `requests`, `json`.
25+
- An Azure OpenAI resource created in the East US region. For more information, see [Create a resource and deploy a model with Azure OpenAI](../how-to/create-resource.md).
26+
27+
> [!NOTE]
28+
> Currently, you must submit an application to access Azure OpenAI Service. To apply for access, complete [this form](https://aka.ms/oai/access). If you need assistance, open an issue on this repo to contact Microsoft.
2729
2830
## Retrieve key and endpoint
2931

30-
To successfully make a call against Azure OpenAI, you'll need the following:
32+
To successfully call the Azure OpenAI APIs, you need the following information about your Azure OpenAI resource:
33+
34+
| Variable | Name | Value |
35+
|---|---|---|
36+
| **Endpoint** | `api_base` | The endpoint value is located under **Keys and Endpoint** for your resource in the Azure portal. Alternatively, you can find the value in **Azure OpenAI Studio** > **Playground** > **Code View**. An example endpoint is: `https://docs-test-001.openai.azure.com/`. |
37+
| **Key** | `api_key` | The key value is also located under **Keys and Endpoint** for your resource in the Azure portal. Azure generates two keys for your resource. You can use either value. |
3138

32-
|Variable name | Value |
33-
|--------------------------|-------------|
34-
| `ENDPOINT` | This value can be found in the **Keys & Endpoint** section when examining your resource from the Azure portal. Alternatively, you can find the value in **Azure OpenAI Studio** > **Playground** > **Code View**. An example endpoint is: `https://docs-test-001.openai.azure.com/`.|
35-
| `API-KEY` | This value can be found in the **Keys & Endpoint** section when examining your resource from the Azure portal. You can use either `KEY1` or `KEY2`.|
39+
Go to your resource in the Azure portal. On the navigation pane, select **Keys and Endpoint** under **Resource Management**. Copy the **Endpoint** value and an access key value. You can use either the **KEY 1** or **KEY 2** value. Always having two keys allows you to securely rotate and regenerate keys without causing a service disruption.
3640

37-
Go to your resource in the Azure portal. The **Endpoint and Keys** can be found in the **Resource Management** section. Copy your endpoint and access key as you'll need both for authenticating your API calls. You can use either `KEY1` or `KEY2`. Always having two keys allows you to securely rotate and regenerate keys without causing a service disruption.
41+
:::image type="content" source="../media/quickstarts/endpoint.png" alt-text="Screenshot that shows the Keys and Endpoint page for an Azure OpenAI resource in the Azure portal." lightbox="../media/quickstarts/endpoint.png":::
3842

3943
## Install the Python SDK
4044

41-
Open the command prompt and navigate to your project folder. Install the OpenAI Python SDK using the following command:
45+
Open a command prompt and browse to your project folder. Install the OpenAI Python SDK by using the following command:
4246

4347
```bash
4448
pip install openai
4549
```
50+
4651
Install the following libraries as well:
4752

4853
```bash
@@ -52,75 +57,76 @@ pip install pillow
5257

5358
## Create a new Python application
5459

55-
Create a new Python file called quickstart.py. Then open it in your preferred editor or IDE.
60+
Create a new Python file named _quickstart.py_. Open the new file in your preferred editor or IDE.
5661

57-
1. Replace the contents of quickstart.py with the following code. Enter your endpoint URL and key in the appropriate fields.
62+
1. Replace the contents of _quickstart.py_ with the following code. Enter your endpoint URL and key in the appropriate fields. Change the value of `prompt` to your preferred text.
5863

5964
```python
6065
import openai
6166
import os
6267
import requests
6368
from PIL import Image
6469

65-
openai.api_base = '<your_openai_endpoint>' # Add your endpoint here
66-
openai.api_key = '<your_openai_key>' # Add your api key here
70+
openai.api_base = '<your_endpoint>' # Enter your endpoint here
71+
openai.api_key = '<your_key>' # Enter your API key here
6772

68-
# At the moment Dall-E is only supported by the 2023-06-01-preview API version
73+
# Assign the API version (DALL-E is currently supported for the 2023-06-01-preview API version only)
6974
openai.api_version = '2023-06-01-preview'
70-
7175
openai.api_type = 'azure'
7276

73-
# Create an image using the image generation API
77+
# Create an image by using the image generation API
7478
generation_response = openai.Image.create(
75-
prompt='A painting of a dog',
79+
prompt='A painting of a dog', # Enter your prompt text here
7680
size='1024x1024',
7781
n=2
7882
)
7983

80-
# Set the directory where we'll store the image
84+
# Set the directory for the stored image
8185
image_dir = os.path.join(os.curdir, 'images')
86+
8287
# If the directory doesn't exist, create it
8388
if not os.path.isdir(image_dir):
8489
os.mkdir(image_dir)
8590

86-
# With the directory in place, we can initialize the image path (note that filetype should be png)
91+
# Initialize the image path (note the filetype should be png)
8792
image_path = os.path.join(image_dir, 'generated_image.png')
8893

89-
# Now we can retrieve the generated image
94+
# Retrieve the generated image
9095
image_url = generation_response["data"][0]["url"] # extract image URL from response
9196
generated_image = requests.get(image_url).content # download the image
9297
with open(image_path, "wb") as image_file:
9398
image_file.write(generated_image)
9499

95100
# Display the image in the default image viewer
96-
display(Image.open(image_path))
101+
image = Image.open(image_path)
102+
image.show()
97103
```
98104

99105
> [!IMPORTANT]
100-
> Remember to remove the key from your code when you're done, and never post it publicly. For production, use a secure way of storing and accessing your credentials. For example, [Azure Key Vault](../../../key-vault/general/overview.md).
106+
> Remember to remove the key from your code when you're done, and never post your key publicly. For production, use a secure way of storing and accessing your credentials. For more information, see [Azure Key Vault](../../../key-vault/general/overview.md).
101107

102108
1. Run the application with the `python` command:
103109

104110
```console
105111
python quickstart.py
106112
```
107113

108-
The script will loop until the generated image is ready.
114+
The script loops until the generated image is ready.
109115

110116
## Output
111117

112-
The output image will be downloaded to _generated_image.png_ at your specified location. The script will also display the image in your default image viewer.
118+
Azure OpenAI stores the output image in the _generated_image.png_ file in your specified directory. The script also displays the image in your default image viewer.
113119

114-
The image generation APIs come with a content moderation filter. If the service recognizes your prompt as harmful content, it won't return a generated image. For more information, see the [content filter](../concepts/content-filter.md) article.
120+
The image generation APIs come with a content moderation filter. If the service recognizes your prompt as harmful content, it doesn't generate an image. For more information, see [Content filtering](../concepts/content-filter.md).
115121

116122
## Clean up resources
117123

118-
If you want to clean up and remove an OpenAI resource, you can delete the resource or resource group. Deleting the resource group also deletes any other resources associated with it.
124+
If you want to clean up and remove an Azure OpenAI resource, you can delete the resource or resource group. Deleting the resource group also deletes any other resources associated with it.
119125

120-
- [Portal](../../multi-service-resource.md?pivots=azportal#clean-up-resources)
126+
- [Azure portal](../../multi-service-resource.md?pivots=azportal#clean-up-resources)
121127
- [Azure CLI](../../multi-service-resource.md?pivots=azcli#clean-up-resources)
122128

123129
## Next steps
124130

125-
* [Azure OpenAI Overview](../overview.md)
126-
* For more examples check out the [Azure OpenAI Samples GitHub repository](https://github.com/Azure/openai-samples).
131+
* Learn more in this [Azure OpenAI overview](../overview.md).
132+
* Try examples in the [Azure OpenAI Samples GitHub repository](https://github.com/Azure/openai-samples).

0 commit comments

Comments
 (0)