Skip to content

Commit

Permalink
Update with production routes
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolphpienaar committed Apr 30, 2024
1 parent 6ca73c8 commit 63936c7
Showing 1 changed file with 57 additions and 18 deletions.
75 changes: 57 additions & 18 deletions pfms/routes/pfms_routerInference.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from shutil import ignore_patterns
from fastapi import APIRouter, Query, HTTPException, BackgroundTasks, Request
from fastapi import File, UploadFile
from typing import List, Dict, Any, Union
from fastapi import File, UploadFile, Path, Form
from typing import List, Dict, Any, Union, Annotated

from starlette.responses import FileResponse

from models import credentialModel
from models import iresponse
from controllers import pfmsController_inference
from routes import credentialRouter

from pathlib import Path as PathLib
from config import settings
from pftag import pftag
import pudb
Expand All @@ -16,13 +19,13 @@


@router.get(
"/spleenseg/models/",
response_model=iresponse.modelsAvailable,
"/spleenseg/modelpth/",
response_model=iresponse.ModelsAvailable,
summary="""
GET the list of available models.
""",
)
def models_listAll() -> iresponse.modelsAvailable:
def models_listAll() -> iresponse.ModelsAvailable:
"""
Description
-----------
Expand All @@ -31,36 +34,72 @@ def models_listAll() -> iresponse.modelsAvailable:
Returns
-------
* `iresponse.modelsAvailable`: The response containing the list of models
* `iresponse.ModelsAvailable`: The response containing the list of models
"""
# pudb.set_trace()
modelList: iresponse.modelsAvailable = pfmsController_inference.showAll()
modelList: iresponse.ModelsAvailable = pfmsController_inference.models_list()
return modelList


@router.post(
"/spleenseg/modelpth/",
response_model=iresponse.ModelUploadResponse,
summary="""
POST a model pth file to the server.
""",
)
async def model_upload(
request: Request,
file: UploadFile = File(...),
) -> iresponse.ModelUploadResponse:
"""
Description
-----------
POST (upload) a model weights file. Pass a query parameter of `?modelID=<modelID>`
to set the internal name of this model.
Returns
-------
* `iresponse.ModelUploadResponse`: The response containing the list of available
models.
"""
# pudb.set_trace()
modelID: str = request.query_params.get("modelID", "")
modelUpload: iresponse.ModelUploadResponse = (
await pfmsController_inference.model_save(file, modelID)
)
return modelUpload


@router.post(
"/spleenseg/NIfTIinference/",
response_model=iresponse.inferenceResponseNIFTI,
summary="""
POST a NIfTI volume and expect an inference.
""",
POST (upload) a NIfTI volume. Pass a query parameter of `?modelID=<modelID>`
to set the internal name of the model to use for inference. Returns a
`FileResponse` octet-stream of the generated segmentned NIfTI volume
response.
""",
)
async def uploadAndInferOnNIfTIfile(
request: Request,
file: UploadFile = File(...),
) -> iresponse.inferenceResponseNIFTI:
) -> FileResponse:
"""
Description
-----------
POST a NIfTI volume spleen scan, and expect a reponse inference.
POST a NIfTI volume spleen scan, specify a modelID in query params,
and expect a reponse inference.
Returns
-------
* `iresponse.inferenceResponseNIFTI`: The response containing the list of models
* `FileResponse`: The response from the inference as an octet-stream; save
to compressed NIfTI file.
"""
pudb.set_trace()
inference: iresponse.inferenceResponseNIFTI = (
await pfmsController_inference.inferenceOnNIfTI(file)
# pudb.set_trace()
modelID: str = request.query_params.get("modelID", "")
inference: FileResponse = await pfmsController_inference.inferenceOnNIfTI(
file, modelID
)

return inference

0 comments on commit 63936c7

Please sign in to comment.