Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Upload 3 files
Browse files- fhe_model/client.zip +3 -0
- fhe_model/server.zip +3 -0
- server.py +38 -0
fhe_model/client.zip
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:af5402a23b687193c74da8aa5157c7b84728a80009075dd7e252b1fde04a8c57
|
3 |
+
size 1593797
|
fhe_model/server.zip
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:90903287cd81228b85e3f41bdc3610c94c8132b5b3fce68075656e44f3f69536
|
3 |
+
size 4531
|
server.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Server that will listen for GET requests from the client."""
|
2 |
+
from fastapi import FastAPI
|
3 |
+
from joblib import load
|
4 |
+
from concrete.ml.deployment import FHEModelServer
|
5 |
+
from pydantic import BaseModel
|
6 |
+
import base64
|
7 |
+
from pathlib import Path
|
8 |
+
|
9 |
+
current_dir = Path(__file__).parent
|
10 |
+
|
11 |
+
# Load the model
|
12 |
+
fhe_model_HLM = FHEModelServer(
|
13 |
+
Path.joinpath(current_dir, "fhe_model")
|
14 |
+
)
|
15 |
+
class PredictRequest(BaseModel):
|
16 |
+
evaluation_key: str
|
17 |
+
encrypted_encoding: str
|
18 |
+
|
19 |
+
|
20 |
+
# Initialize an instance of FastAPI
|
21 |
+
app = FastAPI()
|
22 |
+
|
23 |
+
|
24 |
+
# Define the default route
|
25 |
+
@app.get("/")
|
26 |
+
def root():
|
27 |
+
return {"message": "Welcome to Your ClairVault!"}
|
28 |
+
|
29 |
+
|
30 |
+
@app.post("/predict")
|
31 |
+
def predict_HLM(query: PredictRequest):
|
32 |
+
encrypted_encoding = base64.b64decode(query.encrypted_encoding)
|
33 |
+
evaluation_key = base64.b64decode(query.evaluation_key)
|
34 |
+
prediction = fhe_model_HLM.run(encrypted_encoding, evaluation_key)
|
35 |
+
|
36 |
+
# Encode base64 the prediction
|
37 |
+
encoded_prediction = base64.b64encode(prediction).decode()
|
38 |
+
return {"encrypted_prediction": encoded_prediction}
|