Spaces:
Runtime error
Runtime error
Upload main.py with huggingface_hub
Browse files
main.py
CHANGED
|
@@ -1,33 +1,8 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
from fastapi.responses import FileResponse
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
wt_model, tc_model, et_model = load_vChain_model('./wt_chkpt.pth', './tc_chkpt.pth', './et_chkpt.pth')
|
| 13 |
-
app = FastAPI()
|
| 14 |
-
|
| 15 |
-
class NiftiFile(BaseModel):
|
| 16 |
-
file: UploadFile
|
| 17 |
-
|
| 18 |
-
@app.post("/segment/")
|
| 19 |
-
async def segment(modalities: List[NiftiFile]):
|
| 20 |
-
try:
|
| 21 |
-
if len(modalities) != 4:
|
| 22 |
-
return {"msg": "Invalid Input Format"}
|
| 23 |
-
flair, t1, t1ce, t2 = (m.file for m in modalities)
|
| 24 |
-
flair_tensor, t1_tensor, t1ce_tensor, t2_tensor = preprocess_input(flair, t1, t1ce, t2)
|
| 25 |
-
|
| 26 |
-
output = segment_all(wt_model, tc_model, et_model, flair_tensor, t1_tensor, t1ce_tensor, t2_tensor)
|
| 27 |
-
with tempfile.NamedTemporaryFile(suffix=".nii") as tempFile:
|
| 28 |
-
nib.save(output, tempFile.name)
|
| 29 |
-
return FileResponse(tempFile.name, media_type="application/octet-stream")
|
| 30 |
-
|
| 31 |
-
except Exception as e:
|
| 32 |
-
print(f"Error occurred: {str(e)}")
|
| 33 |
-
return {"msg": "An error occurred during segmentation."}
|
|
|
|
| 1 |
+
numpy
|
| 2 |
+
nibabel
|
| 3 |
+
torch
|
| 4 |
+
torch.nn
|
| 5 |
+
torch.summary
|
| 6 |
+
fastapi
|
| 7 |
+
uvicorn
|
| 8 |
+
python-multipart
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|