Newer
Older

Christopher Randolph Rhodes
committed
from typing import Dict
from fastapi import FastAPI, HTTPException

Christopher Randolph Rhodes
committed
from model_server.ilastik import IlastikPixelClassifierModel, IlastikObjectClassifierModel
from model_server.model import DummyImageToImageModel
from model_server.session import Session
from model_server.workflow import infer_image_to_image
app = FastAPI(debug=True)
session = Session()
@app.on_event("startup")
def startup():
pass
@app.get('/')
def read_root():
@app.get('/models')
def list_active_models():

Christopher Randolph Rhodes
committed
return session.describe_loaded_models()

Christopher Randolph Rhodes
committed
@app.put('/models/dummy/load/')
def load_dummy_model(params: str = None) -> dict:
return session.load_model(DummyImageToImageModel, params)
@app.put('/models/ilastik/pixel_classification/load/')
def load_ilastik_pixel_classification_model(params: str) -> dict:
return session.load_model(IlastikPixelClassifierModel, params)
@app.put('/models/ilastik/object_classification/load/')
def load_ilastik_object_classification_model(params: str) -> dict:
return session.load_model(IlastikObjectClassifierModel, params)
@app.put('/i2i/infer/')
def infer_img(model_id: str, input_filename: str, channel: int = None) -> dict:

Christopher Randolph Rhodes
committed
if model_id not in session.describe_loaded_models().keys():
raise HTTPException(
status_code=409,
detail=f'Model {model_id} has not been loaded'
)
inpath = session.inbound.path / input_filename
if not inpath.exists():
raise HTTPException(
status_code=404,
detail=f'Could not find file:\n{inpath}'
)

Christopher Randolph Rhodes
committed
record = infer_image_to_image(

Christopher Randolph Rhodes
committed
session.models[model_id]['object'],
session.outbound.path,
channel=channel,
)

Christopher Randolph Rhodes
committed
session.record_workflow_run(record)
return record