Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
model_server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Christopher Randolph Rhodes
model_server
Commits
d09bdffb
Commit
d09bdffb
authored
1 year ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Added endpoint to restart session, i.e. to clear loaded models
parent
c712a665
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
api.py
+5
-0
5 additions, 0 deletions
api.py
imagej/infer_ilastik_by_api.py
+29
-31
29 additions, 31 deletions
imagej/infer_ilastik_by_api.py
run_server.py
+1
-1
1 addition, 1 deletion
run_server.py
tests/test_api.py
+13
-1
13 additions, 1 deletion
tests/test_api.py
with
48 additions
and
33 deletions
api.py
+
5
−
0
View file @
d09bdffb
...
...
@@ -22,6 +22,11 @@ def read_root():
def
read_root
(
par1
=
None
,
par2
=
None
):
return
{
'
success
'
:
True
,
'
params
'
:
{
'
par1
'
:
par1
,
'
par2
'
:
par2
}}
@app.get
(
'
/restart
'
)
def
restart_session
()
->
dict
:
session
.
restart
()
return
session
.
describe_loaded_models
()
@app.get
(
'
/models
'
)
def
list_active_models
():
return
session
.
describe_loaded_models
()
...
...
This diff is collapsed.
Click to expand it.
imagej/infer_ilastik_by_api.py
+
29
−
31
View file @
d09bdffb
import
httplib
import
urllib2
import
json
import
urllib
...
...
@@ -18,33 +17,32 @@ input_filename = os.path.split(abspath)[-1]
outpath
=
'
C:
\\
Users
\\
rhodes
\\
projects
\\
proj0015-model-server
\\
resources
\\
testdata
'
global
connection
connection
=
httplib
.
HTTPConnection
(
'
127.0.0.1
'
,
8001
)
def
hit_endpoint
(
method
,
endpoint
,
params
=
None
):
if
not
method
in
[
'
GET
'
,
'
PUT
'
]:
raise
Exception
(
'
Can only handle GET and PUT requests
'
)
if
params
:
url
=
endpoint
+
'
?
'
+
urllib
.
urlencode
(
params
)
else
:
url
=
endpoint
connection
.
request
(
method
,
url
)
resp
=
connection
.
getresponse
()
print
(
method
+
'
'
+
url
+
'
, status
'
+
str
(
resp
.
status
)
+
'
:
\n
'
+
str
(
json
.
loads
(
resp
.
read
())))
return
resp
hit_endpoint
(
'
GET
'
,
'
/
'
)
hit_endpoint
(
'
GET
'
,
'
/models
'
)
hit_endpoint
(
'
PUT
'
,
'
/bounce_back
'
,
{
'
par1
'
:
'
ghij
'
})
hit_endpoint
(
'
PUT
'
,
'
/models/ilastik/pixel_classification/load/
'
,
{
'
project_file
'
:
'
demo_px.ilp
'
})
resp
=
hit_endpoint
(
'
GET
'
,
'
/models
'
)
print
(
resp
.
read
())
#print(json.loads(resp.read())) # trying to extract model_id, but json.loads throws an error
#infer_params = {
# 'model_id': model_id,
# 'input_filename': input_filename,
# 'channel': 0
# }
#
#hit_endpoint('PUT', '/infer/from_image_file', infer_params)
\ No newline at end of file
def
hit_endpoint
(
method
,
endpoint
,
params
=
None
,
verbose
=
False
):
connection
=
httplib
.
HTTPConnection
(
host
,
port
)
if
not
method
in
[
'
GET
'
,
'
PUT
'
]:
raise
Exception
(
'
Can only handle GET and PUT requests
'
)
if
params
:
url
=
endpoint
+
'
?
'
+
urllib
.
urlencode
(
params
)
else
:
url
=
endpoint
connection
.
request
(
method
,
url
)
resp
=
connection
.
getresponse
()
resp_str
=
resp
.
read
()
if
verbose
:
print
(
method
+
'
'
+
url
+
'
, status
'
+
str
(
resp
.
status
)
+
'
:
\n
'
+
resp_str
)
return
json
.
loads
(
resp_str
)
#hit_endpoint('GET', '/')
#hit_endpoint('GET', '/models')
#hit_endpoint('PUT', '/bounce_back', {'par1': 'ghij'})
resp
=
hit_endpoint
(
'
PUT
'
,
'
/models/ilastik/pixel_classification/load/
'
,
{
'
project_file
'
:
'
demo_px.ilp
'
})
pxmid
=
resp
[
'
model_id
'
]
resp
=
hit_endpoint
(
'
GET
'
,
'
/models
'
,
verbose
=
True
)
infer_params
=
{
'
model_id
'
:
pxmid
,
'
input_filename
'
:
input_filename
,
'
channel
'
:
0
}
hit_endpoint
(
'
PUT
'
,
'
/infer/from_image_file
'
,
infer_params
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
run_server.py
+
1
−
1
View file @
d09bdffb
...
...
@@ -4,4 +4,4 @@ host = '127.0.0.1'
port
=
8001
if
__name__
==
'
__main__
'
:
uvicorn
.
run
(
'
api:app
'
,
**
{
'
host
'
:
host
,
'
port
'
:
port
,
'
log_level
'
:
'
debug
'
},
reload
=
True
)
\ No newline at end of file
uvicorn
.
run
(
'
api:app
'
,
**
{
'
host
'
:
host
,
'
port
'
:
port
,
'
log_level
'
:
'
debug
'
},
reload
=
False
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
tests/test_api.py
+
13
−
1
View file @
d09bdffb
...
...
@@ -64,7 +64,6 @@ class TestApiFromAutomatedClient(TestServerBaseClass):
self
.
assertEqual
(
rj
[
model_id
][
'
class
'
],
'
DummyImageToImageModel
'
)
return
model_id
def
test_respond_with_error_when_invalid_filepath_requested
(
self
):
model_id
=
self
.
test_load_dummy_model
()
...
...
@@ -102,3 +101,16 @@ class TestApiFromAutomatedClient(TestServerBaseClass):
)
self
.
assertEqual
(
resp_infer
.
status_code
,
200
,
resp_infer
.
content
.
decode
())
def
test_restarting_session_clears_loaded_models
(
self
):
resp_load
=
requests
.
put
(
self
.
uri
+
f
'
models/dummy/load
'
,
)
self
.
assertEqual
(
resp_load
.
status_code
,
200
,
resp_load
.
json
())
resp_list_0
=
requests
.
get
(
self
.
uri
+
'
models
'
)
self
.
assertEqual
(
resp_list_0
.
status_code
,
200
)
rj0
=
resp_list_0
.
json
()
self
.
assertEqual
(
len
(
rj0
),
1
,
f
'
Unexpected models in response:
{
rj0
}
'
)
resp_restart
=
requests
.
get
(
self
.
uri
+
'
restart
'
)
resp_list_1
=
requests
.
get
(
self
.
uri
+
'
models
'
)
rj1
=
resp_list_1
.
json
()
self
.
assertEqual
(
len
(
rj1
),
0
,
f
'
Unexpected models in response:
{
rj1
}
'
)
\ 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