|
| 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 | + |
0 commit comments