Skip to content

Commit

Permalink
Register separate services
Browse files Browse the repository at this point in the history
  • Loading branch information
oeway committed Aug 29, 2024
1 parent 364905c commit 1c94900
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
25 changes: 10 additions & 15 deletions bioimageio/engine/ray_app_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@ def __init__(self, server_url, workspace, token, ray_apps):
self.server_url = server_url
self._apps = ray_apps
self._hypha_server = connect_to_server({"server_url": server_url, "token": token, "workspace": workspace})
svc = {
"name": "Hypha Ray Apps",
"id": "hypha-ray-apps",
"config": {
"visibility": "protected"
},
}

def create_service_function(name, app_bind, method_name):
async def service_function(*args, **kwargs):
Expand All @@ -108,17 +101,19 @@ async def service_function(*args, **kwargs):
for app_id, app_info in self._apps.items():
app_bind = app_info["app_bind"]
methods = app_info["methods"]
app_service = {}
app_service = {
"id": app_id,
"name": app_info["name"],
"description": app_info["description"],
"config":{
"visibility": "protected"
},
}
for method in methods:
print(f"Registering method {method} for app {app_id}")
app_service[method] = create_service_function(method, app_bind, method)

svc[app_id] = app_service

info = self._hypha_server.register_service(svc, {"overwrite":True})
print("Hypha service info:", info)
print(f"Service URL: {self.server_url}/{workspace}/services/{info.id.split('/')[1]}")
self.info = info
info = self._hypha_server.register_service(app_service, {"overwrite":True})
print(f"Added service {app_id} with id {info.id}, use it at {self.server_url}/{workspace}/services/{info.id.split('/')[1]}")

async def __call__(self, request: Request):
# return a json object with the services
Expand Down
4 changes: 2 additions & 2 deletions bioimageio/engine/ray_apps/cellpose/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ def __init__(self):
pass

def predict(self, image: str) -> str:
prediction = "prediction of cellpose model on image" + image
prediction = "prediction of cellpose model on image: " + image
return prediction

def train(self, data: str, config: str) -> str:
training = "training cellpose model on data" + data + "with config" + config
training = "training cellpose model on data: " + data + "with config:" + config
return training


Expand Down

0 comments on commit 1c94900

Please sign in to comment.