Skip to content

Commit

Permalink
Merge branch 'main' of github.com:bioimage-io/BioEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
oeway committed Apr 16, 2024
2 parents 339f851 + 05b6e1a commit 47acc2d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,5 @@ cython_debug/

.executor/
.hypha_launcher/

bin/
62 changes: 28 additions & 34 deletions bioimageio/engine/__main__.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,48 @@
import sys
import argparse
import secrets
import asyncio
import subprocess
# import os
from hypha_launcher.api import HyphaLauncher
from hypha_launcher.utils.log import get_logger

def start_server(args):
import fire

logger = get_logger()

async def start_server(host = "0.0.0.0", port = 9000, public_base_url = ""):
# get current file path so we can get the path of apps under the same directory
# current_dir = os.path.dirname(os.path.abspath(__file__))
launcher = HyphaLauncher()
minio_root_user = "minio_root_user"
minio_root_password = secrets.token_urlsafe(16)
info = await launcher.launch_s3_server(minio_root_user, minio_root_password)
logger.info("S3 server launched at: %s", info["port"])
print(info)
command = [
sys.executable,
"-m",
"hypha.server",
f"--host={args.host}",
f"--port={args.port}",
f"--public-base-url={args.public_base_url}",
"--startup-functions=bioimageio.engine:register_bioengine_apps"
f"--host={host}",
f"--port={port}",
f"--public-base-url={public_base_url}",
"--startup-functions=bioimageio.engine:register_bioengine_apps",
"--enable-s3",
f"--endpoint-url=http://localhost:{info['port']}",
f"--access-key-id={minio_root_user}",
f"--secret-access-key={minio_root_password}",
]
subprocess.run(command)

def connect_server(args):
def connect_server(server_url, login_required=False):
from engine import connect_server
server_url = args.server_url
server_url = server_url
loop = asyncio.get_event_loop()
loop.create_task(connect_server(server_url))
loop.run_forever()


def main():
parser = argparse.ArgumentParser(description="BioImage.IO Chatbot utility commands.")

subparsers = parser.add_subparsers()

# Start server command
parser_start_server = subparsers.add_parser("start-server")
parser_start_server.add_argument("--host", type=str, default="0.0.0.0")
parser_start_server.add_argument("--port", type=int, default=9000)
parser_start_server.add_argument("--public-base-url", type=str, default="")
parser_start_server.set_defaults(func=start_server)

# Connect server command
parser_connect_server = subparsers.add_parser("connect-server")
parser_connect_server.add_argument("--server-url", default="https://ai.imjoy.io")
parser_connect_server.add_argument("--login-required", action="store_true")
parser_connect_server.set_defaults(func=connect_server)

args = parser.parse_args()
if hasattr(args, 'func'):
args.func(args)
else:
parser.print_help()

if __name__ == '__main__':
main()
fire.Fire({
"start_server": start_server,
"connect_server": connect_server
})
1 change: 1 addition & 0 deletions docs/k8s-toolkit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit 47acc2d

Please sign in to comment.