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
ms.custom: VS Code-azure-extension-update-completed
14
14
---
15
15
16
16
# Tutorial: Use Azure Functions and Python to process stored documents
17
17
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).
19
19
20
20
:::image type="content" source="media/tutorial-azure-function/workflow-diagram.png" alt-text="Screenshot of Azure Service workflow diagram":::
21
21
22
22
In this tutorial, you learn how to:
23
23
24
24
> [!div class="checklist"]
25
25
>
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.
30
30
31
31
## Prerequisites
32
32
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)
34
34
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.
36
36
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:
38
38
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.":::
40
40
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).
42
42
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:
*[**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.
46
46
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).
48
48
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)
* 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.
54
54
55
55
## Create an Azure Storage account
56
56
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:
58
58
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.
60
61
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.
62
63
63
-
## Create an Azure Functions project
64
+
1. Once your storage account has deployed, create two empty blob storage containers, named **input** and **output**.
64
65
65
-
1. Create a new folder named **form-recognizer-function-app** to contain the project and choose **Select**.
66
+
##Create an Azure Functions project
66
67
67
-
1.Open Visual Studio Code.
68
+
1.Create a new folder named **functions-app** to contain the project and choose **Select**.
68
69
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.
70
71
71
-
1.If you've successfully installed the Azure Functions extension, you should see an Azure logo on the leftnavigation pane. Select it.
72
+
1.Select the Azure logo from the left-navigation pane.
72
73
73
-
* You'll see all your existing resources in the Resources view.
74
+
* You'll see your existing Azure resources in the Resources view.
74
75
75
76
* Select the Azure subscription that you're using for this project and below you should see the Azure Function App.
76
77
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.":::
78
79
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.
80
81
81
82
:::image type="content" source="media/tutorial-azure-function/workspace-create-function.png" alt-text="Screenshot showing where to begin creating an Azure function.":::
82
83
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**.
84
85
85
-
1. You'll be prompted to configure a number of settings:
86
+
1. You'll be prompted to configure several settings:
86
87
87
88
***Select a language** → choose Python.
88
89
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.
90
91
91
92
***Select a template** → choose **Azure Blob Storage trigger** and give the trigger a name or accept the default name. Press **Enter** to confirm.
92
93
93
94
***Select setting** → choose **➕Create new local app setting** from the dropdown menu.
94
95
95
96
***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.
96
97
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.
98
99
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:
100
101
101
102
```python
102
103
import logging
@@ -112,23 +113,23 @@ In this tutorial, you learn how to:
112
113
113
114
## Test the function
114
115
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.
116
117
117
118
* Select the storage account you created and continue.
118
119
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.
120
121
121
122
* The script should log that it was triggered by the PDF upload.
122
123
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.":::
124
125
125
-
Stop the script before continuing.
126
+
*Stop the script before continuing.
126
127
127
128
## Add document processing code
128
129
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).
130
131
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:
132
133
133
134
```txt
134
135
cryptography
@@ -171,7 +172,7 @@ Next, you'll add your own code to the Python script to call the Form Recognizer
171
172
# This is the call to the Form Recognizer endpoint
@@ -210,7 +211,7 @@ Next, you'll add your own code to the Python script to call the Form Recognizer
210
211
211
212
212
213
if status == "succeeded":
213
-
print("Layout Analysis succeeded:\n%s")
214
+
print("POST Layout Analysis succeeded:\n%s")
214
215
results=resp_json
215
216
else:
216
217
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
219
220
results=resp_json
220
221
```
221
222
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.
223
224
224
225
```Python
225
226
# 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
298
299
> [Microsoft Power BI](https://powerbi.microsoft.com/integrations/azure-table-storage/)
299
300
300
301
* [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)
Copy file name to clipboardExpand all lines: articles/applied-ai-services/form-recognizer/whats-new.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,19 +31,19 @@ Form Recognizer service is updated on an ongoing basis. Bookmark this page to st
31
31
32
32
***Custom models**. The Studio now includes the ability to reorder labels in custom model projects to improve labeling efficiency.
33
33
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.
35
35
36
36
***Delete documents**. The Studio now supports deleting documents from labeled dataset within custom projects.
37
37
38
38
##### Form Recognizer service updates
39
39
40
40
*[**prebuilt-invoice**](concept-invoice.md). The TotalVAT and Line/VAT fields will now resolve to the existing fields TotalTax and Line/Tax respectively.
41
41
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.
43
43
44
44
*[**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).
45
45
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.
0 commit comments