Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -3,31 +3,32 @@ from inference import preprocess_input, segment_all
|
|
| 3 |
|
| 4 |
import tempfile
|
| 5 |
import nibabel as nib
|
| 6 |
-
from typing import List
|
| 7 |
from pydantic import BaseModel
|
| 8 |
-
from fastapi import FastAPI, UploadFile
|
| 9 |
from fastapi.responses import FileResponse
|
| 10 |
|
| 11 |
app = FastAPI()
|
| 12 |
|
| 13 |
wt_model, tc_model, et_model = load_vChain_model('./wt_chkpt.pth', './tc_chkpt.pth', './et_chkpt.pth')
|
| 14 |
|
| 15 |
-
print("Waiting For Segmentation Requests ...")
|
| 16 |
|
| 17 |
-
class NiftiFile(BaseModel):
|
| 18 |
-
file: UploadFile
|
| 19 |
|
| 20 |
@app.post("/segment/")
|
| 21 |
-
async def segment(
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
import tempfile
|
| 5 |
import nibabel as nib
|
|
|
|
| 6 |
from pydantic import BaseModel
|
| 7 |
+
from fastapi import FastAPI, UploadFile, File
|
| 8 |
from fastapi.responses import FileResponse
|
| 9 |
|
| 10 |
app = FastAPI()
|
| 11 |
|
| 12 |
wt_model, tc_model, et_model = load_vChain_model('./wt_chkpt.pth', './tc_chkpt.pth', './et_chkpt.pth')
|
| 13 |
|
| 14 |
+
print("Waiting For Segmentation Requests ....")
|
| 15 |
|
|
|
|
|
|
|
| 16 |
|
| 17 |
@app.post("/segment/")
|
| 18 |
+
async def segment(file: UploadFile):
|
| 19 |
+
return {"filename": file.filename}
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# try:
|
| 24 |
+
# return {"msg": "file received successfully"}
|
| 25 |
+
# # flair, t1, t1ce, t2 = (m.file for m in modalities)
|
| 26 |
+
# # flair_tensor, t1_tensor, t1ce_tensor, t2_tensor = preprocess_input(flair, t1, t1ce, t2)
|
| 27 |
+
# # print("input processed")
|
| 28 |
+
# # output = segment_all(wt_model, tc_model, et_model, flair_tensor, t1_tensor, t1ce_tensor, t2_tensor)
|
| 29 |
+
# # with tempfile.NamedTemporaryFile(suffix=".nii") as tempFile:
|
| 30 |
+
# # nib.save(output, tempFile.name)
|
| 31 |
+
# # return FileResponse(tempFile.name, media_type="application/octet-stream")
|
| 32 |
+
# except Exception as e:
|
| 33 |
+
# print(f"Error occurred: {str(e)}")
|
| 34 |
+
# return {"msg": "An error occurred during segmentation."}
|