-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:bioimage-io/BioEngine
- Loading branch information
Showing
3 changed files
with
31 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,3 +165,5 @@ cython_debug/ | |
|
||
.executor/ | ||
.hypha_launcher/ | ||
|
||
bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|