File size: 1,472 Bytes
aaffad9
 
 
 
 
 
 
c61a090
aaffad9
 
7b468fa
7ac84c7
 
 
 
 
 
 
 
 
 
 
 
 
7b468fa
 
7ac84c7
7b468fa
aaffad9
d73a93b
aaffad9
 
a8246da
7b468fa
aaffad9
 
 
 
 
 
 
 
 
 
 
 
 
 
d73a93b
aaffad9
 
d73a93b
aaffad9
 
 
c61a090
 
a8246da
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""Server that will listen for GET requests from the client."""
from fastapi import FastAPI
from joblib import load
from concrete.ml.deployment import FHEModelServer
from pydantic import BaseModel
import base64
from pathlib import Path


current_dir = Path(__file__).parent


# Initialize an instance of FastAPI
app = FastAPI()

@app.get("/")
def root():
    """
    Root endpoint of the health prediction API.
    Returns:
        dict: The welcome message.
    """
    return {"message": "Welcome to your disease prediction with FHE!"}

print(Path.joinpath(current_dir, "fhe_model"))
from glob import glob 

print(glob(f'{current_dir}/fhe_model/*'))
# Load the model
fhe_model = FHEModelServer(
    Path.joinpath(current_dir, "fhe_model")
)
print(fhe_model)
print('1111', current_dir)
class PredictRequest(BaseModel):
    evaluation_key: str
    encrypted_encoding: str




# Define the default route
@app.get("/")
def root():
    return {"message": "Welcome to Your ClairVault!"}


@app.post("/predict")
def predict(query: PredictRequest):
    encrypted_encoding = base64.b64decode(query.encrypted_encoding)
    evaluation_key = base64.b64decode(query.evaluation_key)
    prediction = fhe_model.run(encrypted_encoding, evaluation_key)

    # Encode base64 the prediction
    encoded_prediction = base64.b64encode(prediction).decode()
    return {"encrypted_prediction": encoded_prediction}

# if __name__ == "__main__":
#    uvicorn.run(app, host="0.0.0.0", port=3000)