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
- Click on the `Azure` icon, and `sign in` into your account. Allow the extension `Azure Resources` to sign in using Microsoft, it will open a browser window. After doing so, you will be able to see your subscription and resources.
- Next, it will prompt you for the path of the blob container where you expect the function to be triggered after a file is uploaded. In this case is `pdfinvoices` as was previously created.
- Now we need to update the function code to extract data from PDFs and store it in Cosmos DB, use this an example:
241
+
242
+
> 1.**PDF Upload**: A PDF is uploaded to the Azure Blob Storage container.
243
+
> 2.**Trigger Azure Function**: The upload triggers the Azure Function `BlobTriggerContosoPDFInvoicesDocIntelligence`.
244
+
> 3.**Initialize Clients**: Sets up connections to Document Intelligence and Cosmos DB. <br/>
245
+
> - The function initializes the `DocumentAnalysisClient` to interact with Azure Document Intelligence. <br/>
246
+
> - It also initializes the `CosmosClient` to interact with Cosmos DB. <br/>
247
+
> 4.**Read PDF from Blob Storage**: The function reads the PDF content from the Blob Storage into a byte stream.
248
+
> 5.**Analyze PDF**: Uses Document Intelligence to extract data. <br/>
249
+
> - The function calls the `begin_analyze_document` method of the `DocumentAnalysisClient` using the prebuilt invoice model to analyze the PDF. <br/>
250
+
> - It waits for the analysis to complete and retrieves the results. <br/>
251
+
> 6.**Extract Data**: Structures the extracted data. <br/>
252
+
> - The function extracts relevant fields from the analysis result, such as customer name, email, address, company name, phone, address, and rental details. <br/>
253
+
> - It structures this extracted data into a dictionary (`invoice_data`). <br/>
254
+
> 7.**Save Data to Cosmos DB**: Inserts the data into Cosmos DB. <br/>
255
+
> - The function calls `save_invoice_data_to_cosmos` to save the structured data into Cosmos DB. <br/>
256
+
> - It ensures the database and container exist, then inserts the extracted data. <br/>
257
+
> 8.**Logging (process and errors)**: Throughout the process, the function logs various steps and any errors encountered for debugging and monitoring purposes.
258
+
259
+
- Update the function_app.py, for example [see the code used in this demo](./src/function_app.py):
- Since this function has already been tested, you can deploy your code to the function app in your subscription. If you want to test, you can use run your function locally for testing.
280
+
- Click on the `Azure` icon.
281
+
- Under `workspace`, click on the `Function App` icon.
> If you need further assistance with the code, please click [here to view all the function code](./src/).
298
+
299
+
> [!NOTE]
300
+
> Please ensure that all specified roles are assigned to the Function App. The provided example used `System assigned` for the Function App to facilitate the role assignment.
301
+
302
+
## Test the solution
303
+
304
+
> [!IMPORTANT]
305
+
> Please ensure that the user/system admin responsible for uploading the PDFs to the blob container has the necessary permissions. The error below illustrates what might occur if these roles are missing. <br/>
> Then, click on `select members` and search for your user/systen admin. Finally click on `Review + assign`.
312
+
313
+
> Upload sample PDF invoices to the Blob container and verify that data is correctly ingested and stored in Cosmos DB.
314
+
315
+
- Click on `Upload`, then select `Browse for files` and choose your PDF invoices to be stored in the blob container, which will trigger the function app to parse them.
- Under `Investigate`, click on `Performance`. Filter by time range, and `drill into the samples`. Sort the results by date (if you have many, like in my case) and click on the last one.
0 commit comments