Skip to content

Commit

Permalink
register sam service with random client
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsmechtel committed Oct 24, 2024
1 parent 8fb66bc commit f69800b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 38 deletions.
38 changes: 5 additions & 33 deletions bioimageio_colab/register_sam_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,33 +204,11 @@ async def register_service(args: dict) -> None:
if not workspace_token:
raise ValueError("Workspace token is required to connect to the Hypha server.")

# Wait until the client ID is available
test_client = await connect_to_server(
{
"server_url": args.server_url,
"workspace": args.workspace_name,
"token": workspace_token,
}
)
colab_client_id = f"{args.workspace_name}/{args.client_id}"
n_failed_attempts = 0
waiting_for_client = True
while waiting_for_client:
all_clients = await test_client.list_clients()
waiting_for_client = any([colab_client_id == client["id"] for client in all_clients])
if waiting_for_client:
n_failed_attempts += 1
logger.info(
f"Waiting for client ID '{colab_client_id}' to be available... (attempt {n_failed_attempts})"
)
await asyncio.sleep(1)

# Connect to the workspace
# Connect to the workspace (with random client ID)
colab_client = await connect_to_server(
{
"server_url": args.server_url,
"workspace": args.workspace_name,
"client_id": args.client_id,
"name": "SAM Server",
"token": workspace_token,
}
Expand Down Expand Up @@ -266,14 +244,13 @@ async def register_service(args: dict) -> None:
# - True if the embedding was removed successfully
# - False if the user was not found in the cache
"clear_cache": partial(clear_cache, embedding_cache),
},
{"overwrite": True},
}
)
sid = service_info["id"]
assert sid == f"{args.workspace_name}/{args.client_id}:{args.service_id}"
client_service = sid.split("/")[1]
logger.info(f"Registered service with ID: {sid}")
logger.info(
f"Test the service here: {args.server_url}/{args.workspace_name}/services/{args.client_id}:{args.service_id}/hello"
f"Test the service here: {args.server_url}/{args.workspace_name}/services/{client_service}/hello"
)


Expand All @@ -291,14 +268,9 @@ async def register_service(args: dict) -> None:
parser.add_argument(
"--workspace_name", default="bioimageio-colab", help="Name of the workspace"
)
parser.add_argument(
"--client_id",
default="kubernetes",
help="Client ID for registering the service",
)
parser.add_argument(
"--service_id",
default="sam",
default="microsam",
help="Service ID for registering the service",
)
parser.add_argument(
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ services:
command: [
"--server_url=https://hypha.aicell.io",
"--workspace_name=bioimageio-colab",
"--client_id=kubernetes",
"--service_id=sam",
]
7 changes: 3 additions & 4 deletions test/test_model_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@

SERVER_URL = "https://hypha.aicell.io"
WORKSPACE_NAME = "bioimageio-colab"
CLIENT_ID = "kubernetes"
SERVICE_ID = "sam"


def test_service_available():
service_url = f"{SERVER_URL}/{WORKSPACE_NAME}/services/{CLIENT_ID}:{SERVICE_ID}/hello"
service_url = f"{SERVER_URL}/{WORKSPACE_NAME}/services/*:{SERVICE_ID}/hello"
response = requests.get(service_url)
assert response.status_code == 200
assert response.json() == "Welcome to the Interactive Segmentation service!"
Expand All @@ -19,8 +18,8 @@ def test_get_service():
client = connect_to_server({"server_url": SERVER_URL, "method_timeout": 5})
assert client

sid = f"{WORKSPACE_NAME}/{CLIENT_ID}:{SERVICE_ID}"
segment_svc = client.get_service(sid)
sid = f"{WORKSPACE_NAME}/*:{SERVICE_ID}"
segment_svc = client.get_service(sid, {"mode": "random"})
assert segment_svc.id == sid
assert segment_svc.config.workspace == WORKSPACE_NAME
assert segment_svc.get("segment")
Expand Down

0 comments on commit f69800b

Please sign in to comment.