-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from capeprivacy/justin/deploy-script
Justin/deploy script
- Loading branch information
Showing
5 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import pathlib | ||
import pycape | ||
from pycape.experimental import cli | ||
|
||
cape = pycape.Cape() | ||
|
||
function_ref = cli.deploy("onnx_resnet_deploy") | ||
|
||
print(function_ref.id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from pycape import Cape | ||
|
||
cape = Cape() | ||
|
||
ciphertext = cape.encrypt(b"hello world") | ||
|
||
print("Encrypted:", ciphertext.decode()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import sys | ||
from pycape import Cape | ||
|
||
if len(sys.argv) < 2: | ||
print("expected user to be passed") | ||
quit() | ||
|
||
cape = Cape() | ||
|
||
ciphertext = cape.encrypt(f"hi {sys.argv[1]}".encode(), username=sys.argv[1]) | ||
|
||
print("Encrypted:", ciphertext.decode()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import json | ||
import os | ||
|
||
from torchvision.io import read_image | ||
from torchvision.models import ResNet50_Weights | ||
|
||
from pycape import Cape | ||
|
||
token_env = os.environ.get("TOKEN") | ||
function_id_env = os.environ.get("FUNCTION_ID") | ||
|
||
|
||
def process_image(file): | ||
img = read_image(file) | ||
weights = ResNet50_Weights.DEFAULT | ||
preprocess = weights.transforms() | ||
batch = preprocess(img).unsqueeze(0) | ||
batch_numpy = batch.detach().numpy() | ||
batch_numpy_bytes = batch_numpy.tobytes() | ||
return batch_numpy_bytes | ||
|
||
|
||
if __name__ == "__main__": | ||
cape = Cape() | ||
f = cape.function(function_id_env) | ||
t = cape.token(token_env) | ||
|
||
input_bytes = process_image("./images_sample/dog.jpeg") | ||
|
||
input_bytes = cape.encrypt(input_bytes) | ||
|
||
top5_classes = cape.run(f, t, input_bytes) | ||
|
||
top5_classes = json.loads(top5_classes) | ||
for category_name, score in top5_classes.items(): | ||
print(f"{category_name}: {100 * score:.1f}%") |