Skip to content

Commit

Permalink
Merge pull request #37 from privateai/restore-process-file-uri-py
Browse files Browse the repository at this point in the history
Restore process_file_uri.py
  • Loading branch information
bryanbellsmith authored Aug 22, 2024
2 parents 1132b9e + 4b0a6a1 commit d15c788
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion python/examples/process_file_base64.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Example script to illustrate how to make API calls to the Private AI API
# to deidentify text using the unique PII markers feature.
# to deidentify a provided file via base64 encoding.


import base64
Expand Down
13 changes: 7 additions & 6 deletions python/examples/process_file_directory_base64.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@
resp = client.process_files_base64(request_object=request_obj)
if not resp.ok:
print(f"response for file {file_name} returned with {resp.status_code}")

# Write to file
with open(os.path.join(output_dir_path, f"redacted-{file_name}"), 'wb') as redacted_file:
processed_file = resp.processed_file.encode()
processed_file = base64.b64decode(processed_file, validate=True)
redacted_file.write(processed_file)
else:
# Write to file
with open(os.path.join(output_dir_path, f"redacted-{file_name}"), 'wb') as redacted_file:
processed_file = resp.processed_file.encode()
processed_file = base64.b64decode(processed_file, validate=True)
redacted_file.write(processed_file)
print(f"File redaction completed: {redacted_file.name}")
else:
print(f"File {file_name} not supported and will not be redacted.")
18 changes: 18 additions & 0 deletions python/examples/process_file_uri.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Example script to illustrate how to make API calls to the Private AI API
# to deidentify a provided file via local file URI.

from privateai_client import PAIClient
from privateai_client.objects import request_objects

input_file = "examples/data/PAI_SYNTH_EN_medical-referral_2.pdf"

client = PAIClient("http", "localhost", "8080")

req_obj = request_objects.file_uri_obj(uri=input_file)
# NOTE this method of file processing requires the container to have an the input and output directories mounted
resp = client.process_files_uri(req_obj)
if resp.ok:
print(f"File redaction completed: {resp.result_uri}")
else:
print(f"response for file {input_file} returned with {resp.status_code}")

0 comments on commit d15c788

Please sign in to comment.