WenqingZhang
commited on
Commit
•
be201e7
1
Parent(s):
4e70a31
Update server.py
Browse files
server.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
from fastapi import FastAPI
|
2 |
from joblib import load
|
3 |
from concrete.ml.deployment import FHEModelServer
|
@@ -9,7 +10,6 @@ current_dir = Path(__file__).parent
|
|
9 |
|
10 |
# Load the model
|
11 |
fhe_model = FHEModelServer("deployment/financial_rating")
|
12 |
-
fhe_legal_model=FHEModelServer("deployment/legal_rating")
|
13 |
|
14 |
class PredictRequest(BaseModel):
|
15 |
evaluation_key: str
|
@@ -29,17 +29,6 @@ def predict_sentiment(query: PredictRequest):
|
|
29 |
evaluation_key = base64.b64decode(query.evaluation_key)
|
30 |
prediction = fhe_model.run(encrypted_encoding, evaluation_key)
|
31 |
|
32 |
-
# Encode base64 the prediction
|
33 |
-
encoded_prediction = base64.b64encode(prediction).decode()
|
34 |
-
return {"encrypted_prediction": encoded_prediction}
|
35 |
-
|
36 |
-
|
37 |
-
@app.post("/legal_rating")
|
38 |
-
def predict_sentiment(query: PredictRequest):
|
39 |
-
encrypted_encoding = base64.b64decode(query.encrypted_encoding)
|
40 |
-
evaluation_key = base64.b64decode(query.evaluation_key)
|
41 |
-
prediction = fhe_legal_model.run(encrypted_encoding, evaluation_key)
|
42 |
-
|
43 |
# Encode base64 the prediction
|
44 |
encoded_prediction = base64.b64encode(prediction).decode()
|
45 |
return {"encrypted_prediction": encoded_prediction}
|
|
|
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
|
|
|
10 |
|
11 |
# Load the model
|
12 |
fhe_model = FHEModelServer("deployment/financial_rating")
|
|
|
13 |
|
14 |
class PredictRequest(BaseModel):
|
15 |
evaluation_key: str
|
|
|
29 |
evaluation_key = base64.b64decode(query.evaluation_key)
|
30 |
prediction = fhe_model.run(encrypted_encoding, evaluation_key)
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
# Encode base64 the prediction
|
33 |
encoded_prediction = base64.b64encode(prediction).decode()
|
34 |
return {"encrypted_prediction": encoded_prediction}
|