Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
VIPSCore-Python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VIPS
VIPSCore-Python
Commits
b14edc41
Commit
b14edc41
authored
2 years ago
by
Tor-Einar Skog
Browse files
Options
Downloads
Patches
Plain Diff
Handling client running non-existent model
parent
fa3b4013
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/internal/model_factory.py
+2
-1
2 additions, 1 deletion
app/internal/model_factory.py
app/main.py
+27
-8
27 additions, 8 deletions
app/main.py
with
29 additions
and
9 deletions
app/internal/model_factory.py
+
2
−
1
View file @
b14edc41
...
...
@@ -34,7 +34,8 @@ def discover_models():
return
models
def
get_model_instance
(
model_id
):
return
get_vips_models
().
get
(
model_id
)()
model_class
=
get_vips_models
().
get
(
model_id
)
return
model_class
()
if
model_class
is
not
None
else
None
def
get_vips_model_packages
():
global
_packages
...
...
This diff is collapsed.
Click to expand it.
app/main.py
+
27
−
8
View file @
b14edc41
from
fastapi
import
FastAPI
from
fastapi
import
FastAPI
,
Response
,
status
from
fastapi.responses
import
PlainTextResponse
from
app.internal.model_factory
import
*
from
vipscore_common.vips_model
import
VIPSModel
...
...
@@ -49,12 +49,17 @@ async def print_model_list(language: str) -> str:
####### Model running endpoints #######
@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
)
async
def
run_model_from_config_only
(
model_configuration
:
ModelConfiguration
,
response
:
Response
):
result
=
_run_model
(
model_configuration
.
model_id
,
model_configuration
)
return
_result_or_404
(
result
,
model_id
=
model_id
,
response
=
response
)
@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_id
,
model_configuration
)
async
def
run_model_from_config_only
(
model_id
,
model_configuration
:
ModelConfiguration
,
response
:
Response
):
result
=
_run_model
(
model_id
,
model_configuration
)
return
_result_or_404
(
result
,
model_id
=
model_id
,
response
=
response
)
####### Helper functions #######
...
...
@@ -66,8 +71,10 @@ def _run_model(model_id:str, model_configuration:ModelConfiguration):
Return a list of Result objects
"""
requested_model
=
get_model_instance
(
model_id
)
requested_model
.
set_configuration
(
model_configuration
)
return
requested_model
.
get_result
()
if
requested_model
is
not
None
:
requested_model
.
set_configuration
(
model_configuration
)
return
requested_model
.
get_result
()
return
None
def
_print_model_list
(
language
:
str
):
...
...
@@ -91,4 +98,16 @@ def _print_model_list_json(language:str):
"
modelId
"
:
model_id
,
"
modelName
"
:
get_model_instance
(
model_id
).
get_model_name
()
})
return
model_list
\ No newline at end of file
return
model_list
def
_result_or_404
(
result
,
model_id
:
str
,
response
:
Response
):
"""
DRY
"""
if
result
is
not
None
:
return
result
else
:
response
.
status_code
=
status
.
HTTP_404_NOT_FOUND
return
{
"
ERROR
"
:
"
VIPS model with id=%s could not be found.
"
%
model_id
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment