In this tutorial, you'll learn how to extract data from images in Airtable using OpenAI. You'll extract specific data such as the name, email, and job title from pictures of business cards.
Here's one of the images we'll work with.
You can follow the steps in this tutorial to extract structured data from any image.
We'll begin by uploading the business card images to Airtable.
1. Create a table called "Business cards" or use an existing table.
2. Create a new field called "Business card" with the type Attachment. You can use an existing attachment field if you have one.
3. Upload the images to the "Business card" field.
4. Create a new Grid view called Needs data and apply the following filters:
We'll use this view to extract data from the business cards that don't have information in the table.
Now that the table is set up, we can connect to OpenAI with Data Fetcher.
We'll create an OpenAI request in Data Fetcher to extract data from the business cards we uploaded. To get started:
1. Add the Data Fetcher extension to your Airtable base.
2. Once you’ve added the extension, sign in to Data Fetcher or sign up if you don’t have an account.
3. Once you're logged in to Data Fetcher, click Create your first request.
Follow these steps to configure the request:
1. Select OpenAI under Application.
2. Rename the request to "Extract image data".
3. Copy and paste your OpenAI API key under Authorization. You can create an API key in your OpenAI account.
4. Under Endpoint, select Create chat message completion.
5. Click Save and Continue in the bottom right corner.
Once you've completed the previous steps, you'll be taken to a new section to give the AI instructions for extracting data from the business cards.
1. Select gpt-4o-mini under Model.
2. Add the following instruction under Messages:
Extract data from this business card:
We'll now reference the "Business card" field.
3. Click the + button next to Messages.
4. In the dialog that opens, select Business card under Field.
5. Under Run for every record in view, select Needs data.
6. Click Confirm to save the options and close the dialog. We'll now fill in the remaining instructions.
7. Press Shift + Enter on your keyboard to go to the next line, then copy and paste the following code:
Return data in a JSON format. If you cannot find a field, return null.
Output format:
{
"name": "TODO",
"jobTitle": "TODO",
"contactEmail": "TODO"
}
8. Press Enter to add the message, then click Save and Run in the bottom right corner to proceed.
Let's walk through the message above before moving on. We're asking OpenAI to extract the name, job title, and email from a business card, which we attached by referencing the "Business card" field in the Needs data view.
We then ask it to return the results in JSON format so that Data Fetcher can process them properly. Finally, we give it the output format, where we specify the data we want from the images.
TIP: You can use the format above to extract data from other images, as long as they have structured data.
After following the previous steps, Data Fetcher will take you to Response field mapping. On this page, you'll choose the fields from the response data you want in your table.
Data Fetcher returned many fields from the request, but we're only interested in the name, contact email, and job title fields. Notice how these fields have the word "Json" in their names.
Data Fetcher automatically added this prefix because we instructed OpenAI to return a JSON response in the message we created earlier.
Follow these steps to import the fields:
1. Click Deselect all.
3. Click Save and Run in the bottom right corner.
Check the default view of your output table and you should see the extracted data.
You may want to extract the data automatically whenever you add new images to your table. In that case, check out Data Fetcher's trigger feature. Triggers will automatically run the request when data changes in your table, saving you time to do other things. Check out our help center to learn more about triggers and scheduling.
Jul 18, 2024
•Zayyad Muhammad Sani
•OpenAIPDFJul 5, 2024
•Andy Cloke
•OpenAIJun 25, 2024
•Andy Cloke
•OpenAI