Skip to content

Commit bde2a8c

Browse files
Improve Segmentation Description and Adjust Timeout (#104)
1 parent 13b835b commit bde2a8c

File tree

4 files changed

+57
-35
lines changed

4 files changed

+57
-35
lines changed

notebooks/build_person_directory.ipynb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@
2222
"| ![PD_enrollment.png](https://media.githubusercontent.com/media/Azure-Samples/azure-ai-content-understanding-python/refs/heads/zhizho/face/data/face/PD_enrollment.png) | ![PD_searching.png](https://media.githubusercontent.com/media/Azure-Samples/azure-ai-content-understanding-python/refs/heads/zhizho/face/data/face/PD_searching.png) |"
2323
]
2424
},
25+
{
26+
"cell_type": "markdown",
27+
"id": "3f0b1227",
28+
"metadata": {},
29+
"source": [
30+
"## Prerequisites\n",
31+
"1. Please ensure your Azure AI service is configured by following the [configuration steps](../README.md#configure-azure-ai-service-resource).\n",
32+
"2. Please install the required packages to run this sample."
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": null,
38+
"id": "08b48760",
39+
"metadata": {},
40+
"outputs": [],
41+
"source": [
42+
"%pip install -r ../requirements.txt"
43+
]
44+
},
2545
{
2646
"cell_type": "markdown",
2747
"id": "80a375ca",

notebooks/field_extraction.ipynb

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"source": [
2121
"## Prerequisites\n",
2222
"1. Please ensure your Azure AI service is configured by following the [configuration steps](../README.md#configure-azure-ai-service-resource).\n",
23-
"2. Install the required packages to run this sample."
23+
"2. Please install the required packages to run this sample."
2424
]
2525
},
2626
{
@@ -38,12 +38,12 @@
3838
"source": [
3939
"## Create Azure AI Content Understanding Client\n",
4040
"\n",
41-
"> The [AzureContentUnderstandingClient](../python/content_understanding_client.py) is a utility class providing functions to interact with the Content Understanding API. Before the official release of the Content Understanding SDK, it acts as a lightweight SDK. Please fill in the constants **AZURE_AI_ENDPOINT** and **AZURE_AI_API_VERSION** with your Azure AI Service information. Optionally, you may provide **AZURE_AI_API_KEY** if your setup requires key-based authentication.\n",
41+
"> The [AzureContentUnderstandingClient](../python/content_understanding_client.py) is a utility class providing functions to interact with the Content Understanding API. Before the official release of the Content Understanding SDK, this acts as a lightweight SDK. Please fill in the constants **AZURE_AI_ENDPOINT** and **AZURE_AI_API_VERSION** with your Azure AI Service information. Optionally, you may provide **AZURE_AI_API_KEY** if your setup requires key-based authentication.\n",
4242
"\n",
4343
"> ⚠️ Important:\n",
4444
"Please update the code below to match your Azure authentication method.\n",
4545
"Look for the `# IMPORTANT` comments and modify those sections accordingly.\n",
46-
"Skipping this step may cause the sample to not run correctly.\n",
46+
"Skipping this step may prevent the sample from running correctly.\n",
4747
"\n",
4848
"> ⚠️ Note: Using a subscription key works, but using a token provider with Azure Active Directory (AAD) is safer and highly recommended for production environments."
4949
]
@@ -105,11 +105,11 @@
105105
"This notebook demonstrates field extraction across multiple modalities using Azure AI Content Understanding. We will walk through each modality step-by-step:\n",
106106
"\n",
107107
"1. **Document Analysis** - Extract fields from invoices and receipts\n",
108-
"2. **Audio Analysis** - Process call recordings and conversational audio \n",
108+
"2. **Audio Analysis** - Process call recordings and conversational audio\n",
109109
"3. **Video Analysis** - Analyze marketing videos and extract insights\n",
110110
"4. **Image Analysis** - Extract information from charts and images\n",
111111
"\n",
112-
"Each section will create an analyzer, process sample data, display results, and clean up the analyzer before moving on to the next modality."
112+
"Each section will create an analyzer, process sample data, display results, and clean up the analyzer before moving to the next modality."
113113
]
114114
},
115115
{
@@ -122,7 +122,7 @@
122122
"\n",
123123
"**Key Schema Components:**\n",
124124
"\n",
125-
"- **`baseAnalyzerId`**: Crucial setting that specifies the prebuilt analyzer to derive from (e.g., `prebuilt-documentAnalyzer`, `prebuilt-audioAnalyzer`, `prebuilt-videoAnalyzer`, `prebuilt-imageAnalyzer`, `prebuilt-callCenter`). This provides foundational capabilities for your custom analyzer.\n",
125+
"- **`baseAnalyzerId`**: Crucial setting specifying the prebuilt analyzer to derive from (e.g., `prebuilt-documentAnalyzer`, `prebuilt-audioAnalyzer`, `prebuilt-videoAnalyzer`, `prebuilt-imageAnalyzer`, `prebuilt-callCenter`). This provides foundational capabilities for your custom analyzer.\n",
126126
"\n",
127127
"- **`fields`**: Defines specific data points to extract. Each field includes:\n",
128128
" - **Field name**: Identifier for the extracted data (required and important for referencing results)\n",
@@ -256,7 +256,7 @@
256256
"source": [
257257
"**Clean Up Invoice Analyzer**\n",
258258
"\n",
259-
"Optionally clean up the analyzer to manage resources (in production, analyzers are typically kept for reuse):"
259+
"Optionally, clean up the analyzer to manage resources (typically, analyzers are kept for reuse in production):"
260260
]
261261
},
262262
{
@@ -276,7 +276,7 @@
276276
"\n",
277277
"Now, let's analyze the same invoice but with enhanced field source information and confidence scores. This provides additional context about the location of each extracted field within the document.\n",
278278
"\n",
279-
"**Note**: This custom analyzer is for demonstration purposes only. In production, please start from `prebuilt-invoice` for invoice processing.\n",
279+
"**Note**: This custom analyzer is for demonstration purposes only. For production, please start from `prebuilt-invoice` for invoice processing.\n",
280280
"\n",
281281
"**Key Feature**: This analyzer template uses `estimateFieldSourceAndConfidence: true` in the 'config', enabling the service to provide detailed information about:\n",
282282
"- **Field source locations**: Exact coordinates and bounding boxes indicating where each field was found\n",
@@ -350,7 +350,7 @@
350350
"source": [
351351
"**Clean Up Invoice Field Source Analyzer**\n",
352352
"\n",
353-
"Optionally clean up the field source analyzer:"
353+
"Optionally, clean up the field source analyzer:"
354354
]
355355
},
356356
{
@@ -439,7 +439,7 @@
439439
"source": [
440440
"**Clean Up Receipt Analyzer**\n",
441441
"\n",
442-
"Optionally clean up the receipt analyzer:"
442+
"Optionally, clean up the receipt analyzer:"
443443
]
444444
},
445445
{
@@ -552,7 +552,7 @@
552552
"source": [
553553
"## 5. Conversational Audio Analytics\n",
554554
"\n",
555-
"Let's analyze the same audio file with a focus on conversational aspects like sentiment analysis and dialogue understanding.\n",
555+
"Let's analyze the same audio file focusing on conversational aspects such as sentiment analysis and dialogue understanding.\n",
556556
"\n",
557557
"Conversational audio analytics template:"
558558
]
@@ -645,23 +645,25 @@
645645
"source": [
646646
"## 6. Marketing Video Analysis\n",
647647
"\n",
648-
"Let's analyze a marketing video to extract descriptions, sentiment, and key insights that could be valuable for content understanding and marketing analytics.\n",
648+
"Let's analyze a marketing video to extract descriptions, sentiment, and key insights valuable for content understanding and marketing analytics.\n",
649649
"\n",
650650
"Content Understanding offers three segmentation options to slice a video, enabling you to get output for entire videos or short clips. You can specify these by setting the `segmentationMode` property in your custom analyzer:\n",
651-
"- Whole-video – `\"segmentationMode\": \"noSegmentation\"` \n",
652-
" The service treats the entire video file as a single segment and extracts metadata across its full duration. \n",
651+
"- Whole-video – `\"segmentationMode\": \"noSegmentation\"`\n",
652+
" The service treats the entire video file as a single segment and extracts metadata across its full duration.\n",
653653
" Examples:\n",
654654
" - Compliance checks looking for specific brand-safety issues anywhere in an ad\n",
655655
" - Full-length descriptive summaries\n",
656-
"- Automatic segmentation – `\"segmentationMode\": \"auto\"` \n",
657-
" The service analyzes the timeline, automatically segmenting the video. It groups successive shots into coherent scenes, capped at one minute each. \n",
656+
"- Automatic segmentation – `\"segmentationMode\": \"auto\"`\n",
657+
" The service analyzes the timeline, automatically segmenting the video. It groups successive shots into coherent scenes, capped at one minute each.\n",
658658
" Examples:\n",
659659
" - Creating storyboards from a show\n",
660660
" - Inserting mid-roll ads at logical pauses\n",
661-
"- Custom segmentation – `\"segmentationMode\": \"custom\"` \n",
662-
" You describe the segmentation logic in natural language, and the model creates segments accordingly. Set `segmentationDefinition` with a string describing your desired segmentation. Custom segmentation allows segments of varying length from seconds to minutes. \n",
661+
"- Custom segmentation – `\"segmentationMode\": \"custom\"`\n",
662+
" You describe the segmentation logic in natural language, and the model creates segments accordingly. Set `segmentationDefinition` with a string describing your desired segmentation. Custom segmentation allows segments of varying length from seconds to minutes.\n",
663663
" Example:\n",
664-
" - Breaking a news broadcast into distinct stories"
664+
" - Breaking a news broadcast into distinct stories\n",
665+
"\n",
666+
"> Important: The defined fields for segment analysis must be declared under `fieldSchema` → `fields` → `Segments` when setting `\"segmentationMode\"` as `\"auto\"` or `\"custom\"`. We will use the same set of fields for each video segment. You won't be able to create the analyzer successfully if other fields are set under `fieldSchema` → `fields`. In other words, whole video analysis cannot be combined with segment analysis."
665667
]
666668
},
667669
{
@@ -754,9 +756,9 @@
754756
"source": [
755757
"### 6-2 Analyze With Automatic Segmentation\n",
756758
"\n",
757-
"In this example, we use automatic segmentation for marketing video analytics. \n",
759+
"In this example, we use automatic segmentation for marketing video analytics.\n",
758760
"- Please set `segmentationMode` to `auto` in the analyzer schema `config` to enable automatic segmentation.\n",
759-
"- The defined fields for segment analysis must be declared under `fieldSchema` → `Segments`."
761+
"- The defined fields for segment analysis must be declared under `fieldSchema` → `fields` → `Segments`."
760762
]
761763
},
762764
{
@@ -803,7 +805,7 @@
803805
"metadata": {},
804806
"source": [
805807
"Marketing video analysis result:\n",
806-
"- The output includes automatically segmented clips with descriptions in the markdown content. \n",
808+
"- The output includes automatically segmented clips with descriptions in the markdown content.\n",
807809
"- The analyzer generates the fields defined in the schema separately for each segment."
808810
]
809811
},
@@ -840,10 +842,10 @@
840842
"source": [
841843
"### 6-3 Analyze With Custom Segmentation\n",
842844
"\n",
843-
"In this example, we use custom segmentation for marketing video analytics. \n",
844-
"- Please set `segmentationMode` to `custom`. \n",
845+
"In this example, we use custom segmentation for marketing video analytics.\n",
846+
"- Please set `segmentationMode` to `custom`.\n",
845847
"- Provide a `segmentationDefinition` string describing how you'd like the video to be segmented.\n",
846-
"- The defined fields for segment analysis must be declared under `fieldSchema` → `Segments`."
848+
"- The defined fields for segment analysis must be declared under `fieldSchema` → `fields` → `Segments`."
847849
]
848850
},
849851
{
@@ -890,8 +892,8 @@
890892
"metadata": {},
891893
"source": [
892894
"Marketing video analysis result:\n",
893-
"- The video is segmented according to your custom definition, with segment descriptions included in the markdown content. \n",
894-
"- The segmentation may differ from automatic segmentation results. \n",
895+
"- The video is segmented according to your custom definition, with segment descriptions included in the markdown content.\n",
896+
"- The segmentation may differ from automatic segmentation results.\n",
895897
"- The analyzer generates the fields defined in the schema separately for each segment."
896898
]
897899
},
@@ -1021,9 +1023,9 @@
10211023
"\n",
10221024
"🎉 **Congratulations!** You have successfully explored all the major modalities of Azure AI Content Understanding:\n",
10231025
"\n",
1024-
"✅ **Document Analysis**: Extracted fields from invoices and receipts \n",
1025-
"✅ **Audio Analysis**: Analyzed call recordings and conversational audio \n",
1026-
"✅ **Video Analysis**: Processed marketing videos for insights \n",
1026+
"✅ **Document Analysis**: Extracted fields from invoices and receipts\n",
1027+
"✅ **Audio Analysis**: Analyzed call recordings and conversational audio\n",
1028+
"✅ **Video Analysis**: Processed marketing videos for insights\n",
10271029
"✅ **Image Analysis**: Extracted information from charts and visual content\n",
10281030
"\n",
10291031
"## Key Takeaways\n",
@@ -1058,9 +1060,9 @@
10581060
"name": "python",
10591061
"nbconvert_exporter": "python",
10601062
"pygments_lexer": "ipython3",
1061-
"version": "3.11.13"
1063+
"version": "3.11.12"
10621064
}
10631065
},
10641066
"nbformat": 4,
10651067
"nbformat_minor": 2
1066-
}
1068+
}

python/content_understanding_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from azure.storage.blob.aio import ContainerClient
2121

2222

23-
POLL_TIMEOUT_SECONDS = 120
23+
POLL_TIMEOUT_SECONDS = 180
2424

2525

2626
@dataclass

tools/test_notebooks/test_notebooks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ def run_all_notebooks(
9898
if __name__ == "__main__":
9999
args: List[str] = sys.argv[1:]
100100

101-
# NOTE: Define skip list (can use full paths or substrings)
101+
# NOTE: Define skip list (can use full paths or substrings, e.g., "notebook_name.ipynb")
102102
skip_list = [
103-
"build_person_directory.ipynb", # Skip due to "new_face_image_path" needed to be added manually
103+
"build_person_directory.ipynb", # Skip due to face API limit wasn't lifted
104104
]
105105

106106
if not args:

0 commit comments

Comments
 (0)