Skip to main content

Sentiment Analysis

This example demonstrates how you can deploy a function that performs secure sentiment analysis using a TensorFlow Lite model. By using Cape, the model is protected because it can only be accessed within a secure enclave. The input data is also protected because it is encrypted prior to being uploaded, and is sent over TLS into the Cape enclave.

Code

Clone the capeprivacy/functions public repository:

git clone git@github.com:capeprivacy/functions.git

Navigate into the folder containing the code for the sentiment analysis function:

cd sentiment_analysis

Install the required dependencies into a target folder (named deploy in our example):

docker run -v `pwd`:/build -w /build --rm -it python:3.9-slim-bullseye pip install -r requirements.txt --target ./deploy/

Note: sudo may be required when running this command.

Login

Log in to Cape using:

cape login

Which produces:

Your CLI confirmation code is: <SOME_CODE>
Visit this URL to complete the login process: https://login.capeprivacy.com/activate?user_code=<SOME_CODE>
Congratulations, you're all set!

Deploy

Deploy your function to Cape using:

cape deploy ./deploy

Which produces:

Deploying function to Cape ...
Success! Deployed function to Cape
Function ID ➜ QF7NRfns5o4qWC9sjxhfB5
Checksum ➜ eb989a5ef2fabf377a11ad5464b81b67757fada90a268c8c6d8f2d95013c4681

Run

Invoke your function using:

cape run QF7NRfns5o4qWC9sjxhfB5 "This was a great film"

Which produces:

78.08% positive

Feel free to try with other phrases:

cape run QF7NRfns5o4qWC9sjxhfB5 "This was a terrible film"