File tree 1 file changed +21
-14
lines changed
1 file changed +21
-14
lines changed Original file line number Diff line number Diff line change @@ -34,30 +34,37 @@ from unstructured_client.models.errors import SDKError
34
34
35
35
s = UnstructuredClient(api_key_auth = " YOUR_API_KEY" )
36
36
37
- filename = " sample-docs/layout-parser-paper.pdf"
38
- file = open (filename, " rb" )
37
+ filename = " sample-docs/layout-parser-paper-fast.pdf"
39
38
40
- req = shared.PartitionParameters(
39
+ with open (filename, " rb " ) as f:
41
40
# Note that this currently only supports a single file
42
- files = shared.Files(
43
- content = file .read(),
44
- file_name = filename,
45
- ),
41
+ files= shared.Files(
42
+ content = f.read(),
43
+ file_name = filename,
44
+ )
45
+
46
+ req = shared.PartitionParameters(
47
+ files = files,
46
48
# Other partition params
47
- strategy = " fast" ,
49
+ strategy = ' ocr_only' ,
50
+ languages = [" eng" ],
48
51
)
49
52
50
53
try :
51
- res = s.general.partition(req)
52
- print (res .elements[0 ])
54
+ resp = s.general.partition(req)
55
+ print (resp .elements[0 ])
53
56
except SDKError as e:
54
57
print (e)
55
58
56
59
# {
57
- # 'type': 'Title',
58
- # 'element_id': '015301d4f56aa4b20ec10ac889d2343f',
59
- # 'metadata': {'filename': 'layout-parser-paper.pdf', 'filetype': 'application/pdf', 'page_number': 1},
60
- # 'text': 'LayoutParser: A Unified Toolkit for Deep Learning Based Document Image Analysis'
60
+ # 'type': 'UncategorizedText',
61
+ # 'element_id': 'fc550084fda1e008e07a0356894f5816',
62
+ # 'metadata': {
63
+ # 'filename': 'layout-parser-paper-fast.pdf',
64
+ # 'filetype': 'application/pdf',
65
+ # 'languages': ['eng'],
66
+ # 'page_number': 1
67
+ # }
61
68
# }
62
69
```
63
70
You can’t perform that action at this time.
0 commit comments