Skip to content

capeprivacy/functions

Repository files navigation

Cape Functions

Getting Started

To run these functions with Cape, you need to first install the Cape CLI. Then you will have to sign up from Cape's website or using the CLI:

cape signup

These examples can be also executed from Cape's SDKs: cape-js and pycape. If you execute these functions from one of the SDK, you will have to generate a personal access token. This can be done from Cape's website or from the CLI:

cape token create --name my-token --description 'for use in the javascript sdk'

Examples

Echo

A simple function that returns whatever you send it. Check out the folder echo to learn how to deploy this function. To invoke this function, you can run the following:

cape run capedocs/echo -f echo/input.echo.data

Isprime

A simple function checking if your number is prime or not. Check out the folder isprime to learn how to deploy this function. To invoke this function, you can run the following:

cape run capedocs/isprime -f isprime/input.isprime.data

Pendulum

In this example, we show how to run a function requiring a dependency. The function simply returns the current time based on a specific timezone using the Pendulum library. To learn how to deploy this function, check out the folder pendulum. To invoke the function, invoke:

cape run capedocs/pendulum Europe/Paris 

Numpy Stats

A simple example with numpy dependencies and using pycape and serdio.lift_io to handle automatic serialization/deserialization of Cape function input/outputs. You can learn how to deploy this function by checking the folder np-stats. You can run the function as follow after install installing in a virtual environment in np-stats/requirements.txt:

export TOKEN=<YOUR TOKEN>
export FUNCTION_ID=capedocs/np-stats
python np-stats/run.py

Secure Search

Simulates a cybersecurity search function, where the IP addresses you are interested in need to remain private but the data/logs you are searching might be public. You can learn more about this function by checking the folder secure-search.

cape run capedocs/secure-search  -f secure_search/input.search.data

Leader Election

Demos how a secure trusted execution environment like Cape can be leveraged in consensus in order to guarantee fairness. Details on how to run this example can be found here.

Hide-and-seek

To learn more about the confidential hide-and-seek example, you can check the folder hide_and_seek.

Mortgage

This application is a mortgage calculator that computes if an applicant is eligible for a mortgage. To learn how to deploy this application, you can check out the folder mortgage. To call this function, you can run:

cape run capedocs/mortgage -f mortgage/input.mortgage.json

Machine Learning Examples

Image Classification Inference with ONNX

To learn how you can deploy and invoke an image classification model using the onnxruntime, you can check the capeprivacy/image-classification-onnx repository.

Image Classification Inference with tflite

This example demonstrates how to deploy and invoke an image classification model with tflite. To learn how to deploy this application, you can check out the folder image-classification. To invoke the model, run:

cape run capedocs/image-recognition -f image_recognition/coffee.jpg

('Image Label is :', 'espresso', ', with Accuracy :', 84.38, '%.')

Sentiment Analysis Inference with tflite

This example demonstrates how you can deploy and invoke a sentiment analysis model with tflite. To learn how to deploy this application, you can check out the folder sentiment_analysis. To invoke the model, simply run:

cape run capedocs/sentiment-analysis -f sentiment_analysis/input.pos.data

('The sentiment is: ', 'positive', ' with a probability of ', 78.08290123939514, '%.')

Training and Inference with Scikit-Learn.

You can check the following examples to learn about how to deploying and invoke machine learning models with Scikit-Learn:

Invoke Cape's Confidential Services

Invoke Cape's Confidential OCR Service from SDKs

This example shows you how you can run the Cape's confidential optical character recognition service from the SDKs: cape-js and pycape.

For this example, we will run the OCR on the PDF ./ocr/claude_shannon.pdf.

From cape-js:

Before invoking the OCR, set the environment variable CAPE_AUTH_TOKEN to your personal access token.

export CAPE_AUTH_TOKEN="your cape auth token"

To run the OCR from cape-js on the PDF, from the ocr folder, run:

node run_ocr.mjs

To encrypt the PDF with cape.encrypt, then invoke the OCR on the encrypted PDF, run:

node encrypt_run_ocr.mjs

From pycape:

Before invoking the OCR, set the environment variable CAPE_AUTH_TOKEN to your personal access token.

export CAPE_AUTH_TOKEN="your cape auth token"

To run the OCR from pycape on the PDF, from the ocr folder, run:

python run_ocr.py

To encrypt the PDF with cape.encrypt, then invoke the OCR on the encrypted PDF, run:

python encrypt_run_ocr.py