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

First version where run model endpoint works

parent e727a33f
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.
from fastapi import FastAPI
from fastapi.responses import PlainTextResponse
from app.internal.model_factory import *
from vipscore_common.vips_model import VIPSModel
from vipscore_common.entities import ModelConfiguration, Result
app = FastAPI()
description = """
Python implementation of VIPSCore, to enable models written in Python.
"""
app = FastAPI(
title = "VIPSCore-Python",
description=description,
contact= {
"name": "Berit Nordskog",
"email": "post@vips.no",
"url": "https://nibio.no/en/employees/berit-nordskog",
},
license_info={
"name": "GNU Affero General Public License v3",
"url": "https://www.gnu.org/licenses/agpl-3.0.en.html"
}
)
@app.get("/")
async def root():
return {"message": "Hello World"}
@app.get("/models", response_class=PlainTextResponse)
async def print_model_list() -> str:
@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.get("/models/json",
name="List all models (Json, default language)"
)
async def print_model_list_json_default_language():
return _print_model_list_json(VIPSModel.default_language)
@app.get("/models/json/{language}",
name="List all models (Json)")
async def print_model_list_json(language:str):
return _print_model_list_json(language)
@app.post("/models/run/",
name="Run a model"
)
async def run_model_from_config_only(model_configuration:ModelConfiguration):
return _run_model(model_configuration.model_id, model_configuration)
@app.post("/models/{model_id}/run/",
name="Run a model"
)
async def run_model_from_config_only(model_id, model_configuration:ModelConfiguration):
return _run_model(model_configuration.model_id, model_configuration)
def _run_model(model_id:str, model_configuration:ModelConfiguration):
requested_model = get_model_instance(model_id)
requested_model.set_configuration(model_configuration)
return requested_model.get_result()
def _print_model_list(language:str):
model_list = ""
vips_models = get_vips_models()
for model_id in vips_models:
model_list = "%s%s %s\n" %(model_list, model_id, get_model_instance(model_id).get_model_name())
model_list = "%s%s %s\n" %(model_list, model_id, get_model_instance(model_id).get_model_name(language))
return model_list
def _print_model_list_json(language:str):
"""
Common method for the web service methods
"""
model_list = []
vips_models = get_vips_models()
for model_id in vips_models:
model_list.append({
"modelId" : model_id,
"modelName" : get_model_instance(model_id).get_model_name()
})
return model_list
\ No newline at end of file
anyio==3.6.2
certifi==2022.12.7
click==8.1.3
dnspython==2.3.0
email-validator==1.3.0
fastapi==0.89.1
h11==0.14.0
httpcore==0.16.3
httptools==0.5.0
httpx==0.23.3
idna==3.4
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.1
orjson==3.8.5
pydantic==1.10.4
python-dotenv==0.21.0
python-multipart==0.0.5
PyYAML==6.0
rfc3986==1.5.0
six==1.16.0
sniffio==1.3.0
starlette==0.22.0
typing_extensions==4.4.0
ujson==5.7.0
uvicorn==0.20.0
uvloop==0.17.0
watchfiles==0.18.1
websockets==10.4
git+https://gitlab.nibio.no/VIPS/vipscore-python-common.git@0.1.6
\ 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