2021-02-23 14:13:33 +00:00
|
|
|
import typer
|
|
|
|
|
import sys
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
from plume.utils import lazy_module
|
2021-03-23 07:57:35 +00:00
|
|
|
|
2021-02-23 14:13:33 +00:00
|
|
|
# from streamlit import cli as stcli
|
|
|
|
|
|
2021-03-23 07:57:35 +00:00
|
|
|
stcli = lazy_module("streamlit.cli")
|
2021-02-23 14:13:33 +00:00
|
|
|
app = typer.Typer()
|
|
|
|
|
|
|
|
|
|
|
2021-03-23 07:57:35 +00:00
|
|
|
@app.callback()
|
|
|
|
|
def ui():
|
|
|
|
|
"""
|
|
|
|
|
ui sub commands
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
2021-02-23 14:13:33 +00:00
|
|
|
@app.command()
|
|
|
|
|
def annotation(data_dir: Path, dump_fname: Path = "ui_dump.json", task_id: str = ""):
|
|
|
|
|
annotation_lit_path = Path(__file__).parent / Path("annotation.py")
|
|
|
|
|
if task_id:
|
|
|
|
|
sys.argv = [
|
|
|
|
|
"streamlit",
|
|
|
|
|
"run",
|
|
|
|
|
str(annotation_lit_path),
|
|
|
|
|
"--",
|
|
|
|
|
str(data_dir),
|
|
|
|
|
"--task-id",
|
|
|
|
|
task_id,
|
|
|
|
|
"--dump-fname",
|
|
|
|
|
dump_fname,
|
|
|
|
|
]
|
|
|
|
|
else:
|
|
|
|
|
sys.argv = [
|
|
|
|
|
"streamlit",
|
|
|
|
|
"run",
|
|
|
|
|
str(annotation_lit_path),
|
|
|
|
|
"--",
|
|
|
|
|
str(data_dir),
|
|
|
|
|
"--dump-fname",
|
|
|
|
|
dump_fname,
|
|
|
|
|
]
|
|
|
|
|
sys.exit(stcli.main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.command()
|
|
|
|
|
def preview(manifest_path: Path):
|
|
|
|
|
annotation_lit_path = Path(__file__).parent / Path("preview.py")
|
2021-03-23 07:57:35 +00:00
|
|
|
sys.argv = ["streamlit", "run", str(annotation_lit_path), "--", str(manifest_path)]
|
2021-02-23 14:13:33 +00:00
|
|
|
sys.exit(stcli.main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.command()
|
|
|
|
|
def collection(data_dir: Path, task_id: str = ""):
|
|
|
|
|
# TODO: Implement web ui for data collection
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2021-03-23 07:57:35 +00:00
|
|
|
@app.command()
|
|
|
|
|
def alignment(preview_dir: Path, port: int = 8010):
|
|
|
|
|
from RangeHTTPServer import RangeRequestHandler
|
|
|
|
|
from functools import partial
|
|
|
|
|
from http.server import HTTPServer
|
|
|
|
|
|
|
|
|
|
server_address = ("", port)
|
|
|
|
|
handler_class = partial(RangeRequestHandler, directory=str(preview_dir))
|
|
|
|
|
httpd = HTTPServer(server_address, handler_class)
|
|
|
|
|
httpd.serve_forever()
|
|
|
|
|
|
|
|
|
|
|
2021-02-23 14:13:33 +00:00
|
|
|
def main():
|
|
|
|
|
app()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|