From 447cf773aaafd5e75a74857367a30e48f9fe42d3 Mon Sep 17 00:00:00 2001 From: WonJin Yoon Date: Thu, 11 Jul 2024 02:29:38 -0400 Subject: [PATCH 1/6] [Docs] Add documentation for webservice (kazu_webservice.rst) --- docs/kazu_webservice.rst | 72 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/docs/kazu_webservice.rst b/docs/kazu_webservice.rst index 5346d6f8e..838894194 100644 --- a/docs/kazu_webservice.rst +++ b/docs/kazu_webservice.rst @@ -1,2 +1,70 @@ -TBA -=== +Kazu as a Web Server (REST API) with FastAPI +============================================ + +The Kazu framework can be run in REST API mode with a few additional steps. This page provides a simple tutorial on how to host a REST API server using FastAPI. + +Installation +------------ + +First, clone the repository: + +.. code-block:: bash + + git clone https://github.com/AstraZeneca/KAZU.git + cd KAZU + +Install the library with the `webserver` option: + +.. code-block:: bash + + export VERSION=2.1.1 + pip install kazu[webserver]==${VERSION} + + wget https://github.com/AstraZeneca/KAZU/releases/download/v${VERSION}/kazu_model_pack_public-v${VERSION}.zip + unzip kazu_model_pack_public-v${VERSION}.zip + + export KAZU_MODEL_PACK=${PWD}/kazu_model_pack_public-v${VERSION} + +Run and Test the Server +----------------------- + +Run the web server: + +.. code-block:: bash + + mkdir run_dir + python -m kazu.web.server --config-path "${KAZU_MODEL_PACK}/conf" hydra.run.dir="${PWD}/run_dir" + +It will take a few minutes to be fully deployed. Once fully deployed, you will see a completion message. + +Following is an example of such a message: + +.. code-block:: bash + + 2024-07-11 01:44:28,366 INFO api.py:609 -- Deployed app 'default' successfully. + 2024-07-11 01:44:28,379 INFO server.py:648 -- ServeStatus(proxies={'0d2e08c45946473': }, + applications={'default': ApplicationStatusOverview(status=, message='', last_deployed_time_s=172067695.0692, + deployments={'KazuWebAPI': DeploymentStatusOverview(status=, status_trigger=, replica_states={'RUNNING': 1}, message='')})}, target_capacity=None) + +To test, execute the following example from any machine on the same network as the server: + +.. code-block:: bash + + # Set IP address according to the server. + # If the web server is running on the same server, use: + export IP_ADDR=127.0.0.1 + export PORT=8080 + + curl --header "Content-Type: application/json" --request POST \ + --data '{"text": "EGFR is an important gene in breast cancer study."}' \ + http://${IP_ADDR}:${PORT}/api/kazu + +FastAPI +------- + +You can see the FastAPI documentation at : + +http://:/docs + +One successful example is http://kazu.korea.ac.kr/docs. From aa6b679c90df589eac85165f96f567a9462aea1d Mon Sep 17 00:00:00 2001 From: WonJin Yoon Date: Thu, 11 Jul 2024 02:41:41 -0400 Subject: [PATCH 2/6] [Misc] Add environment used for testing the tutorial --- docs/kazu_webservice.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/kazu_webservice.rst b/docs/kazu_webservice.rst index 838894194..76c07f481 100644 --- a/docs/kazu_webservice.rst +++ b/docs/kazu_webservice.rst @@ -47,6 +47,7 @@ Following is an example of such a message: deployments={'KazuWebAPI': DeploymentStatusOverview(status=, status_trigger=, replica_states={'RUNNING': 1}, message='')})}, target_capacity=None) + To test, execute the following example from any machine on the same network as the server: .. code-block:: bash @@ -68,3 +69,8 @@ You can see the FastAPI documentation at : http://:/docs One successful example is http://kazu.korea.ac.kr/docs. + + +Note +---- +We tested this tutorial with python 3.9.6, Kazu 2.1.1, on a CPU-only linux server. From acd0eb7dc94e375a2f4884619c3777f18d57b75c Mon Sep 17 00:00:00 2001 From: WonJin Yoon Date: Thu, 11 Jul 2024 09:28:04 -0400 Subject: [PATCH 3/6] [Misc] Run pre-commit --- docs/kazu_webservice.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/kazu_webservice.rst b/docs/kazu_webservice.rst index 76c07f481..7296e96e9 100644 --- a/docs/kazu_webservice.rst +++ b/docs/kazu_webservice.rst @@ -35,16 +35,16 @@ Run the web server: mkdir run_dir python -m kazu.web.server --config-path "${KAZU_MODEL_PACK}/conf" hydra.run.dir="${PWD}/run_dir" -It will take a few minutes to be fully deployed. Once fully deployed, you will see a completion message. +It will take a few minutes to be fully deployed. Once fully deployed, you will see a completion message. Following is an example of such a message: .. code-block:: bash 2024-07-11 01:44:28,366 INFO api.py:609 -- Deployed app 'default' successfully. - 2024-07-11 01:44:28,379 INFO server.py:648 -- ServeStatus(proxies={'0d2e08c45946473': }, - applications={'default': ApplicationStatusOverview(status=, message='', last_deployed_time_s=172067695.0692, - deployments={'KazuWebAPI': DeploymentStatusOverview(status=, status_trigger=}, + applications={'default': ApplicationStatusOverview(status=, message='', last_deployed_time_s=172067695.0692, + deployments={'KazuWebAPI': DeploymentStatusOverview(status=, status_trigger=, replica_states={'RUNNING': 1}, message='')})}, target_capacity=None) @@ -73,4 +73,4 @@ One successful example is http://kazu.korea.ac.kr/docs. Note ---- -We tested this tutorial with python 3.9.6, Kazu 2.1.1, on a CPU-only linux server. +We tested this tutorial with python 3.9.6, Kazu 2.1.1, on a CPU-only linux server. From 7e35884949a3b57f6b1517b154a9a773f7b31edc Mon Sep 17 00:00:00 2001 From: Wonjin Yoon <13089179+wonjininfo@users.noreply.github.com> Date: Sat, 13 Jul 2024 02:30:18 -0400 Subject: [PATCH 4/6] Update kazu_webservice.rst Get the version of Kazu in a dynamic manner, Add correct term (Swagger UI), Test env --- docs/kazu_webservice.rst | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/docs/kazu_webservice.rst b/docs/kazu_webservice.rst index 7296e96e9..8fc968a65 100644 --- a/docs/kazu_webservice.rst +++ b/docs/kazu_webservice.rst @@ -17,8 +17,12 @@ Install the library with the `webserver` option: .. code-block:: bash - export VERSION=2.1.1 - pip install kazu[webserver]==${VERSION} + pip install 'kazu[webserver]' + + # Get the version of Kazu in a dynamic manner + # Alternatively, you can set the version string manually, + # for example: export VERSION=2.1.1 + export VERSION=$(python -c "from importlib.metadata import version; print(version('kazu'))") wget https://github.com/AstraZeneca/KAZU/releases/download/v${VERSION}/kazu_model_pack_public-v${VERSION}.zip unzip kazu_model_pack_public-v${VERSION}.zip @@ -61,16 +65,33 @@ To test, execute the following example from any machine on the same network as t --data '{"text": "EGFR is an important gene in breast cancer study."}' \ http://${IP_ADDR}:${PORT}/api/kazu -FastAPI +Demo Front Page +--------------- + +(New feature) - in development stage (PR #57) + +You can see the demo frontend page at: + +`http://:/` + +You can find an example from here: http://kazu.korea.ac.kr/ + + +Swagger UI (by FastAPI) ------- -You can see the FastAPI documentation at : +You can see the FastAPI documentation (Swagger UI) at : -http://:/docs +`http://:/api/docs` -One successful example is http://kazu.korea.ac.kr/docs. +One example is http://kazu.korea.ac.kr/api/docs Note ---- -We tested this tutorial with python 3.9.6, Kazu 2.1.1, on a CPU-only linux server. + +We tested this tutorial with: + +1. Python 3.9.6, Kazu 2.1.1, on a CPU-only Linux server. +2. Python 3.11, Kazu 2.1.1+, on a CPU-only macOS (Intel MacBook). + From 942b19268786d8e496e6c7b84c7bb7241f714b35 Mon Sep 17 00:00:00 2001 From: Richard Jackson Date: Thu, 12 Sep 2024 18:50:33 +0100 Subject: [PATCH 5/6] fixed short line on swagger header --- docs/kazu_webservice.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/kazu_webservice.rst b/docs/kazu_webservice.rst index 8fc968a65..d32e619ba 100644 --- a/docs/kazu_webservice.rst +++ b/docs/kazu_webservice.rst @@ -20,7 +20,7 @@ Install the library with the `webserver` option: pip install 'kazu[webserver]' # Get the version of Kazu in a dynamic manner - # Alternatively, you can set the version string manually, + # Alternatively, you can set the version string manually, # for example: export VERSION=2.1.1 export VERSION=$(python -c "from importlib.metadata import version; print(version('kazu'))") @@ -78,7 +78,7 @@ You can find an example from here: http://kazu.korea.ac.kr/ Swagger UI (by FastAPI) -------- +---------------------------- You can see the FastAPI documentation (Swagger UI) at : @@ -94,4 +94,3 @@ We tested this tutorial with: 1. Python 3.9.6, Kazu 2.1.1, on a CPU-only Linux server. 2. Python 3.11, Kazu 2.1.1+, on a CPU-only macOS (Intel MacBook). - From 84d6add92ff8cd9e9623332358ee8523988827fb Mon Sep 17 00:00:00 2001 From: Wonjin Yoon <13089179+wonjininfo@users.noreply.github.com> Date: Thu, 12 Sep 2024 14:55:54 -0400 Subject: [PATCH 6/6] Update kazu_webservice.rst (Use pip to install) --- docs/kazu_webservice.rst | 6 ------ 1 file changed, 6 deletions(-) diff --git a/docs/kazu_webservice.rst b/docs/kazu_webservice.rst index d32e619ba..63e1f4792 100644 --- a/docs/kazu_webservice.rst +++ b/docs/kazu_webservice.rst @@ -6,12 +6,6 @@ The Kazu framework can be run in REST API mode with a few additional steps. This Installation ------------ -First, clone the repository: - -.. code-block:: bash - - git clone https://github.com/AstraZeneca/KAZU.git - cd KAZU Install the library with the `webserver` option: