From efad3875425c33ab78a10852437208b45a5e6835 Mon Sep 17 00:00:00 2001 From: s184364 <s184364@student.dtu.dk> Date: Thu, 14 Dec 2023 13:25:33 +0100 Subject: [PATCH] Command Line Interface for qim3d --- qim3d/gui/annotation_tool.py | 7 +++++-- qim3d/gui/data_explorer.py | 7 +++++-- qim3d/gui/iso3d.py | 8 ++++++-- qim3d/gui/local_thickness.py | 6 ++++-- qim3d/utils/cli.py | 35 +++++++++++++++++++++++++++++++++++ qim3d/utils/internal_tools.py | 6 +++--- setup.py | 5 +++++ 7 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 qim3d/utils/cli.py diff --git a/qim3d/gui/annotation_tool.py b/qim3d/gui/annotation_tool.py index cdd29f55..c3c60c1d 100644 --- a/qim3d/gui/annotation_tool.py +++ b/qim3d/gui/annotation_tool.py @@ -353,7 +353,10 @@ class Operations: ] + output_masks_update +def run_interface(host = "0.0.0.0"): + gradio_interface = Interface().create_interface() + internal_tools.run_gradio_app(gradio_interface,host) + if __name__ == "__main__": # Creates interface - gradio_interface = Interface().create_interface() - internal_tools.run_gradio_app(gradio_interface) + run_interface() \ No newline at end of file diff --git a/qim3d/gui/data_explorer.py b/qim3d/gui/data_explorer.py index 17eb8268..1be62208 100644 --- a/qim3d/gui/data_explorer.py +++ b/qim3d/gui/data_explorer.py @@ -629,8 +629,11 @@ class Pipeline: return vol_hist, bin_edges +def run_interface(host = "0.0.0.0"): + gradio_interface = Interface().create_interface() + internal_tools.run_gradio_app(gradio_interface,host) + if __name__ == "__main__": # Creates interface - gradio_interface = Interface().create_interface() - internal_tools.run_gradio_app(gradio_interface) + run_interface() \ No newline at end of file diff --git a/qim3d/gui/iso3d.py b/qim3d/gui/iso3d.py index a60b761e..1536aa7d 100644 --- a/qim3d/gui/iso3d.py +++ b/qim3d/gui/iso3d.py @@ -397,7 +397,11 @@ class Interface: ) +def run_interface(host = "0.0.0.0"): + gradio_interface = Interface().create_interface() + internal_tools.run_gradio_app(gradio_interface,host) + + if __name__ == "__main__": # Creates interface - gradio_interface = Interface().create_interface() - internal_tools.run_gradio_app(gradio_interface) + run_interface() \ No newline at end of file diff --git a/qim3d/gui/local_thickness.py b/qim3d/gui/local_thickness.py index 1e179eed..b3a7dce1 100644 --- a/qim3d/gui/local_thickness.py +++ b/qim3d/gui/local_thickness.py @@ -421,8 +421,10 @@ class Pipeline: return filename +def run_interface(host = "0.0.0.0"): + gradio_interface = Interface().create_interface() + internal_tools.run_gradio_app(gradio_interface,host) if __name__ == "__main__": # Creates interface - gradio_interface = Interface().create_interface() - internal_tools.run_gradio_app(gradio_interface) + run_interface() \ No newline at end of file diff --git a/qim3d/utils/cli.py b/qim3d/utils/cli.py new file mode 100644 index 00000000..f48a5b81 --- /dev/null +++ b/qim3d/utils/cli.py @@ -0,0 +1,35 @@ +import argparse +from qim3d.gui import data_explorer, iso3d, annotation_tool, local_thickness + +def main(): + parser = argparse.ArgumentParser(description='Qim3d command-line interface.') + subparsers = parser.add_subparsers(title='Subcommands', dest='subcommand') + + # subcommands + gui_parser = subparsers.add_parser('gui', help = 'Graphical User Interfaces.') + + gui_parser.add_argument('--data-explorer', action='store_true', help='Run data explorer.') + gui_parser.add_argument('--iso3d', action='store_true', help='Run iso3d.') + gui_parser.add_argument('--annotation-tool', action='store_true', help='Run annotation tool.') + gui_parser.add_argument('--local-thickness', action='store_true', help='Run local thickness tool.') + gui_parser.add_argument('--host', default='0.0.0.0', help='Desired host.') + + args = parser.parse_args() + + if args.subcommand == 'gui': + arghost = args.host + if args.data_explorer: + + data_explorer.run_interface(arghost) + + elif args.iso3d: + iso3d.run_interface(arghost) + + elif args.annotation_tool: + annotation_tool.run_interface(arghost) + + elif args.local_thickness: + local_thickness.run_interface(arghost) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/qim3d/utils/internal_tools.py b/qim3d/utils/internal_tools.py index a4f6ede0..465cd1cf 100644 --- a/qim3d/utils/internal_tools.py +++ b/qim3d/utils/internal_tools.py @@ -267,8 +267,8 @@ def get_port_dict(): return port_dict -def run_gradio_app(gradio_interface): - host = "0.0.0.0" +def run_gradio_app(gradio_interface, host = "0.0.0.0"): + # Get port using the QIM API port_dict = get_port_dict() @@ -291,7 +291,7 @@ def run_gradio_app(gradio_interface): print(f"http://{host}:{port}{path}") # Run the FastAPI server usign uvicorn - run(app, host="0.0.0.0", port=int(port)) + run(app, host=host, port=int(port)) def get_css(): diff --git a/setup.py b/setup.py index 899bafa6..df399107 100644 --- a/setup.py +++ b/setup.py @@ -18,6 +18,11 @@ setup( url="https://lab.compute.dtu.dk/QIM/tools/qim3d", packages=find_packages(), include_package_data=True, + entry_points = { + 'console_scripts': [ + 'qim3d=qim3d.utils.cli:main' + ] + }, classifiers=[ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", -- GitLab