Skip to content

Commit 5ade645

Browse files
feat(documents): add samples
1 parent 861e2db commit 5ade645

File tree

7 files changed

+1935
-0
lines changed

7 files changed

+1935
-0
lines changed

samples/documents/README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Document Understanding Sample
2+
3+
This sample demonstrates how to use UiPath Document Understanding capabilities with the UiPath Python SDK to classify, extract and validate data from documents.
4+
5+
## Overview
6+
7+
Document Understanding enables automated processing of documents through:
8+
9+
- **Classification**: Identify document types
10+
- **Extraction**: Extract data from classified documents
11+
- **Validation**: Create human-in-the-loop validation actions for review
12+
13+
This sample includes three Document Understanding approaches:
14+
15+
- **IXP (Intelligent Xtraction and Processing)** (`samples/ixp.py`) - [IXP documentation](https://docs.uipath.com/ixp/automation-cloud/latest/overview/introduction)
16+
- **Modern Projects** (`samples/du_modern.py`) - [Modern DU documentation](https://docs.uipath.com/document-understanding/automation-cloud/latest/user-guide/about-document-understanding)
17+
- **Pretrained Models** (`samples/pretrained.py`) - [Pretrained models documentation](https://docs.uipath.com/document-understanding/automation-cloud/latest/user-guide/out-of-the-box-pre-trained-ml-packages)
18+
19+
## Prerequisites
20+
21+
- UiPath Automation Suite or Automation Cloud tenant
22+
- Document Understanding projects deployed with appropriate tags
23+
- Action catalog configured for validation actions
24+
- Storage bucket for validation data
25+
26+
## Setup
27+
28+
1. **Install dependencies**:
29+
30+
```bash
31+
uv sync
32+
```
33+
34+
2. **Configure UiPath credentials and initialize project**:
35+
36+
```bash
37+
uv run uipath auth
38+
uv run uipath init
39+
```
40+
41+
3. **Update sample parameters**:
42+
43+
Edit the sample files to match your environment:
44+
- Project names and tags
45+
- Document type names
46+
- Action catalog and folder names
47+
- Storage bucket configuration
48+
49+
4. **Add test document**:
50+
51+
Place a `test.pdf` file in the project root for processing.
52+
53+
## Usage
54+
55+
Run the complete sample workflow:
56+
57+
```bash
58+
uipath run main.py '{"message": "test"}'
59+
```
60+
61+
Or run individual samples:
62+
63+
```python
64+
from samples import ixp, du_modern, pretrained
65+
66+
# IXP extraction and validation
67+
ixp.extract_validate()
68+
69+
# Modern project
70+
du_modern.extract_validate()
71+
du_modern.classify_extract_validate()
72+
73+
# Pretrained model
74+
pretrained.extract_validate()
75+
pretrained.classify_extract_validate()
76+
```

samples/documents/main.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from dataclasses import dataclass
2+
from samples import ixp, du_modern, pretrained
3+
4+
5+
@dataclass
6+
class EchoIn:
7+
message: str
8+
9+
10+
@dataclass
11+
class EchoOut:
12+
message: str
13+
14+
def main(input: EchoIn) -> EchoOut:
15+
ixp.extract_validate()
16+
17+
du_modern.extract_validate()
18+
du_modern.classify_extract_validate()
19+
20+
pretrained.extract_validate()
21+
pretrained.classify_extract_validate()
22+
23+
return EchoOut(message="")

samples/documents/pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[project]
2+
name = "documents"
3+
version = "0.1.0"
4+
authors = [{ name = "John Doe" }]
5+
description = "Add your description here"
6+
readme = "README.md"
7+
requires-python = ">=3.10"
8+
dependencies = [
9+
"uipath>=2.1.173",
10+
]
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from uipath import UiPath
2+
from uipath.models.documents import ProjectType, ActionPriority
3+
4+
TAG = "Production"
5+
PROJECT_NAME = "TestModernProject"
6+
7+
def extract_validate():
8+
uipath = UiPath()
9+
10+
extraction_response = uipath.documents.extract(
11+
tag=TAG,
12+
project_name=PROJECT_NAME,
13+
project_type=ProjectType.MODERN,
14+
document_type_name="TestDocumentType",
15+
file_path="test.pdf",
16+
)
17+
18+
validation_action = uipath.documents.create_validate_extraction_action(
19+
action_title="Test Validation Action",
20+
action_priority=ActionPriority.MEDIUM,
21+
action_catalog="default_du_actions",
22+
action_folder="Shared",
23+
storage_bucket_name="du_storage_bucket",
24+
storage_bucket_directory_path="TestDirectory",
25+
extraction_response=extraction_response,
26+
)
27+
28+
uipath.documents.get_validate_extraction_result(
29+
validation_action=validation_action
30+
)
31+
32+
def classify_extract_validate():
33+
uipath = UiPath()
34+
35+
classification_results = uipath.documents.classify(
36+
tag=TAG,
37+
project_name=PROJECT_NAME,
38+
project_type=ProjectType.MODERN,
39+
file_path="test.pdf",
40+
)
41+
42+
validation_action = uipath.documents.create_validate_classification_action(
43+
action_title="Test Validation Action",
44+
action_priority=ActionPriority.MEDIUM,
45+
action_catalog="default_du_actions",
46+
action_folder="Shared",
47+
storage_bucket_name="du_storage_bucket",
48+
storage_bucket_directory_path="TestDirectory",
49+
classification_results=classification_results,
50+
)
51+
52+
validated_classification_results = uipath.documents.get_validate_classification_result(
53+
validation_action=validation_action
54+
)
55+
56+
best_confidence_result = max(validated_classification_results, key=lambda result: result.confidence)
57+
58+
extraction_response = uipath.documents.extract(classification_result=best_confidence_result)
59+
60+
validation_action = uipath.documents.create_validate_extraction_action(
61+
action_title="Test Extraction Validation Action",
62+
action_priority=ActionPriority.MEDIUM,
63+
action_catalog="default_du_actions",
64+
action_folder="Shared",
65+
storage_bucket_name="du_storage_bucket",
66+
storage_bucket_directory_path="TestDirectory",
67+
extraction_response=extraction_response,
68+
)
69+
70+
uipath.documents.get_validate_extraction_result(
71+
validation_action=validation_action
72+
)
73+

samples/documents/samples/ixp.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from uipath import UiPath
2+
from uipath.models.documents import ProjectType, ActionPriority
3+
4+
def extract_validate():
5+
uipath = UiPath()
6+
7+
extraction_response = uipath.documents.extract(
8+
tag="live",
9+
project_name="TestIxpProject",
10+
project_type=ProjectType.IXP,
11+
file_path="test.pdf",
12+
)
13+
14+
validation_action = uipath.documents.create_validate_extraction_action(
15+
action_title="Test Validation Action",
16+
action_priority=ActionPriority.MEDIUM,
17+
action_catalog="default_du_actions",
18+
action_folder="Shared",
19+
storage_bucket_name="du_storage_bucket",
20+
storage_bucket_directory_path="TestDirectory",
21+
extraction_response=extraction_response,
22+
)
23+
24+
uipath.documents.get_validate_extraction_result(
25+
validation_action=validation_action
26+
)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from uipath import UiPath
2+
from uipath.models.documents import ProjectType, ActionPriority
3+
4+
def extract_validate():
5+
uipath = UiPath()
6+
7+
extraction_response = uipath.documents.extract(
8+
project_type=ProjectType.PRETRAINED,
9+
document_type_name="invoices",
10+
file_path="test.pdf",
11+
)
12+
13+
extraction_action = uipath.documents.create_validate_extraction_action(
14+
action_title="Test Validation Action",
15+
action_priority=ActionPriority.MEDIUM,
16+
action_catalog="default_du_actions",
17+
action_folder="Shared",
18+
storage_bucket_name="du_storage_bucket",
19+
storage_bucket_directory_path="TestDirectory",
20+
extraction_response=extraction_response,
21+
)
22+
23+
uipath.documents.get_validate_extraction_result(
24+
validation_action=extraction_action
25+
)
26+
27+
def classify_extract_validate():
28+
uipath = UiPath()
29+
30+
classification_results = uipath.documents.classify(
31+
project_type=ProjectType.PRETRAINED, file_path="test.pdf"
32+
)
33+
34+
best_confidence_result = max(classification_results, key=lambda result: result.confidence)
35+
36+
extraction_response = uipath.documents.extract(
37+
classification_result=best_confidence_result
38+
)
39+
40+
extraction_action = uipath.documents.create_validate_extraction_action(
41+
action_title="Test Validation Action",
42+
action_priority=ActionPriority.MEDIUM,
43+
action_catalog="default_du_actions",
44+
action_folder="Shared",
45+
storage_bucket_name="du_storage_bucket",
46+
storage_bucket_directory_path="TestDirectory",
47+
extraction_response=extraction_response,
48+
)
49+
50+
uipath.documents.get_validate_extraction_result(
51+
validation_action=extraction_action
52+
)

0 commit comments

Comments
 (0)