File tree Expand file tree Collapse file tree 1 file changed +21
-14
lines changed Expand file tree Collapse file tree 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
3434
3535s = UnstructuredClient(api_key_auth = " YOUR_API_KEY" )
3636
37- filename = " sample-docs/layout-parser-paper.pdf"
38- file = open (filename, " rb" )
37+ filename = " sample-docs/layout-parser-paper-fast.pdf"
3938
40- req = shared.PartitionParameters(
39+ with open (filename, " rb " ) as f:
4140 # 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,
4648 # Other partition params
47- strategy = " fast" ,
49+ strategy = ' ocr_only' ,
50+ languages = [" eng" ],
4851)
4952
5053try :
51- res = s.general.partition(req)
52- print (res .elements[0 ])
54+ resp = s.general.partition(req)
55+ print (resp .elements[0 ])
5356except SDKError as e:
5457 print (e)
5558
5659# {
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+ # }
6168# }
6269```
6370
You can’t perform that action at this time.
0 commit comments