From 4ada9f8ac7e7565396156bbfb18653e5e0adef36 Mon Sep 17 00:00:00 2001 From: Ceyda Cinarel <15624271+cceyda@users.noreply.github.com> Date: Mon, 21 Jun 2021 22:04:07 +0900 Subject: [PATCH] rough template --- setup.py | 10 ++++---- torchserve_dashboard/api/__init__.py | 0 torchserve_dashboard/api/inference_api.py | 22 ++++++++++++++++++ .../{api.py => api/management_api.py} | 0 torchserve_dashboard/cli.py | 15 ++++++++++-- torchserve_dashboard/ui/__init__.py | 0 torchserve_dashboard/{ => ui}/icon.png | Bin torchserve_dashboard/ui/inference_dash.py | 16 +++++++++++++ .../{dash.py => ui/management_dash.py} | 5 ++-- 9 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 torchserve_dashboard/api/__init__.py create mode 100644 torchserve_dashboard/api/inference_api.py rename torchserve_dashboard/{api.py => api/management_api.py} (100%) create mode 100644 torchserve_dashboard/ui/__init__.py rename torchserve_dashboard/{ => ui}/icon.png (100%) create mode 100644 torchserve_dashboard/ui/inference_dash.py rename torchserve_dashboard/{dash.py => ui/management_dash.py} (98%) diff --git a/setup.py b/setup.py index 8025867..fddfe3e 100644 --- a/setup.py +++ b/setup.py @@ -96,8 +96,10 @@ def _prepare_extras(): # that you indicate whether you support Python 2, Python 3 or both. 'Programming Language :: Python :: 3', ], - entry_points=""" - [console_scripts] - torchserve-dashboard=torchserve_dashboard.cli:main - """, + entry_points={ + 'console_scripts':['torchserve-management=torchserve_dashboard.cli:manage', + 'torchserve-inference=torchserve_dashboard.cli:ui'] + # tentative..torchserve-dashboard may spin both independently. + # definitely want things on different ports though (should have port assignements too, to avoid confusion) + } ) diff --git a/torchserve_dashboard/api/__init__.py b/torchserve_dashboard/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/torchserve_dashboard/api/inference_api.py b/torchserve_dashboard/api/inference_api.py new file mode 100644 index 0000000..2b2b53f --- /dev/null +++ b/torchserve_dashboard/api/inference_api.py @@ -0,0 +1,22 @@ +import os +from typing import Any, Dict, List, Optional, Tuple, Union, Callable + +import httpx +from httpx import Response + +import logging + +class InferenceAPI: + def __init__(self, address: str, error_callback: Callable = None) -> None: + pass + + # get available models + # determine type of model (NOT currently possible, we don't know which endpoint maps to what type) + # auto generate python client based on model spec? (use library) + # or define explicitly like below (not sustainable) + def image_classify(endpoint,image): + # put image in request body + # + # res send(address+endpoint,req) + # return res + pass diff --git a/torchserve_dashboard/api.py b/torchserve_dashboard/api/management_api.py similarity index 100% rename from torchserve_dashboard/api.py rename to torchserve_dashboard/api/management_api.py diff --git a/torchserve_dashboard/cli.py b/torchserve_dashboard/cli.py index 8899c66..f4d2ed5 100644 --- a/torchserve_dashboard/cli.py +++ b/torchserve_dashboard/cli.py @@ -10,7 +10,18 @@ @configurator_options @click.argument("args", nargs=-1) @click.pass_context -def main(ctx: click.Context, args: Any, **kwargs: Any): +def manage(ctx: click.Context, args: Any, **kwargs: Any): dirname = os.path.dirname(__file__) - filename = os.path.join(dirname, 'dash.py') + filename = os.path.join(dirname, 'ui/management_dash.py') + ctx.forward(streamlit.cli.main_run, target=filename, args=args, *kwargs) + + +@click.command(context_settings=dict(ignore_unknown_options=True, + allow_extra_args=True)) +@configurator_options +@click.argument("args", nargs=-1) +@click.pass_context +def ui(ctx: click.Context, args: Any, **kwargs: Any): + dirname = os.path.dirname(__file__) + filename = os.path.join(dirname, 'ui/inference_dash.py') ctx.forward(streamlit.cli.main_run, target=filename, args=args, *kwargs) diff --git a/torchserve_dashboard/ui/__init__.py b/torchserve_dashboard/ui/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/torchserve_dashboard/icon.png b/torchserve_dashboard/ui/icon.png similarity index 100% rename from torchserve_dashboard/icon.png rename to torchserve_dashboard/ui/icon.png diff --git a/torchserve_dashboard/ui/inference_dash.py b/torchserve_dashboard/ui/inference_dash.py new file mode 100644 index 0000000..9b705a9 --- /dev/null +++ b/torchserve_dashboard/ui/inference_dash.py @@ -0,0 +1,16 @@ +import streamlit as st + +#def ImageClassifier Component (may auto generate based on spec) + + +#def ImageSegmentation Component + + +#def TextClassifier Component + +#... + +# list available endpoints +# show component based on model type (NOT currently possible, we don't know which endpoint maps to what type) +# call endpoint api with inputs + diff --git a/torchserve_dashboard/dash.py b/torchserve_dashboard/ui/management_dash.py similarity index 98% rename from torchserve_dashboard/dash.py rename to torchserve_dashboard/ui/management_dash.py index 64e420b..67917e7 100644 --- a/torchserve_dashboard/dash.py +++ b/torchserve_dashboard/ui/management_dash.py @@ -4,7 +4,8 @@ import streamlit as st from httpx import Response -from torchserve_dashboard.api import ManagementAPI, LocalTS +from torchserve_dashboard.api.management_api import ManagementAPI, LocalTS +from torchserve_dashboard import _PACKAGE_ROOT from pathlib import Path st.set_page_config( @@ -48,7 +49,7 @@ def check_args(args): metrics_location = args.metrics_location if not os.path.exists(config_path): st.write(f"Can't find config file at {config_path}. Using default config instead") - config_path = os.path.join(os.path.dirname(__file__), "default.torchserve.properties") + config_path = os.path.join(_PACKAGE_ROOT, "default.torchserve.properties") if os.path.exists(config_path): config = open(config_path, "r").readlines() for c in config: