Quickstart Guide

This quickstart guide covers how to set up and run the Private AI container.

info

If you'd like to use the Private AI-hosted API, which includes the free demo, please create a portal account and use the code examples provided in the portal.

Setting up the Container

The Private AI container can be deployed anywhere, but mostly commonly we see customer deployments on AWS and Azure. In all production deployments we recommend a Kubernetes deployment. For detailed installation instructions please see our installation guides.

Logging into the Customer Portal

When you are onboarded, a customer portal account will be created for you. In the portal you can find helpful links, download your license file and instructions on how to login to our container registry and pull the latest container image.

If you haven't received this information yet during your onboarding, please contact our customer support team via your dedicated Slack channel, or at support@private-ai.com

Getting the Container

info

The Private AI container comes in 4 different versions: cpu, cpu-text, gpu and gpu-text. Please see Grabbing the Image for details. In particular, if only process/text is required it is recommended to use the text-only container versions - they are smaller and require less resources to run.

Once you've logged into the customer portal, you will find some commands to get the latest container. The container is distributed via a container registry on Azure, which you can login to with the command found in the portal that looks like this:

Copy
Copied
docker login -u INSERT_UNIQUE_CLIENT_ID -p INSERT_UNIQUE_CLIENT_PW crprivateaiprod.azurecr.io

Please reach out to our customer support if you are experiencing issues.

Getting a License

When you are logged into the customer portal, you should find the license file (or files) assigned to your account in the top right of the main page. There will be a download link beside the file along with information about the license tier and expiry date.

Starting up the Container - CPU

Starting with 3.0, license files are used for authentication. To start the container, please mount the license file as follows:

Copy
Copied
docker run --rm -v "full path to your license.json file":/app/license/license.json \
-p 8080:8080 -it crprivateaiprod.azurecr.io/deid:<tag>

For example:

Copy
Copied
docker run --rm -v "/home/johnsmith/paisandbox/my-license-file.json":/app/license/license.json \
-p 8080:8080 -it crprivateaiprod.azurecr.io/deid:3.0.0-cpu

Starting up the Container - GPU

To run the GPU container, please install the Nvidia Container Toolkit first. The command to run the container is similar to CPU, except that the device must be specified and shared memory must be set:

Copy
Copied
docker run --gpus '"device=<GPU_ID, usually 0>"' --shm-size=<4g, only required for non-text container> --rm -v "full path to license.json":/app/license/license.json \
-p 8080:8080 -it crprivateaiprod.azurecr.io/deid:<version>

Please see Running the Container for more details.

Sending Requests

You can then make a request to the container like this:

Request BodycURLPythonPython Client
Copy
Copied
{
    "text": [
        "Hello John"
    ]
}
Copy
Copied
curl --request POST --url http://localhost:8080/v3/process/text --header 'Content-Type: application/json' --data '{"text": ["Hello John"]}'
Copy
Copied
import requests

r = requests.post(url="http://localhost:8080/v3/process/text",                  
                  json={"text": ["Hello John"]})

results = r.json()

print(results)
Copy
Copied
from privateai_client import PAIClient
from privateai_client import request_objects

client = PAIClient(url="http://localhost:8080/")

text_request = request_objects.process_text_obj(text=["Hello John"])
response = client.process_text(text_request)

print(response.processed_text)

Processing Files

Processing files can be done by sending base64-encoded files to the /v3/process/files/base64 route:

Request BodycURLPythonPython Client
Copy
Copied
{
    "file": {
        "data": file_content_base64,
        "content_type": "image/jpg",
    },
}
Copy
Copied
echo '{"file": {"data": "'$(base64 -w 0 sample.jpg)'", "content_type": "image/jpg"}}' \
| curl --request POST --url 'http://localhost:8080/v3/process/files/base64' \
-H 'Content-Type: application/json' -d @- | jq -r .processed_file | base64 -d > 'sample.redacted.jpeg'
Copy
Copied
import base64
import requests

# Specify the input and output file paths
filename_in = "<input filename>"
filename_out = "<output filename>"

# Read the file and do base64 encoding
with open(filename_in, "rb") as f:
    b64_file_content = base64.b64encode(f.read())
    b64_file_content = b64_file_content.decode("utf-8")

# Make the request and load the results as JSON
r = requests.post(url="http://localhost:8080/v3/process/files/base64", 
                  json={"file": {"data": b64_file_content, "content_type": "image/jpg"}})
results = r.json()

# Decode and write the file to disk
with open(filename_out, "wb") as f:
    f.write(base64.b64decode(results["processed_file"]))
Copy
Copied
from privateai_client import PAIClient
from privateai_client.objects import request_objects
import base64

# Specify the input and output file paths
filename_in = "sample.pdf"
filename_out = "sample.redacted.pdf"

file_type= "application/pdf"
client = PAIClient(url="http://localhost:8080/")

# Read from file
with open(filename_in, "rb") as b64_file:
    file_data = base64.b64encode(b64_file.read())
    file_data = file_data.decode("ascii")

# Make the request
file_obj = request_objects.file_obj(data=file_data, content_type=file_type)
request_obj = request_objects.file_base64_obj(file=file_obj)
resp = client.process_files_base64(request_object=request_obj)

# Write to file
with open(filename_out, 'wb') as redacted_file:
    processed_file = resp.processed_file.encode("ascii")
    processed_file = base64.b64decode(processed_file, validate=True)
    redacted_file.write(processed_file)

It is also possible to send URIs instead to the /v3/process/files/uri route, avoiding the overhead of base64 encoding and avoiding sending any sensitive information in the request. Please see Processing Files for details.

© Copyright 2024 Private AI.