Spaces:
Sleeping
Sleeping
Commit
·
57d2857
1
Parent(s):
5e509b3
alk
Browse files
app.py
CHANGED
@@ -2,12 +2,13 @@ from fastapi import FastAPI, File, Form, UploadFile, Body
|
|
2 |
from fastapi.responses import JSONResponse, Response
|
3 |
from concrete.ml.deployment import FHEModelServer
|
4 |
import numpy as np
|
|
|
|
|
5 |
|
6 |
from concrete.ml.deployment import FHEModelClient
|
7 |
import subprocess
|
8 |
from pathlib import Path
|
9 |
|
10 |
-
|
11 |
from utils import (
|
12 |
CLIENT_DIR,
|
13 |
CURRENT_DIR,
|
@@ -24,7 +25,6 @@ from utils import (
|
|
24 |
pretty_print,
|
25 |
)
|
26 |
|
27 |
-
|
28 |
import time
|
29 |
from typing import List
|
30 |
|
@@ -32,13 +32,15 @@ from typing import List
|
|
32 |
# FHE_SERVER = FHEModelServer(DEPLOYMENT_DIR)
|
33 |
|
34 |
|
|
|
|
|
|
|
35 |
app = FastAPI()
|
36 |
|
37 |
@app.get("/")
|
38 |
def greet_json():
|
39 |
return {"Hello": "World!"}
|
40 |
|
41 |
-
|
42 |
def root():
|
43 |
"""
|
44 |
Root endpoint of the health prediction API.
|
@@ -48,7 +50,6 @@ def root():
|
|
48 |
"""
|
49 |
return {"message": "Welcome to your disease prediction with FHE!"}
|
50 |
|
51 |
-
|
52 |
@app.post("/send_input")
|
53 |
def send_input(
|
54 |
user_id: str = Form(),
|
@@ -69,7 +70,6 @@ def send_input(
|
|
69 |
encrypted_input.write(files[0].file.read())
|
70 |
evaluation_key.write(files[1].file.read())
|
71 |
|
72 |
-
|
73 |
@app.post("/run_fhe")
|
74 |
def run_fhe(
|
75 |
user_id: str = Form(),
|
@@ -102,7 +102,6 @@ def run_fhe(
|
|
102 |
|
103 |
return JSONResponse(content=fhe_execution_time)
|
104 |
|
105 |
-
|
106 |
@app.post("/get_output")
|
107 |
def get_output(user_id: str = Form()):
|
108 |
"""Retrieve the encrypted output from the server."""
|
@@ -121,12 +120,11 @@ def get_output(user_id: str = Form()):
|
|
121 |
# Send the encrypted output
|
122 |
return Response(encrypted_output)
|
123 |
|
124 |
-
|
125 |
@app.post("/generate_keys")
|
126 |
-
def generate_keys(
|
127 |
"""
|
128 |
Endpoint to generate keys based on user symptoms.
|
129 |
-
|
130 |
Args:
|
131 |
user_symptoms (List[str]): The list of user symptoms.
|
132 |
|
@@ -139,7 +137,7 @@ def generate_keys(user_symptoms: List[str] = Body(...)):
|
|
139 |
# Call the key generation function
|
140 |
clean_directory()
|
141 |
|
142 |
-
if is_none(
|
143 |
return JSONResponse(
|
144 |
status_code=400, content={"error": "Please submit your symptoms first."}
|
145 |
)
|
@@ -173,12 +171,11 @@ def generate_keys(user_symptoms: List[str] = Body(...)):
|
|
173 |
}
|
174 |
)
|
175 |
|
176 |
-
|
177 |
@app.post("/run_dev")
|
178 |
def run_dev_script():
|
179 |
"""
|
180 |
Endpoint to execute the dev.py script to generate deployment files.
|
181 |
-
|
182 |
Returns:
|
183 |
JSONResponse: Success message or error details.
|
184 |
"""
|
@@ -204,4 +201,4 @@ def run_dev_script():
|
|
204 |
return JSONResponse(
|
205 |
status_code=500,
|
206 |
content={"error": "Failed to execute dev.py", "details": e.stderr}
|
207 |
-
)
|
|
|
2 |
from fastapi.responses import JSONResponse, Response
|
3 |
from concrete.ml.deployment import FHEModelServer
|
4 |
import numpy as np
|
5 |
+
from pydantic import BaseModel
|
6 |
+
|
7 |
|
8 |
from concrete.ml.deployment import FHEModelClient
|
9 |
import subprocess
|
10 |
from pathlib import Path
|
11 |
|
|
|
12 |
from utils import (
|
13 |
CLIENT_DIR,
|
14 |
CURRENT_DIR,
|
|
|
25 |
pretty_print,
|
26 |
)
|
27 |
|
|
|
28 |
import time
|
29 |
from typing import List
|
30 |
|
|
|
32 |
# FHE_SERVER = FHEModelServer(DEPLOYMENT_DIR)
|
33 |
|
34 |
|
35 |
+
class Symptoms(BaseModel):
|
36 |
+
user_symptoms: List[str]
|
37 |
+
|
38 |
app = FastAPI()
|
39 |
|
40 |
@app.get("/")
|
41 |
def greet_json():
|
42 |
return {"Hello": "World!"}
|
43 |
|
|
|
44 |
def root():
|
45 |
"""
|
46 |
Root endpoint of the health prediction API.
|
|
|
50 |
"""
|
51 |
return {"message": "Welcome to your disease prediction with FHE!"}
|
52 |
|
|
|
53 |
@app.post("/send_input")
|
54 |
def send_input(
|
55 |
user_id: str = Form(),
|
|
|
70 |
encrypted_input.write(files[0].file.read())
|
71 |
evaluation_key.write(files[1].file.read())
|
72 |
|
|
|
73 |
@app.post("/run_fhe")
|
74 |
def run_fhe(
|
75 |
user_id: str = Form(),
|
|
|
102 |
|
103 |
return JSONResponse(content=fhe_execution_time)
|
104 |
|
|
|
105 |
@app.post("/get_output")
|
106 |
def get_output(user_id: str = Form()):
|
107 |
"""Retrieve the encrypted output from the server."""
|
|
|
120 |
# Send the encrypted output
|
121 |
return Response(encrypted_output)
|
122 |
|
|
|
123 |
@app.post("/generate_keys")
|
124 |
+
def generate_keys(symptoms: Symptoms):
|
125 |
"""
|
126 |
Endpoint to generate keys based on user symptoms.
|
127 |
+
|
128 |
Args:
|
129 |
user_symptoms (List[str]): The list of user symptoms.
|
130 |
|
|
|
137 |
# Call the key generation function
|
138 |
clean_directory()
|
139 |
|
140 |
+
if is_none(symptoms):
|
141 |
return JSONResponse(
|
142 |
status_code=400, content={"error": "Please submit your symptoms first."}
|
143 |
)
|
|
|
171 |
}
|
172 |
)
|
173 |
|
|
|
174 |
@app.post("/run_dev")
|
175 |
def run_dev_script():
|
176 |
"""
|
177 |
Endpoint to execute the dev.py script to generate deployment files.
|
178 |
+
|
179 |
Returns:
|
180 |
JSONResponse: Success message or error details.
|
181 |
"""
|
|
|
201 |
return JSONResponse(
|
202 |
status_code=500,
|
203 |
content={"error": "Failed to execute dev.py", "details": e.stderr}
|
204 |
+
)
|