LouayMagdy commited on
Commit
56eaa84
·
verified ·
1 Parent(s): 3d35348

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +19 -18
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(modalities: NiftiFile):
22
- try:
23
- return {"msg": "file received successfully"}
24
- # flair, t1, t1ce, t2 = (m.file for m in modalities)
25
- # flair_tensor, t1_tensor, t1ce_tensor, t2_tensor = preprocess_input(flair, t1, t1ce, t2)
26
- # print("input processed")
27
- # output = segment_all(wt_model, tc_model, et_model, flair_tensor, t1_tensor, t1ce_tensor, t2_tensor)
28
- # with tempfile.NamedTemporaryFile(suffix=".nii") as tempFile:
29
- # nib.save(output, tempFile.name)
30
- # return FileResponse(tempFile.name, media_type="application/octet-stream")
31
- except Exception as e:
32
- print(f"Error occurred: {str(e)}")
33
- return {"msg": "An error occurred during segmentation."}
 
 
 
 
 
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."}