Skip to content
Snippets Groups Projects
Commit bbe9ca23 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Working endpoint for running a model!

parent 0c2cbc5c
No related branches found
No related tags found
1 merge request!2Model factory
This commit is part of merge request !2. Comments created here will be created in the context of that merge request.
...@@ -23,58 +23,57 @@ app = FastAPI( ...@@ -23,58 +23,57 @@ app = FastAPI(
} }
) )
# TODO Create a nice welcome page
@app.get("/") @app.get("/")
async def root(): async def root():
return {"message": "Hello World"} return {"message": "Hello World"}
@app.get("/models", response_class=PlainTextResponse, ####### Model listing endpoints #######
name="List all models (plain text, default language)")
async def print_model_list_default_language() -> str:
return _print_model_list(VIPSModel.default_language)
@app.get("/models/{language}", response_class=PlainTextResponse, @app.get("/models/json", name="List all models (Json, default language)")
name="List all models (plain text)"
)
async def print_model_list(language: str) -> str:
return _print_model_list(language)
@app.get("/models/json",
name="List all models (Json, default language)"
)
async def print_model_list_json_default_language(): async def print_model_list_json_default_language():
return _print_model_list_json(VIPSModel.default_language) return _print_model_list_json(VIPSModel.default_language)
@app.get("/models/json/{language}", name="List all models (Json)")
@app.get("/models/json/{language}",
name="List all models (Json)")
async def print_model_list_json(language:str): async def print_model_list_json(language:str):
return _print_model_list_json(language) return _print_model_list_json(language)
@app.get("/models", response_class=PlainTextResponse, name="List all models (plain text, default language)")
async def print_model_list_default_language() -> str:
return _print_model_list(VIPSModel.default_language)
@app.get("/models/{language}", response_class=PlainTextResponse, name="List all models (plain text)")
async def print_model_list(language: str) -> str:
return _print_model_list(language)
@app.post("/models/run/", ####### Model running endpoints #######
name="Run a model" @app.post("/models/run/", name="Run a model")
)
async def run_model_from_config_only(model_configuration:ModelConfiguration): async def run_model_from_config_only(model_configuration:ModelConfiguration):
return _run_model(model_configuration.model_id, model_configuration) return _run_model(model_configuration.model_id, model_configuration)
@app.post("/models/{model_id}/run/", @app.post("/models/{model_id}/run/", name="Run a model")
name="Run a model"
)
async def run_model_from_config_only(model_id, model_configuration:ModelConfiguration): async def run_model_from_config_only(model_id, model_configuration:ModelConfiguration):
return _run_model(model_configuration.model_id, model_configuration) return _run_model(model_id, model_configuration)
####### Helper functions #######
# Dealing with no method overload in Python :-)
def _run_model(model_id:str, model_configuration:ModelConfiguration): def _run_model(model_id:str, model_configuration:ModelConfiguration):
"""
Run a model, using provided model_id and ModelConfiguration
Return a list of Result objects
"""
requested_model = get_model_instance(model_id) requested_model = get_model_instance(model_id)
requested_model.set_configuration(model_configuration) requested_model.set_configuration(model_configuration)
return requested_model.get_result() return requested_model.get_result()
def _print_model_list(language:str): def _print_model_list(language:str):
"""
Returns the list of available models in plain text format
"""
model_list = "" model_list = ""
vips_models = get_vips_models() vips_models = get_vips_models()
for model_id in vips_models: for model_id in vips_models:
...@@ -83,7 +82,7 @@ def _print_model_list(language:str): ...@@ -83,7 +82,7 @@ def _print_model_list(language:str):
def _print_model_list_json(language:str): def _print_model_list_json(language:str):
""" """
Common method for the web service methods Returns the list of available models in Json format
""" """
model_list = [] model_list = []
vips_models = get_vips_models() vips_models = get_vips_models()
......
fastapi==0.89.1 fastapi==0.89.1
git+https://gitlab.nibio.no/VIPS/vipscore-python-common.git@0.1.6 git+https://gitlab.nibio.no/VIPS/vipscore-python-common.git@0.1.9
\ No newline at end of file \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment