Skip to content

Commit 0d0da4d

Browse files
committed
update file
1 parent a3401fe commit 0d0da4d

File tree

2 files changed

+47
-46
lines changed

2 files changed

+47
-46
lines changed

articles/applied-ai-services/form-recognizer/tutorial-azure-function.md

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,93 +10,94 @@ ms.subservice: forms-recognizer
1010
ms.topic: tutorial
1111
ms.date: 08/23/2022
1212
ms.author: lajanuar
13-
ms.custom: vscode-azure-extension-update-completed
13+
ms.custom: VS Code-azure-extension-update-completed
1414
---
1515

1616
# Tutorial: Use Azure Functions and Python to process stored documents
1717

18-
You can use Form Recognizer as part of an automated data processing pipeline built with Azure Functions. This guide shows you how to use Azure Functions to process documents that are uploaded to an Azure blob storage container. This workflow extracts table data from stored documents using the Form Recognizer Layout service and saves the table data in a .csv file in Azure. You can then display the data using Microsoft Power BI (not covered here).
18+
Form Recognizer can be used as part of an automated data processing pipeline built with Azure Functions. This guide will show you how to use Azure Functions to process documents that are uploaded to an Azure blob storage container. This workflow extracts table data from stored documents using the Form Recognizer layout model and saves the table data in a .csv file in Azure. You can then display the data using Microsoft Power BI (not covered here).
1919

2020
:::image type="content" source="media/tutorial-azure-function/workflow-diagram.png" alt-text="Screenshot of Azure Service workflow diagram":::
2121

2222
In this tutorial, you learn how to:
2323

2424
> [!div class="checklist"]
2525
>
26-
> * Create an Azure Storage account
27-
> * Create an Azure Functions project
28-
> * Extract layout data from uploaded forms
29-
> * Upload layout data to Azure Storage
26+
> * Create an Azure Storage account.
27+
> * Create an Azure Functions project.
28+
> * Extract layout data from uploaded forms.
29+
> * Upload extracted layout data to Azure Storage.
3030
3131
## Prerequisites
3232

