Skip to content

Commit d15c788

Browse files
Merge pull request #37 from privateai/restore-process-file-uri-py
Restore process_file_uri.py
2 parents 1132b9e + 4b0a6a1 commit d15c788

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

python/examples/process_file_base64.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Example script to illustrate how to make API calls to the Private AI API
2-
# to deidentify text using the unique PII markers feature.
2+
# to deidentify a provided file via base64 encoding.
33

44

55
import base64

python/examples/process_file_directory_base64.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@
7474
resp = client.process_files_base64(request_object=request_obj)
7575
if not resp.ok:
7676
print(f"response for file {file_name} returned with {resp.status_code}")
77-
78-
# Write to file
79-
with open(os.path.join(output_dir_path, f"redacted-{file_name}"), 'wb') as redacted_file:
80-
processed_file = resp.processed_file.encode()
81-
processed_file = base64.b64decode(processed_file, validate=True)
82-
redacted_file.write(processed_file)
77+
else:
78+
# Write to file
79+
with open(os.path.join(output_dir_path, f"redacted-{file_name}"), 'wb') as redacted_file:
80+
processed_file = resp.processed_file.encode()
81+
processed_file = base64.b64decode(processed_file, validate=True)
82+
redacted_file.write(processed_file)
83+
print(f"File redaction completed: {redacted_file.name}")
8384
else:
8485
print(f"File {file_name} not supported and will not be redacted.")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Example script to illustrate how to make API calls to the Private AI API
2+
# to deidentify a provided file via local file URI.
3+
4+
from privateai_client import PAIClient
5+
from privateai_client.objects import request_objects
6+
7+
input_file = "examples/data/PAI_SYNTH_EN_medical-referral_2.pdf"
8+
9+
client = PAIClient("http", "localhost", "8080")
10+
11+
req_obj = request_objects.file_uri_obj(uri=input_file)
12+
# NOTE this method of file processing requires the container to have an the input and output directories mounted
13+
resp = client.process_files_uri(req_obj)
14+
if resp.ok:
15+
print(f"File redaction completed: {resp.result_uri}")
16+
else:
17+
print(f"response for file {input_file} returned with {resp.status_code}")
18+

0 commit comments

Comments
 (0)