Skip to content

Commit 2175391

Browse files
authored
Merge pull request #45 from Azure-Samples/dev-container
Fix devcontainer issues for local and Codespaces run
2 parents ccd6ca1 + 928842e commit 2175391

File tree

9 files changed

+138
-30
lines changed

9 files changed

+138
-30
lines changed

.devcontainer/devcontainer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Azure AI Document Processing Samples",
3-
"image": "mcr.microsoft.com/devcontainers/python:1-3.12-bullseye",
3+
"image": "mcr.microsoft.com/vscode/devcontainers/python:1-3.12-bullseye",
44
"features": {
55
"ghcr.io/devcontainers/features/git:1": {
66
"version": "latest",
@@ -30,6 +30,12 @@
3030
"ghcr.io/devcontainers/features/docker-in-docker",
3131
"./local-features/dev-tools"
3232
],
33+
"remoteUser": "vscode",
34+
"containerUser": "vscode",
35+
"forwardPorts": [],
36+
"otherPortsAttributes": {
37+
"onAutoForward": "ignore"
38+
},
3339
"customizations": {
3440
"vscode": {
3541
"extensions": [

.devcontainer/local-features/dev-tools/install.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env bash
22

3-
# Default: Exit on any failure.
4-
set -e
3+
USERNAME=${USERNAME:-"vscode"}
4+
5+
set -eux
56

67
# Setup STDERR.
78
err() {
@@ -13,9 +14,12 @@ if [ "$(id -u)" -ne 0 ]; then
1314
exit 1
1415
fi
1516

16-
###################
17+
# Ensure apt is in non-interactive to avoid prompts
18+
export DEBIAN_FRONTEND=noninteractive
19+
20+
###########################################
1721
# Helper Functions
18-
###################
22+
###########################################
1923

2024
apt_get_update() {
2125
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
@@ -36,9 +40,6 @@ check_packages() {
3640
# Install Feature
3741
###########################################
3842

39-
# Ensure apt is in non-interactive to avoid prompts
40-
export DEBIAN_FRONTEND=noninteractive
41-
4243
# Install dependencies
4344
check_packages poppler-utils tesseract-ocr libtesseract-dev ffmpeg libsm6 libxext6 python3-opencv
4445

.gitattributes

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Set default behavior to automatically normalize line endings.
2+
* text=auto
3+
4+
# Collapse these files in PRs by default
5+
*.xlf linguist-generated=true
6+
*.lcl linguist-generated=true
7+
8+
*.jpg binary
9+
*.png binary
10+
*.gif binary
11+
12+
# Force bash scripts to always use lf line endings so that if a repo is accessed
13+
# in Unix via a file share from Windows, the scripts will work.
14+
*.in text eol=lf
15+
*.sh text eol=lf
16+
17+
# Likewise, force cmd and batch scripts to always use crlf
18+
*.cmd text eol=crlf
19+
*.bat text eol=crlf
20+
21+
*.cs text=auto diff=csharp
22+
*.vb text=auto
23+
*.resx text=auto
24+
*.c text=auto
25+
*.cpp text=auto
26+
*.cxx text=auto
27+
*.h text=auto
28+
*.hxx text=auto
29+
*.py text=auto
30+
*.rb text=auto
31+
*.java text=auto
32+
*.html text=auto
33+
*.htm text=auto
34+
*.css text=auto
35+
*.scss text=auto
36+
*.sass text=auto
37+
*.less text=auto
38+
*.js text=auto
39+
*.lisp text=auto
40+
*.clj text=auto
41+
*.sql text=auto
42+
*.php text=auto
43+
*.lua text=auto
44+
*.m text=auto
45+
*.asm text=auto
46+
*.erl text=auto
47+
*.fs text=auto
48+
*.fsx text=auto
49+
*.hs text=auto
50+
51+
*.csproj text=auto
52+
*.vbproj text=auto
53+
*.fsproj text=auto
54+
*.dbproj text=auto
55+
*.sln text=auto eol=crlf
56+
57+
# Set linguist language for .h files explicitly based on
58+
# https://github.com/github/linguist/issues/1626#issuecomment-401442069
59+
# this only affects the repo's language statistics
60+
*.h linguist-language=C

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,4 +561,5 @@ cython_debug/
561561
#.idea/
562562

563563
# Repo Specific
564-
*Outputs.json
564+
*Outputs.json
565+
*.pdf.json

.vscode/extensions.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"recommendations": [
3+
"ms-python.vscode-pylance",
4+
"ms-python.python",
5+
"ms-python.debugpy",
6+
"ms-toolsai.jupyter",
7+
"ms-azuretools.vscode-bicep",
8+
"ms-vscode.vscode-node-azure-pack",
9+
"ms-vscode.powershell",
10+
"GitHub.vscode-pull-request-github"
11+
]
12+
}

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"python.terminal.activateEnvironment": true
3+
}

README.md

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
page_type: sample
33
languages:
4-
- python
5-
- bicep
4+
- python
5+
- bicep
66
products:
7-
- azure
8-
- ai-services
9-
- azure-openai
7+
- azure
8+
- ai-services
9+
- azure-openai
1010
name: Document Processing with Azure AI Samples
1111
description: This collection of samples demonstrates how to use various Azure AI capabilities to build solution to extract structured data, classify, and analyze documents.
1212
---
@@ -27,6 +27,9 @@ The techniques demonstrated take advance of various capabilities from each servi
2727

2828
- [Samples](#samples)
2929
- [Getting Started](#getting-started)
30+
- [Setup on GitHub Codespaces](#setup-on-github-codespaces)
31+
- [Setup on Local](#setup-on-local)
32+
- [Deploy the Azure environment](#deploy-the-azure-environment)
3033
- [Contributing](#contributing)
3134
- [License](#license)
3235

@@ -35,38 +38,53 @@ The techniques demonstrated take advance of various capabilities from each servi
3538
> [!NOTE]
3639
> All data extraction samples provide both an accuracy and confidence score for the extracted data. The accuracy score is calculated based on the similarity between the extracted data and the ground truth data. The confidence score is calculated based on OCR analysis confidence and `logprobs` in Azure OpenAI requests.
3740
38-
| Sample | Description | Example Use Cases |
39-
| -------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
40-
| [Data Extraction - Azure AI Document Intelligence + Azure OpenAI GPT-4o](./samples/extraction/text-based/document-intelligence-openai.ipynb) | Demonstrates how to use Azure AI Document Intelligence pre-built layout and Azure OpenAI GPT models to extract structured data from documents. | Predominantly text-based documents such as invoices, receipts, and forms. |
41-
| [Data Extraction - Azure AI Document Intelligence + Phi-3.5 MoE](./samples/extraction/text-based/document-intelligence-phi.ipynb) | Demonstrates how to use Azure AI Document Intelligence pre-built layout and Microsoft's Phi-3 models to extract structured data from documents. | Predominantly text-based documents such as invoices, receipts, and forms. |
42-
| [Data Extraction - Marker/Surya + Azure OpenAI GPT-4o](./samples/extraction/text-based/marker-surya-openai.ipynb) | Demonstrates how to use Marker/Surya and Azure OpenAI GPT models to extract structured data from documents. | Predominantly text-based documents such as invoices, receipts, and forms. |
43-
| [Data Extraction - Azure OpenAI GPT-4o with Vision](./samples/extraction/vision-based/openai.ipynb) | Demonstrates how to use Azure OpenAI GPT-4o and GPT-4o-mini models to extract structured data from documents using their built-in vision capabilities. | Complex documents with a mix of text and images, including diagrams, signatures, selection marks, etc. such as reports and contracts. |
44-
| [Data Extraction - Comprehensive Azure AI Document Intelligence + Azure OpenAI GPT-4o with Vision](./samples/extraction/vision-based/comprehensive.ipynb) | Demonstrates how to improve the accuracy and confidence in extracting structured data from documents by combining Azure AI Document Intelligence and Azure OpenAI GPT-4o models with vision capabilities. | Any structured or unstructured document type. |
45-
| [Classification - Azure OpenAI GPT-4o with Vision](./samples/classification/openai.ipynb) | Demonstrates how to use Azure OpenAI GPT-4o and GPT-4o-mini models to classify documents using their built-in vision capabilities. | Processing multiple documents types or documents with varying purposes, such as contracts, legal documents, and emails. |
46-
| [Classification - Azure AI Document Intelligence + Embeddings](./samples/classification/document-intelligence-embeddings.ipynb) | Demonstrates how to use Azure AI Document Intelligence pre-built layout and embeddings models to classify documents based on their content. | Processing multiple documents types or documents with varying purposes, such as contracts, legal documents, and emails. |
41+
| Sample | Description | Example Use Cases |
42+
| --------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
43+
| [Data Extraction - Azure AI Document Intelligence + Azure OpenAI GPT-4o](./samples/extraction/text-based/document-intelligence-openai.ipynb) | Demonstrates how to use Azure AI Document Intelligence pre-built layout and Azure OpenAI GPT models to extract structured data from documents. | Predominantly text-based documents such as invoices, receipts, and forms. |
44+
| [Data Extraction - Azure AI Document Intelligence + Phi-3.5 MoE](./samples/extraction/text-based/document-intelligence-phi.ipynb) | Demonstrates how to use Azure AI Document Intelligence pre-built layout and Microsoft's Phi-3 models to extract structured data from documents. | Predominantly text-based documents such as invoices, receipts, and forms. |
45+
| [Data Extraction - Marker/Surya + Azure OpenAI GPT-4o](./samples/extraction/text-based/marker-surya-openai.ipynb) | Demonstrates how to use Marker/Surya and Azure OpenAI GPT models to extract structured data from documents. | Predominantly text-based documents such as invoices, receipts, and forms. |
46+
| [Data Extraction - Azure OpenAI GPT-4o with Vision](./samples/extraction/vision-based/openai.ipynb) | Demonstrates how to use Azure OpenAI GPT-4o and GPT-4o-mini models to extract structured data from documents using their built-in vision capabilities. | Complex documents with a mix of text and images, including diagrams, signatures, selection marks, etc. such as reports and contracts. |
47+
| [Data Extraction - Comprehensive Azure AI Document Intelligence + Azure OpenAI GPT-4o with Vision](./samples/extraction/vision-based/comprehensive.ipynb) | Demonstrates how to improve the accuracy and confidence in extracting structured data from documents by combining Azure AI Document Intelligence and Azure OpenAI GPT-4o models with vision capabilities. | Any structured or unstructured document type. |
48+
| [Classification - Azure OpenAI GPT-4o with Vision](./samples/classification/openai.ipynb) | Demonstrates how to use Azure OpenAI GPT-4o and GPT-4o-mini models to classify documents using their built-in vision capabilities. | Processing multiple documents types or documents with varying purposes, such as contracts, legal documents, and emails. |
49+
| [Classification - Azure AI Document Intelligence + Embeddings](./samples/classification/document-intelligence-embeddings.ipynb) | Demonstrates how to use Azure AI Document Intelligence pre-built layout and embeddings models to classify documents based on their content. | Processing multiple documents types or documents with varying purposes, such as contracts, legal documents, and emails. |
4750

4851
## Getting Started
4952

50-
The sample repository comes with a [**Dev Container**](./.devcontainer/README.md) that contains all the necessary tools and dependencies to run the sample. To use the Dev Container, you need to have the following tools installed on your local machine:
53+
The sample repository comes with a [**Dev Container**](./.devcontainer/README.md) that contains all the necessary tools and dependencies to run the sample.
54+
55+
> [!IMPORTANT]
56+
> An Azure subscription is required to run these samples. If you don't have an Azure subscription, create an [account](https://azure.microsoft.com/en-us/).
57+
58+
### Setup on GitHub Codespaces
59+
60+
To use the Dev Container in GitHub Codespaces, follow these steps:
61+
62+
1. Click on the `Code` button in the repository and select `Codespaces`.
63+
2. Click on the **+** button to create a new Codespace using the provided `.devcontainer\devcontainer.json` configuration.
64+
3. Once the Codespace is created, continue to the [Azure environment setup](#deploy-the-azure-environment) section.
65+
66+
### Setup on Local
67+
68+
To use the Dev Container, you need to have the following tools installed on your local machine:
5169

5270
- Install [**Visual Studio Code**](https://code.visualstudio.com/download)
5371
- Install [**Docker Desktop**](https://www.docker.com/products/docker-desktop)
5472
- Install [**Remote - Containers**](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension for Visual Studio Code
5573

56-
Additionally, you will require:
57-
58-
- An Azure subscription. If you don't have an Azure subscription, create an [account](https://azure.microsoft.com/en-us/).
59-
6074
To setup a local development environment, follow these steps:
6175

62-
> [!NOTE]
76+
> [!IMPORTANT]
6377
> Ensure that Docker Desktop is running on your local machine.
6478
6579
1. Clone the repository to your local machine.
6680
2. Open the repository in Visual Studio Code.
6781
3. Press `F1` to open the command palette and type `Dev Containers: Reopen in Container`.
6882

69-
Once the Dev Container is up and running, you can setup the necessary Azure services and run the [samples](#samples) in the repository by running the following command in VS Code's `pwsh` terminal:
83+
Once the Dev Container is up and running, continue to the [Azure environment setup](#deploy-the-azure-environment) section.
84+
85+
### Deploy the Azure environment
86+
87+
Once the Dev Container is up and running, you can setup the necessary Azure services and run the [samples](#samples) in the repository by running the following command in a `pwsh` terminal:
7088

7189
> [!NOTE]
7290
> For the most optimal sample experience, it is recommended to run the samples in `East US` which will provide support for all the services used in the samples. Find out more about region availability for [Azure AI Document Intelligence](https://learn.microsoft.com/en-us/azure/ai-services/document-intelligence/concept-layout?view=doc-intel-4.0.0&tabs=sample-code), and [`GPT-4o`](https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models#standard-and-global-standard-deployment-model-quota), [`Phi-3.5 MoE`](https://azure.microsoft.com/en-us/pricing/details/phi-3/), and [`text-embedding-3-large`](https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models#standard-deployment-model-availability) models.
@@ -77,6 +95,9 @@ az login
7795
./Setup-Environment.ps1 -DeploymentName <UniqueDeploymentName> -Location <AzureRegion> -SkipInfrastructure $false
7896
```
7997

98+
> [!NOTE]
99+
> If a specific tenant is required, use the `--tenant <TenantId>` parameter in the `az login` command.
100+
80101
The script will deploy the following resources to your Azure subscription:
81102

82103
- [**Azure AI Studio Hub & Project**](https://learn.microsoft.com/en-us/azure/ai-studio/what-is-ai-studio), a development platform for building AI solutions that integrates with Azure AI Services in a secure manner using Microsoft Entra ID for authentication.

Setup-Environment.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ $Phi3PrimaryKey = (az keyvault secret show --vault-name $KeyVaultName --name $Ph
6868
Write-Host "Updating local settings..."
6969

7070
$ConfigurationFile = './.env'
71+
if (-not (Test-Path -Path $ConfigurationFile)) {
72+
New-Item -Path $ConfigurationFile -ItemType File
73+
}
7174

7275
Set-ConfigurationFileVariable -configurationFile $ConfigurationFile -variableName 'RESOURCE_GROUP_NAME' -variableValue $ResourceGroupName
7376
Set-ConfigurationFileVariable -configurationFile $ConfigurationFile -variableName 'MANAGED_IDENTITY_CLIENT_ID' -variableValue $ManagedIdentityClientId

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ azure-ai-documentintelligence==1.0.0b4
22
azure-core==1.32.0
33
azure-identity==1.19.0
44
azure-storage-blob==12.24.0
5+
httpx==0.25.2
56
ipycanvas==0.13.3
67
ipykernel==6.29.5
78
marker-pdf==0.3.10

0 commit comments

Comments
 (0)