Using the OpenAIImageGenerator

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

  • FME 2022.2

Tutorial: Getting Started with OpenAI in FME | Previous: Using the OpenAICompletionsConnector
 

Introduction

OpenAI is the artificial intelligence company responsible for services such as DALL-E. In FME, you can connect to the OpenAI Images API using the OpenAIImageGenerator transformer. Just input a text prompt, and the transformer will provide the output as a URL to the image.

This tutorial will walk through how to create an FME Workspace that uses the OpenAIImageGenerator to generate images and saves them into a folder on the end user’s machine.
 

Requirements

To use the OpenAIImageGenerator, sign up for the OpenAI API, then generate an API key.
In FME, the OpenAIImageGenerator is available via FME Hub in FME Workbench 2022.2.1.0 and later.
 

Step-by-Step Instructions

This scenario will walk through how to generate images of different infrastructure based on a list of descriptions in a text file. The end user can then make use of these images for presentations or marketing materials.

Screenshot 2023-02-24 at 12.56.18 PM.png

1. Get an OpenAI API key
If you haven’t already, sign up for the OpenAI API, then generate an API key.

2. Create a new FME workspace
Open FME Workbench and create a blank workspace.

3. Add a reader
To kick off the workspace, we’ll need to read the source data and set up the prompt for the AI. Click Add Reader and set the following parameters:

  • Format: Text File
  • Dataset: <Tutorial download>/infrastructure.txt


Screenshot 2023-02-24 at 11.30.56 AM.png

4. Add OpenAIImageGenerator transformer
Type OpenAI on the canvas and choose the OpenAIImageGenerator. Connect it after the reader feature type. Open the parameters. This is where you specify the prompt(s) for the AI.

Open the parameters and set the following:
 

  • OpenAI API key: <your OpenAI API key generated in step 1>
  • Prompt: select the down arrow and choose the attribute “text_line_data”
  • Size: 1024x1024


Screenshot 2023-02-24 at 11.31.15 AM.png

The size is in pixels and can be set to 256x256, 512x512, or 1024x1024. Learn more about the parameters in the OpenAIImageGenerator parameter documentation.

Your workspace should look as follows:

Screenshot 2023-02-24 at 12.17.54 PM.png

5. Add a writer
Now it’s time to output the data to a folder of PNG images. Add a new writer and set the following parameters:

  • Format: PNG (Portable Network Graphics)
  • Dataset: <specify an output folder>
  • Raster File Definition: Manual…


Screenshot 2023-02-24 at 12.10.46 PM.png

Click OK. On the Feature Type dialog, set World File Generation to “No”, and click OK.

The workspace should look as follows:

Screenshot 2023-02-24 at 12.12.38 PM.png

6. Run the workspace
Run the workspace, and open the folder at the location you specified to view the output PNG files.

If you want to ask the end user for input before prompting the AI, configure a user parameter. In the Navigator pane, right-click “User Parameters”, choose “Manage User Parameters…”, and add a new one. Then use this value in the OpenAIImageGenerator to prompt the AI.

Additional Resources

 

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.