Skip to content

Commit 7061947

Browse files
authored
Merge pull request #50 from Azure-Samples/scenario_improvements
Refactor scenarios and modules to improve readability
2 parents 2175391 + b4a1239 commit 7061947

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+6092
-3251
lines changed

.devcontainer/README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ The following tools are included in the devcontainer:
1313
- **PowerShell Core** - Used for running deployment scripts for the necessary infrastructure.
1414
- **Azure CLI** - Used to managed the Azure resources.
1515
- **Azure Developer CLI** - Used to manage the Azure resources.
16-
- **.NET 8.0 SDK** - Used for .NET samples.
17-
- **Node 22.x** - Used for JavaScript samples.
1816
- **Python 3.12** - Used for Python samples.
1917
- **GitHub CLI** - Used to interact with the GitHub repository.
2018
- **Docker-in-Docker** - Used to run Docker containers from within the devcontainer.
@@ -30,9 +28,7 @@ The following VS Code extensions are included in the devcontainer:
3028
- **Bicep** - Bicep language support.
3129
- **Azure Tools** - Azure resource management support.
3230
- **PowerShell** - PowerShell language support.
33-
- **C# Dev Kit** - C# language support.
3431
- **GitHub Pull Requests** - GitHub pull request support.
35-
- **Polyglot Notebooks** - Jupyter notebook support for C# and PowerShell.
3632

3733
## Python Dependencies
3834