33-
* Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services)
33+
* **Azure subscription** - [Create one for free](https://azure.microsoft.com/free/cognitive-services)
3434

35-
* A Form Recognizer resource. Once you have your Azure subscription, create a [Form Recognizer resource](https://portal.azure.com/#create/Microsoft.CognitiveServicesFormRecognizer) in the Azure portal to get your key and endpoint. You can use the free pricing tier (`F0`) to try the service, and upgrade later to a paid tier for production.
35+
* **A Form Recognizer resource**. Once you have your Azure subscription, create a [Form Recognizer resource](https://portal.azure.com/#create/Microsoft.CognitiveServicesFormRecognizer) in the Azure portal to get your key and endpoint. You can use the free pricing tier (`F0`) to try the service, and upgrade later to a paid tier for production.
3636

37-
* After your resource deploys, select **Go to resource**. You need the key and endpoint from the resource you create to connect your application to the Form Recognizer API. You'll paste your key and endpoint into the code below later in the quickstart:
37+
* After your resource deploys, select **Go to resource**. You need the key and endpoint from the resource you create to connect your application to the Form Recognizer API. You'll paste your key and endpoint into the code below later in the quickstart:
3838

39-
:::image type="content" source="media/containers/keys-and-endpoint.png" alt-text="Screenshot: keys and endpoint location in the Azure portal.":::
39+
:::image type="content" source="media/containers/keys-and-endpoint.png" alt-text="Screenshot: keys and endpoint location in the Azure portal.":::
4040

41-
* [Python 3.6.x, 3.7.x, 3.8.x or 3.9.x](https://www.python.org/downloads/) installed (Python 3.10.x is not supported for this project).
41+
* [**Python 3.6.x, 3.7.x, 3.8.x or 3.9.x**](https://www.python.org/downloads/) (Python 3.10.x isn't supported for this project).
4242

43-
* The latest version of [Visual Studio Code](https://code.visualstudio.com/) with the following extensions installed:
43+
* The latest version of [**Visual Studio Code**](https://code.visualstudio.com/) with the following extensions installed:
4444

45-
* [Azure Functions extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions).
45+
* [**Azure Functions extension**](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.VS Code-azurefunctions). Once it's installed, you should see the Azure logo in the left-navigation pane.
4646

47-
* [Azure Functions Core Tools](/azure/azure-functions/functions-run-local?tabs=v3%2Cwindows%2Ccsharp%2Cportal%2Cbash) version 3.x (Version 4.x is not supported for this project).
47+
* [**Azure Functions Core Tools**](/azure/azure-functions/functions-run-local?tabs=v3%2Cwindows%2Ccsharp%2Cportal%2Cbash) version 3.x (Version 4.x isn't supported for this project).
4848

49-
* The [Python Extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) for Visual Studio code. For more information, *see* [Getting Started with Python in VS Code](https://code.visualstudio.com/docs/python/python-tutorial)
49+
* [**Python Extension**](https://marketplace.visualstudio.com/items?itemName=ms-python.python) for Visual Studio code. For more information, *see* [Getting Started with Python in VS Code](https://code.visualstudio.com/docs/python/python-tutorial)
5050

51-
* [Azure Storage Explorer](https://azure.microsoft.com/features/storage-explorer/) installed.
51+
* [**Azure Storage Explorer**](https://azure.microsoft.com/features/storage-explorer/) installed.
5252

53-
* A local PDF document to analyze. You can use our [sample pdf document](https://github.com/Azure-Samples/cognitive-services-REST-api-samples/blob/master/curl/form-recognizer/sample-layout.pdf) for this project.
53+
* **A local PDF document to analyze**. You can use our [sample pdf document](https://github.com/Azure-Samples/cognitive-services-REST-api-samples/blob/master/curl/form-recognizer/sample-layout.pdf) for this project.
5454

5555
## Create an Azure Storage account
5656

57-
* [Create an Azure Storage account](https://portal.azure.com/#create/Microsoft.StorageAccount-ARM) in the Azure portal. Select **StorageV2** as the Account kind.
57+
1. [Create a general-purpose v2 Azure Storage account](https://portal.azure.com/#create/Microsoft.StorageAccount-ARM) in the Azure portal. If you don't know how to create an Azure storage account with a storage container, follow these quickstarts:
5858

59-
* On the left pane, select the **CORS** tab, and remove the existing CORS policy if any exists.
59+
* [Create a storage account](../../storage/common/storage-account-create.md). When you create your storage account, select **Standard** performance in the **Instance details** > **Performance** field.
60+
* [Create a container](../../storage/blobs/storage-quickstart-blobs-portal.md#create-a-container). When you create your container, set **Public access level** to **Container** (anonymous read access for containers and files) in the **New Container** window.
6061

61-
* Once that has deployed, create two empty blob storage containers, named **input** and **output**.
62+
1. On the left pane, select the **Resource sharing (CORS)** tab, and remove the existing CORS policy if any exists.
6263

63-
## Create an Azure Functions project
64+
1. Once your storage account has deployed, create two empty blob storage containers, named **input** and **output**.
6465

65-
1. Create a new folder named **form-recognizer-function-app** to contain the project and choose **Select**.
66+
## Create an Azure Functions project
6667

67-
1. Open Visual Studio Code.
68+
1. Create a new folder named **functions-app** to contain the project and choose **Select**.
6869

69-
1. Open the Command Palette (Ctrl+Shift+P) and search for and choose **Python:Select Interpreter** → choose **Use Python from \`python.defaultInterpreterPath` setting. This will set the default Python interpreter path.
70+
1. Open Visual Studio Code and open the Command Palette (Ctrl+Shift+P). Search for and choose **Python:Select Interpreter** → choose **Use Python from \`python.defaultInterpreterPath` setting**. This selection will set the default Python interpreter path.
7071

71-
1. If you've successfully installed the Azure Functions extension, you should see an Azure logo on the left navigation pane. Select it.
72+
1. Select the Azure logo from the left-navigation pane.
7273

73-
* You'll see all your existing resources in the Resources view.
74+
* You'll see your existing Azure resources in the Resources view.
7475

7576
* Select the Azure subscription that you're using for this project and below you should see the Azure Function App.
7677

77-
:::image type="content" source="media/tutorial-azure-function/azure-extensions-vsc.png" alt-text="Screenshot of a list showing your Azure resoures in a single, unified view.":::
78+
:::image type="content" source="media/tutorial-azure-function/azure-extensions-vsc.png" alt-text="Screenshot of a list showing your Azure resources in a single, unified view.":::
7879

79-
1. Select the Workspace (Local) section located below your listed resources, select the plus symbol and choose the **Create Function** button.
80+
1. Select the Workspace (Local) section located below your listed resources. Select the plus symbol and choose the **Create Function** button.
8081

8182
:::image type="content" source="media/tutorial-azure-function/workspace-create-function.png" alt-text="Screenshot showing where to begin creating an Azure function.":::
8283

83-
1. When prompted, choose **Create new project**. Navigate to the **form-recognizer-function-app** directory and choose **Select**.
84+
1. When prompted, choose **Create new project** and navigate to the **function-app** directory. Choose **Select**.
8485

85-
1. You'll be prompted to configure a number of settings:
86+
1. You'll be prompted to configure several settings:
8687

8788
* **Select a language** → choose Python.
8889

89-
* **Select a Python interpreter to create a virtual environment** → select the interpreter you set as a default earlier.
90+
* **Select a Python interpreter to create a virtual environment** → select the interpreter you set as the default earlier.
9091

9192
* **Select a template** → choose **Azure Blob Storage trigger** and give the trigger a name or accept the default name. Press **Enter** to confirm.
9293

9394
* **Select setting** → choose **➕Create new local app setting** from the dropdown menu.
9495

9596
* **Select subscription** → choose your Azure subscription with the storage account you created → select your storage account → then select the name of the storage input container (in this case, `input/{name}`). Press **Enter** to confirm.
9697

97-
* **Select how your would like to open your project** → choose open the project in the current window from the dropdown window.
98+
* **Select how your would like to open your project** → choose **Open the project in the current window** from the dropdown window.
9899

99-
1. Once you've completed these steps, VSCode will add a new Azure Function project with a *\_\_init\_\_.py* Python script. This script will be triggered when a file is uploaded to the **input** storage container:
100+
1. Once you've completed these steps, VS Code will add a new Azure Function project with a *\_\_init\_\_.py* Python script. This script will be triggered when a file is uploaded to the **input** storage container:
100101

101102
```python
102103
import logging
@@ -112,23 +113,23 @@ In this tutorial, you learn how to:
112113

113114
## Test the function
114115

115-
* Press F5 to run the basic function. VSCode will prompt you to select a storage account to interface with.
116+
* Press F5 to run the basic function. VS Code will prompt you to select a storage account to interface with.
116117

117118
* Select the storage account you created and continue.
118119

119-
* Open Azure Storage Explorer and upload a sample PDF document to the **input** container. Then check the VSCode terminal.
120+
* Open Azure Storage Explorer and upload the sample PDF document to the **input** container. Then check the VS Code terminal.
120121

121122
* The script should log that it was triggered by the PDF upload.
122123

123-
:::image type="content" source="media/tutorial-azure-function/vs-code-terminal-test.png" alt-text="Screenshot of the VSCode terminal after uploading a new document.":::
124+
:::image type="content" source="media/tutorial-azure-function/vs-code-terminal-test.png" alt-text="Screenshot of the VS Code terminal after uploading a new document.":::
124125

125-
Stop the script before continuing.
126+
* Stop the script before continuing.
126127

127128
## Add document processing code
128129

129-
Next, you'll add your own code to the Python script to call the Form Recognizer service and parse the uploaded documents using the Form Recognizer [Layout API](concept-layout.md).
130+
Next, you'll add your own code to the Python script to call the Form Recognizer service and parse the uploaded documents using the Form Recognizer [layout model](concept-layout.md).
130131

131-
1. In VSCode, navigate to the function's *requirements.txt* file. This defines the dependencies for your script. Add the following Python packages to the file:
132+
1. In VS Code, navigate to the function's *requirements.txt* file. This file defines the dependencies for your script. Add the following Python packages to the file:
132133

133134
```txt
134135
cryptography
@@ -171,7 +172,7 @@ Next, you'll add your own code to the Python script to call the Form Recognizer
171172
# This is the call to the Form Recognizer endpoint
172173
endpoint = r"Your Form Recognizer Endpoint"
173174
apim_key = "Your Form Recognizer Key"
174-
post_url = endpoint + "/formrecognizer/documentModels/prebuilt-layout:analyze?api-version=2022-08-31"
175+
post_url = endpoint + "/formrecognizer/v2.1/layout/analyze"
175176
source = myblob.read()
176177
177178
headers = {
@@ -210,7 +211,7 @@ Next, you'll add your own code to the Python script to call the Form Recognizer
210211
211212
212213
if status == "succeeded":
213-
print("Layout Analysis succeeded:\n%s")
214+
print("POST Layout Analysis succeeded:\n%s")
214215
results=resp_json
215216
else:
216217
print("GET Layout results failed:\n%s")
@@ -219,7 +220,7 @@ Next, you'll add your own code to the Python script to call the Form Recognizer
219220
results=resp_json
220221
```
221222
222-
1. Then add the following code to connect to the Azure Storage **output** container. Fill in your own values for the storage account name and key. You can get the key on the **Access keys** tab of your storage resource in the Azure portal.
223+
1. Add the following code to connect to the Azure Storage **output** container. Fill in your own values for the storage account name and key. You can get the key on the **Access keys** tab of your storage resource in the Azure portal.
223224
224225
```Python
225226
# This is the connection to the blob storage, with the Azure Python SDK
@@ -298,4 +299,4 @@ In this tutorial, you learned how to use an Azure Function written in Python to
298299
> [Microsoft Power BI](https://powerbi.microsoft.com/integrations/azure-table-storage/)
299300
300301
* [What is Form Recognizer?](overview.md)
301-
* Learn more about the [Layout API](concept-layout.md)
302+
* Learn more about the [layout model](concept-layout.md)

articles/applied-ai-services/form-recognizer/whats-new.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ Form Recognizer service is updated on an ongoing basis. Bookmark this page to st
3131

3232
* **Custom models**. The Studio now includes the ability to reorder labels in custom model projects to improve labeling efficiency.
3333

34-
* **Copy Models** Custom models can be copied across Form Recognizer services from within the Studio. This enables the promotion of a trained model to other environments and regions.
34+
* **Copy Models** Custom models can be copied across Form Recognizer services from within the Studio. The operation enables the promotion of a trained model to other environments and regions.
3535

3636
* **Delete documents**. The Studio now supports deleting documents from labeled dataset within custom projects.
3737

3838
##### Form Recognizer service updates
3939

4040
* [**prebuilt-invoice**](concept-invoice.md). The TotalVAT and Line/VAT fields will now resolve to the existing fields TotalTax and Line/Tax respectively.
4141

42-
* [**prebuilt-idDocument**](concept-id-document.md). Data extraction support for US state ID, social security, and green cards as well as passport visa information.
42+
* [**prebuilt-idDocument**](concept-id-document.md). Data extraction support for US state ID, social security, and green cards. Support for passport visa information.
4343

4444
* [**prebuilt-receipt**](concept-receipt.md). Expanded locale support for French (fr-FR), Spanish (es-ES), Portuguese (pt-PT), Italian (it-IT) and German (de-DE).
4545

46-
* [**prebuilt-businessCard**](concept-business-card.md). Address parsing support to extract sub-fields for address components like address, city, state, country, and zip code.
46+
* [**prebuilt-businessCard**](concept-business-card.md). Address parsing support to extract subfields for address components like address, city, state, country, and zip code.
4747

4848
* **AI quality improvements**
4949

0 commit comments

Comments
 (0)