@@ -44,7 +40,6 @@ The following Python dependencies are included in the devcontainer:
4440
- **azure-storage-blob** - To interact with the Azure Blob Storage service.
4541
- **ipycanvas** - To create interactive canvases in Jupyter notebooks.
4642
- **ipykernel** - To create Jupyter kernels.
47-
- **marker-pdf** - To extract text from PDF files as Markdown.
4843
- **matplotlib** - To create plots in Jupyter notebooks.
4944
- **notebook** - To create Jupyter notebooks.
5045
- **numpy** - To work with numerical data.
@@ -57,6 +52,5 @@ The following Python dependencies are included in the devcontainer:
5752
- **pytesseract** - To extract text from images.
5853
- **python-dotenv** - To load environment variables from a `.env` file.
5954
- **seaborn** - To create plots in Jupyter notebooks.
60-
- **surya-ocr** - To extract text from images.
55+
- **tabulate** - To create tables in Jupyter notebooks.
6156
- **tiktoken** - To calculate confidence scores for structured outputs using OpenAI's logprobs.
62-
- **transformers** - To interact with the Hugging Face Transformers library.

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ The techniques demonstrated take advance of various capabilities from each servi
4242
| --------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
4343
| [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. |
4444
| [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. |
4645
| [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. |
4746
| [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. |
4847
| [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. |

Setup-Environment.ps1

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
1-
<#
2-
.SYNOPSIS
3-
Deploys the infrastructure and applications required to run the solution.
4-
.PARAMETER DeploymentName
5-
The name of the deployment.
6-
.PARAMETER Location
7-
The location of the deployment.
8-
.PARAMETER SkipInfrastructure
9-
Whether to skip the infrastructure deployment. Requires InfrastructureOutputs.json to exist in the infra directory.
10-
.EXAMPLE
11-
.\Setup-Environment.ps1 -DeploymentName 'ai-document-data-extraction' -Location 'eastus' -SkipInfrastructure $false
12-
.NOTES
13-
Author: James Croft
14-
#>
15-
161
param
172
(
183
[Parameter(Mandatory = $true)]
194
[string]$DeploymentName,
205
[Parameter(Mandatory = $true)]
216
[string]$Location,
22-
[Parameter(Mandatory = $true)]
23-
[string]$SkipInfrastructure
7+
[switch]$WhatIf
248
)
259

2610
function Set-ConfigurationFileVariable($configurationFile, $variableName, $variableValue) {
@@ -36,19 +20,14 @@ function Set-ConfigurationFileVariable($configurationFile, $variableName, $varia
3620

3721
Write-Host "Starting environment setup..."
3822

39-
if ($SkipInfrastructure -eq '$false' -or -not (Test-Path -Path './infra/InfrastructureOutputs.json')) {
40-
Write-Host "Deploying infrastructure..."
41-
$InfrastructureOutputs = (./infra/Deploy-Infrastructure.ps1 `
42-
-DeploymentName $DeploymentName `
43-
-Location $Location)
44-
}
45-
else {
46-
Write-Host "Skipping infrastructure deployment. Using existing outputs..."
47-
$InfrastructureOutputs = Get-Content -Path './infra/InfrastructureOutputs.json' -Raw | ConvertFrom-Json
48-
}
23+
Write-Host "Deploying infrastructure..."
24+
$InfrastructureOutputs = (./infra/Deploy-Infrastructure.ps1 `
25+
-DeploymentName $DeploymentName `
26+
-Location $Location `
27+
-WhatIf:$WhatIf)
4928

5029
if (-not $InfrastructureOutputs) {
51-
Write-Error "Infrastructure deployment outputs are not available. Exiting..."
30+
Write-Error "Failed to deploy infrastructure."
5231
exit 1
5332
}
5433

infra/Deploy-Infrastructure.ps1

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,65 @@
1-
<#
2-
.SYNOPSIS
3-
Deploys the core infrastructure for the AI Document Data Extraction demos to an Azure subscription.
4-
.DESCRIPTION
5-
This script initiates the deployment of the main.bicep template to the current default Azure subscription,
6-
determined by the Azure CLI. The deployment name and location are required parameters.
7-
.PARAMETER DeploymentName
8-
The name of the deployment to create in an Azure subscription.
9-
.PARAMETER Location
10-
The location to deploy the Azure resources to.
11-
.EXAMPLE
12-
.\Deploy-Infrastructure.ps1 -DeploymentName "ai-document-data-extraction" -Location "eastus"
13-
.NOTES
14-
Author: James Croft
15-
#>
16-
171
param
182
(
193
[Parameter(Mandatory = $true)]
204
[string]$DeploymentName,
215
[Parameter(Mandatory = $true)]
22-
[string]$Location
6+
[string]$Location,
7+
[switch]$WhatIf
238
)
249

2510
Write-Host "Starting infrastructure deployment..."
2611

2712
Push-Location -Path $PSScriptRoot
2813

29-
az --version
30-
31-
$userPrincipalId = ((az rest --method GET --uri "https://graph.microsoft.com/v1.0/me") | ConvertFrom-Json).id
32-
33-
$DeploymentOutputs = (az deployment sub create --name $DeploymentName --location $Location --template-file './main.bicep' `
14+
$principalId = (az ad signed-in-user show --query id -o tsv)
15+
$identity = @{
16+
"principalId" = "$principalId"
17+
"principalType" = "User"
18+
}
19+
$identityArray = ConvertTo-Json @($identity) -Depth 5 -Compress
20+
21+
if ($whatIf) {
22+
Write-Host "Previewing Azure infrastructure deployment. No changes will be made."
23+
24+
$result = (az deployment sub what-if `
25+
--name $deploymentName `
26+
--location $location `
27+
--template-file './main.bicep' `
28+
--parameters './main.parameters.json' `
29+
--parameters workloadName=$deploymentName `
30+
--parameters location=$location `
31+
--parameters identities=$identityArray `
32+
--no-pretty-print) | ConvertFrom-Json
33+
34+
if (-not $result) {
35+
Write-Error "Azure infrastructure deployment preview failed."
36+
exit 1
37+
}
38+
39+
Write-Host "Azure infrastructure deployment preview succeeded."
40+
$result.changes | Format-List
41+
exit
42+
}
43+
44+
$deploymentOutputs = (az deployment sub create `
45+
--name $deploymentName `
46+
--location $location `
47+
--template-file './main.bicep' `
3448
--parameters './main.parameters.json' `
35-
--parameters workloadName=$DeploymentName `
36-
--parameters location=$Location `
37-
--parameters userPrincipalId=$userPrincipalId `
49+
--parameters workloadName=$deploymentName `
50+
--parameters location=$location `
51+
--parameters identities=$identityArray `
3852
--query properties.outputs -o json) | ConvertFrom-Json
39-
$DeploymentOutputs | ConvertTo-Json | Out-File -FilePath './InfrastructureOutputs.json' -Encoding utf8
53+
54+
if (-not $deploymentOutputs) {
55+
Write-Error "Azure infrastructure deployment failed."
56+
exit 1
57+
}
58+
59+
Write-Host "Azure infrastructure deployment succeeded."
60+
$deploymentOutputs | Format-List
61+
$deploymentOutputs | ConvertTo-Json | Out-File -FilePath './InfrastructureOutputs.json' -Encoding utf8
4062

4163
Pop-Location
42-
43-
return $DeploymentOutputs
64+
65+
return $deploymentOutputs

infra/ai_ml/ai-hub.bicep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ param keyVaultId string
3939
@description('ID for the Application Insights associated with the AI Hub.')
4040
param applicationInsightsId string
4141
@description('ID for the Container Registry associated with the AI Hub.')
42-
param containerRegistryId string
42+
param containerRegistryId string?
4343
@description('ID for the Managed Identity associated with the AI Hub. Defaults to the system-assigned identity.')
4444
param identityId string?
4545
@description('Name for the AI Services resource to connect to.')

0 commit comments

Comments
 (0)