vvk-jsl-inference 1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. vvk_jsl_inference-1.0/LICENSE +28 -0
  2. vvk_jsl_inference-1.0/PKG-INFO +58 -0
  3. vvk_jsl_inference-1.0/README.md +139 -0
  4. vvk_jsl_inference-1.0/endpoints/__about__.py +1 -0
  5. vvk_jsl_inference-1.0/endpoints/__init__.py +33 -0
  6. vvk_jsl_inference-1.0/endpoints/cli/__init__.py +9 -0
  7. vvk_jsl_inference-1.0/endpoints/cli/cli.py +131 -0
  8. vvk_jsl_inference-1.0/endpoints/cli/internals.py +80 -0
  9. vvk_jsl_inference-1.0/endpoints/cli/options.py +32 -0
  10. vvk_jsl_inference-1.0/endpoints/container/Dockerfile +45 -0
  11. vvk_jsl_inference-1.0/endpoints/container/__init__.py +66 -0
  12. vvk_jsl_inference-1.0/endpoints/container/requests.py +27 -0
  13. vvk_jsl_inference-1.0/endpoints/container/setup.py +69 -0
  14. vvk_jsl_inference-1.0/endpoints/container/utils.py +622 -0
  15. vvk_jsl_inference-1.0/endpoints/core/__init__.py +6 -0
  16. vvk_jsl_inference-1.0/endpoints/core/exceptions.py +2 -0
  17. vvk_jsl_inference-1.0/endpoints/core/model_info.py +68 -0
  18. vvk_jsl_inference-1.0/endpoints/core/model_registry.py +411 -0
  19. vvk_jsl_inference-1.0/endpoints/core/models/__init__.py +7 -0
  20. vvk_jsl_inference-1.0/endpoints/core/models/base.py +106 -0
  21. vvk_jsl_inference-1.0/endpoints/core/models/schema.py +145 -0
  22. vvk_jsl_inference-1.0/endpoints/core/utils.py +50 -0
  23. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/__init__.py +26 -0
  24. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/chromadb_resolver_model_loader.py +57 -0
  25. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/encoder.py +35 -0
  26. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/healthcare/__init__.py +4 -0
  27. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/healthcare/loader/__init__.py +3 -0
  28. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/healthcare/loader/chroma_loader.py +478 -0
  29. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/healthcare/loader/healthcare_loader.py +56 -0
  30. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/healthcare/models/__init__.py +17 -0
  31. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/healthcare/models/chromadb_resolver.py +187 -0
  32. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/healthcare/models/deidentification.py +219 -0
  33. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/healthcare/models/entity_extraction.py +238 -0
  34. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/healthcare/models/explain_doc_clinical_granular.py +10 -0
  35. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/healthcare/models/extract_clinical_doc_sodh_small.py +10 -0
  36. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/healthcare/models/extract_sdoh.py +95 -0
  37. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/healthcare/models/med_nlp.py +138 -0
  38. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/healthcare/models/mh_extract_entities.py +8 -0
  39. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/healthcare/models_hub.py +82 -0
  40. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/healthcare/registry.py +272 -0
  41. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/installer.py +163 -0
  42. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/jsl_model.py +97 -0
  43. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/license_utils.py +123 -0
  44. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/model_loader.py +74 -0
  45. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/spark_session.py +96 -0
  46. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/utils.py +78 -0
  47. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/visual/__init__.py +8 -0
  48. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/visual/loader.py +61 -0
  49. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/visual/models/__init__.py +4 -0
  50. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/visual/models/pdf_deidentification.py +41 -0
  51. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/visual/models/visual_nlp.py +181 -0
  52. vvk_jsl_inference-1.0/endpoints/johnsnowlabs/visual/registry.py +13 -0
  53. vvk_jsl_inference-1.0/endpoints/logging/__init__.py +33 -0
  54. vvk_jsl_inference-1.0/endpoints/logging/config.py +3 -0
  55. vvk_jsl_inference-1.0/endpoints/pip_utils.py +13 -0
  56. vvk_jsl_inference-1.0/endpoints/sagemaker/__init__.py +340 -0
  57. vvk_jsl_inference-1.0/endpoints/sagemaker/cli.py +176 -0
  58. vvk_jsl_inference-1.0/endpoints/sagemaker/client.py +185 -0
  59. vvk_jsl_inference-1.0/endpoints/sagemaker/marketplace/__init__.py +3 -0
  60. vvk_jsl_inference-1.0/endpoints/sagemaker/marketplace/constants.py +30 -0
  61. vvk_jsl_inference-1.0/endpoints/sagemaker/marketplace/helper.py +221 -0
  62. vvk_jsl_inference-1.0/endpoints/sagemaker/marketplace/marketplace.py +235 -0
  63. vvk_jsl_inference-1.0/endpoints/sagemaker/router.py +54 -0
  64. vvk_jsl_inference-1.0/endpoints/sagemaker/utils.py +428 -0
  65. vvk_jsl_inference-1.0/endpoints/server/__init__.py +13 -0
  66. vvk_jsl_inference-1.0/endpoints/server/app_config.py +157 -0
  67. vvk_jsl_inference-1.0/endpoints/server/dependencies.py +122 -0
  68. vvk_jsl_inference-1.0/endpoints/server/engine/__init__.py +3 -0
  69. vvk_jsl_inference-1.0/endpoints/server/engine/engine.py +42 -0
  70. vvk_jsl_inference-1.0/endpoints/server/engine/jsl_engine.py +99 -0
  71. vvk_jsl_inference-1.0/endpoints/server/exceptions.py +2 -0
  72. vvk_jsl_inference-1.0/endpoints/server/request/parsers.py +132 -0
  73. vvk_jsl_inference-1.0/endpoints/server/response/generator.py +257 -0
  74. vvk_jsl_inference-1.0/endpoints/server/routers/healthcheck.py +13 -0
  75. vvk_jsl_inference-1.0/endpoints/server/server.py +224 -0
  76. vvk_jsl_inference-1.0/endpoints/server/utils.py +118 -0
  77. vvk_jsl_inference-1.0/endpoints/settings.py +81 -0
  78. vvk_jsl_inference-1.0/endpoints/snowflake/__init__.py +282 -0
  79. vvk_jsl_inference-1.0/endpoints/snowflake/cli.py +163 -0
  80. vvk_jsl_inference-1.0/endpoints/snowflake/config.py +25 -0
  81. vvk_jsl_inference-1.0/endpoints/snowflake/manager.py +572 -0
  82. vvk_jsl_inference-1.0/endpoints/snowflake/marketplace/__init__.py +4 -0
  83. vvk_jsl_inference-1.0/endpoints/snowflake/marketplace/app_package.py +374 -0
  84. vvk_jsl_inference-1.0/endpoints/snowflake/marketplace/constants.py +1 -0
  85. vvk_jsl_inference-1.0/endpoints/snowflake/marketplace/helper.py +181 -0
  86. vvk_jsl_inference-1.0/endpoints/snowflake/marketplace/marketplace.py +143 -0
  87. vvk_jsl_inference-1.0/endpoints/snowflake/marketplace/templates/input_config.py +16 -0
  88. vvk_jsl_inference-1.0/endpoints/snowflake/marketplace/templates/setup.sql +166 -0
  89. vvk_jsl_inference-1.0/endpoints/snowflake/marketplace/templates/streamlit_app.py +400 -0
  90. vvk_jsl_inference-1.0/endpoints/snowflake/router.py +236 -0
  91. vvk_jsl_inference-1.0/endpoints/snowflake/tester.py +287 -0
  92. vvk_jsl_inference-1.0/endpoints/snowflake/utils.py +57 -0
  93. vvk_jsl_inference-1.0/endpoints/utils.py +310 -0
  94. vvk_jsl_inference-1.0/pyproject.toml +49 -0
  95. vvk_jsl_inference-1.0/setup.cfg +4 -0
  96. vvk_jsl_inference-1.0/tests/test_platform.py +44 -0
  97. vvk_jsl_inference-1.0/tests/test_utils.py +137 -0
  98. vvk_jsl_inference-1.0/vvk_jsl_inference.egg-info/PKG-INFO +58 -0
  99. vvk_jsl_inference-1.0/vvk_jsl_inference.egg-info/SOURCES.txt +101 -0
  100. vvk_jsl_inference-1.0/vvk_jsl_inference.egg-info/dependency_links.txt +1 -0
  101. vvk_jsl_inference-1.0/vvk_jsl_inference.egg-info/entry_points.txt +2 -0
  102. vvk_jsl_inference-1.0/vvk_jsl_inference.egg-info/requires.txt +24 -0
  103. vvk_jsl_inference-1.0/vvk_jsl_inference.egg-info/top_level.txt +1 -0
@@ -0,0 +1,28 @@
1
+ Copyright 2015-2025 © John Snow Labs Inc.
2
+
3
+ This Software ("Software" or "Product") including code, design, documentation, configuration, models, tests, and related assets is owned by John Snow Labs Inc. All rights reserved.
4
+
5
+ John Snow Labs Inc. ("we") is the only owner of the copyright for this Software.
6
+
7
+ Unless otherwise specified in a separate Software License Agreement, Services Agreement, or End User License Agreement that you have executed directly with John Snow Labs Inc.:
8
+
9
+ * You are NOT granted any license or right to use the Software in any way.
10
+ * You are NOT granted any license or right to retain a copy of this Software.
11
+ * You are NOT granted any license or right to change, modify, adapt, or translate the Software.
12
+ * You are NOT granted any license or right to sell, assign, rent, exchange, lend, lease, sublease, or redistribute the Software.
13
+ * You are NOT granted any license or rights to bundle, repackage, or include the Software with any software in any way.
14
+ * The Software is Confidential and Proprietary. You are NOT allowed to distribute copies of the Software to others by any means whatsoever.
15
+ * The Software does NOT come with any warranty, express or implied.
16
+ * It is NOT legal to create derivative works based on the Software.
17
+ * It is NOT legal to claim any title in the Software or any of its derivatives.
18
+ * It is NOT legal to reverse engineer, disassemble or decompile the Software.
19
+ * It is NOT legal to make or retain a copy of the Software.
20
+ * We have no liability whatsoever for use of the Software.
21
+ * You may not make any public statements about this Software or John Snow Labs without explicit written permission from John Snow Labs.
22
+ * You must retain a copy of this notice without changes along with every copy of the Software, even if you have a license for it.
23
+
24
+ Unless required by applicable law or agreed to in writing, John Snow Labs provides the Software on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Software and assume any risks associated with Your exercise of permissions under this license.
25
+
26
+ In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall John Snow Labs be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this license or out of the use or inability to use the Software (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if advised of the possibility of such damages.
27
+
28
+ Unless required by applicable law or agreed to in writing, Software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -0,0 +1,58 @@
1
+ Metadata-Version: 2.4
2
+ Name: vvk_jsl_inference
3
+ Version: 1.0
4
+ Maintainer-email: Vivek Shrestha <vivek@johnsnowlabs.com>
5
+ License: Copyright 2015-2025 © John Snow Labs Inc.
6
+
7
+ This Software ("Software" or "Product") including code, design, documentation, configuration, models, tests, and related assets is owned by John Snow Labs Inc. All rights reserved.
8
+
9
+ John Snow Labs Inc. ("we") is the only owner of the copyright for this Software.
10
+
11
+ Unless otherwise specified in a separate Software License Agreement, Services Agreement, or End User License Agreement that you have executed directly with John Snow Labs Inc.:
12
+
13
+ * You are NOT granted any license or right to use the Software in any way.
14
+ * You are NOT granted any license or right to retain a copy of this Software.
15
+ * You are NOT granted any license or right to change, modify, adapt, or translate the Software.
16
+ * You are NOT granted any license or right to sell, assign, rent, exchange, lend, lease, sublease, or redistribute the Software.
17
+ * You are NOT granted any license or rights to bundle, repackage, or include the Software with any software in any way.
18
+ * The Software is Confidential and Proprietary. You are NOT allowed to distribute copies of the Software to others by any means whatsoever.
19
+ * The Software does NOT come with any warranty, express or implied.
20
+ * It is NOT legal to create derivative works based on the Software.
21
+ * It is NOT legal to claim any title in the Software or any of its derivatives.
22
+ * It is NOT legal to reverse engineer, disassemble or decompile the Software.
23
+ * It is NOT legal to make or retain a copy of the Software.
24
+ * We have no liability whatsoever for use of the Software.
25
+ * You may not make any public statements about this Software or John Snow Labs without explicit written permission from John Snow Labs.
26
+ * You must retain a copy of this notice without changes along with every copy of the Software, even if you have a license for it.
27
+
28
+ Unless required by applicable law or agreed to in writing, John Snow Labs provides the Software on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Software and assume any risks associated with Your exercise of permissions under this license.
29
+
30
+ In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall John Snow Labs be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this license or out of the use or inability to use the Software (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if advised of the possibility of such damages.
31
+
32
+ Unless required by applicable law or agreed to in writing, Software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33
+
34
+ Requires-Python: >=3.8
35
+ License-File: LICENSE
36
+ Requires-Dist: click<9.0.0,>=8.1.8
37
+ Requires-Dist: johnsnowlabs<7.0.0,>=6.2.0
38
+ Requires-Dist: fastapi<1.0.0,>=0.115.6
39
+ Requires-Dist: uvicorn<1.0.0,>=0.33.0
40
+ Requires-Dist: uvloop<1.0.0,>=0.21.0
41
+ Requires-Dist: httptools<1.0.0,>=0.6.4
42
+ Requires-Dist: cloudpickle<4.0.0,>=3.0.0
43
+ Requires-Dist: psutil<8.0.0,>=7.2.2
44
+ Provides-Extra: dev
45
+ Requires-Dist: pytest>=8.3.4; extra == "dev"
46
+ Requires-Dist: pytest-mock>=3.14.0; extra == "dev"
47
+ Requires-Dist: pytest-cov>=5.0.0; extra == "dev"
48
+ Requires-Dist: httpx; extra == "dev"
49
+ Requires-Dist: black; extra == "dev"
50
+ Requires-Dist: ruff; extra == "dev"
51
+ Requires-Dist: snowflake.core; extra == "dev"
52
+ Requires-Dist: pytest-asyncio; extra == "dev"
53
+ Provides-Extra: docs
54
+ Requires-Dist: mkdocs>=1.6.1; extra == "docs"
55
+ Requires-Dist: mkdocs-click>=0.8.1; extra == "docs"
56
+ Requires-Dist: mkdocs-material>=9.7.6; extra == "docs"
57
+ Requires-Dist: mkdocstrings[python]>=0.18; extra == "docs"
58
+ Dynamic: license-file
@@ -0,0 +1,139 @@
1
+ # endpoints
2
+
3
+
4
+ ## Development
5
+
6
+ ### Pre-requisites
7
+
8
+ - Python 3.8 or higher
9
+ - Docker
10
+ - A valid JSL License
11
+
12
+ ### Setup
13
+
14
+ ```bash
15
+ make install-dev
16
+ ```
17
+
18
+ ### CLI
19
+
20
+ The `jsl_inference` CLI provides commands to deploy John Snow Labs healthcare NLP models to AWS SageMaker and Snowflake platforms.
21
+
22
+ **Get started with the CLI:**
23
+
24
+ ```bash
25
+ # View all available commands
26
+ jsl_inference --help
27
+
28
+ # View SageMaker-specific commands
29
+ jsl_inference sagemaker --help
30
+
31
+ # View Snowflake-specific commands
32
+ jsl_inference snowflake --help
33
+ ```
34
+
35
+ **Example usage:**
36
+
37
+ ```bash
38
+ # Deploy a clinical deidentification model to SageMaker
39
+ jsl_inference sagemaker deploy clinical_deidentification_docwise_wip \
40
+ --endpoint-name my-clinical-model \
41
+ --instance-type ml.m5.large
42
+
43
+ # Run a model locally for testing
44
+ jsl_inference serve clinical_deidentification_docwise_wip --port 8080
45
+
46
+ # Deploy to Snowflake with container services
47
+ jsl_inference snowflake deploy clinical_deidentification_docwise_wip \
48
+ --service-name prediction_service \
49
+ --compute-pool-name my_compute_pool
50
+ ```
51
+
52
+
53
+
54
+ ## Docs
55
+
56
+ Documentation is served using MkDocs. To view the documentation, run:
57
+
58
+ ```bash
59
+ make docs
60
+ ```
61
+ This will start a local development server and serve the documentation at `http://127.0.0.1:8000/`. The server will automatically reload when documentation files are modified.
62
+
63
+ ## Testing
64
+
65
+ Tests are run via the Makefile which handles virtual environment setup and dependency installation automatically.
66
+
67
+ To run the tests, use one of the following commands:
68
+
69
+ ```bash
70
+ # Run tests (installs dependencies automatically)
71
+ make test
72
+
73
+ # Run tests with verbose output
74
+ make test-verbose
75
+
76
+ # Run tests with coverage report
77
+ make test-coverage
78
+ ```
79
+
80
+ Alternatively, if you prefer to manage dependencies manually:
81
+ ```bash
82
+ pip install -e .[dev]
83
+ pytest
84
+ ```
85
+
86
+ ## Publishing
87
+
88
+ ### Prerequisites
89
+ Before publishing to PyPI, ensure you have:
90
+ - `TWINE_PASSWORD` environment variable set with your PyPI API token
91
+ - Appropriate permissions to publish the package
92
+
93
+ ### Version Management
94
+ To update the package version, modify the `__version__` variable in `endpoints/__about__.py`:
95
+
96
+ ```python
97
+ __version__ = "x.y.z"
98
+ ```
99
+
100
+ ### Publishing to PyPI
101
+ Once the version is updated and prerequisites are met, publish the package:
102
+
103
+ ```bash
104
+ make publish
105
+ ```
106
+
107
+ This command will build the package and upload it to PyPI using twine.
108
+
109
+ ### Toolkit
110
+
111
+ To get some information on the available models and its details, use this helper command
112
+
113
+ <small>Please make sure to install dependencies before. See tools/requirements.txt </small>
114
+ ```bash
115
+ python tools/models_info.py
116
+ ```
117
+ You can also refer the help for this toolkit
118
+
119
+ ```bash
120
+ python tools/models_info.py --help
121
+ ```
122
+
123
+ ### Run tests for models
124
+
125
+ Execute tests for a single model classed in johnsnowlabs. Example
126
+ ```shell
127
+ pytest -q tests/johnsnowlabs/models/test_extract_entities.py
128
+ ```
129
+
130
+
131
+
132
+ ## Databricks Development (Needs to fixed)
133
+
134
+ see `databricks_tests.py`
135
+ 1. Start up a Databricks Cluster producer. Once Started you must **manually enable it to Unity Catalog**
136
+ 2. Submit publisher job
137
+ 3. Once completed, need to go to provider UI and publish the model to either private or public exchange
138
+ 4. Once published, **you must manually import the listing on consumer end form the UI and accept the Terms of usage**. Then model can be tested via consumer jobs
139
+
@@ -0,0 +1 @@
1
+ __version__ = "1.0"
@@ -0,0 +1,33 @@
1
+ """JSL Inference Module"""
2
+
3
+ from enum import Enum
4
+
5
+
6
+ class ModelType(str, Enum):
7
+ LOCAL = "local"
8
+ PRETRAINED_HEALTHCARE = "pretrained_healthcare"
9
+ PRETRAINED_VISUAL = "pretrained_visual"
10
+ CHROMADB_RESOLVER = "chromadb_resolver"
11
+
12
+
13
+ class Platform(str, Enum):
14
+ SAGEMAKER = "sagemaker"
15
+ SNOWFLAKE = "snowflake"
16
+ LOCAL = "local"
17
+
18
+ def get_python_requirements(self):
19
+ if self == Platform.SNOWFLAKE:
20
+ return ["snowflake.core"]
21
+ return []
22
+
23
+
24
+ class JslInferenceException(Exception):
25
+ """Exception for JSL Inference errors"""
26
+
27
+ pass
28
+
29
+
30
+ class JslLicenseException(Exception):
31
+ """Exception for JSL License errors"""
32
+
33
+ pass
@@ -0,0 +1,9 @@
1
+ from endpoints.logging import init_logging
2
+
3
+ from .internals import run_local
4
+
5
+ init_logging()
6
+
7
+ from .cli import cli
8
+
9
+ __all__ = ["cli", "run_local"]
@@ -0,0 +1,131 @@
1
+ from typing import Optional
2
+
3
+ import click
4
+
5
+ from endpoints import Platform
6
+ from endpoints.core.exceptions import ModelRegistryException
7
+ from endpoints.sagemaker.cli import sagemaker
8
+
9
+ from . import internals
10
+
11
+
12
+ @click.group()
13
+ def cli():
14
+ """
15
+ John Snow Labs Endpoints CLI - Deploy and manage JSL models across platforms.
16
+
17
+ This command-line interface provides tools for deploying John Snow Labs models
18
+ to various cloud platforms and running local inference servers. It supports
19
+ multiple deployment targets including SageMaker, Snowflake, and local development.
20
+
21
+ Use the subcommands to deploy to specific platforms or start a local server
22
+ for development and testing purposes.
23
+
24
+ Examples:
25
+
26
+ # Start a local inference server
27
+ endpoints serve my-model-name
28
+
29
+ # Deploy to SageMaker
30
+ endpoints sagemaker deploy my-model-name
31
+
32
+ # Deploy to Snowflake
33
+ endpoints snowflake deploy my-model-name
34
+ """
35
+ pass
36
+
37
+
38
+ @cli.command()
39
+ @click.argument("model_id")
40
+ @click.option(
41
+ "--language", required=False, default="en", help="The language of the model"
42
+ )
43
+ @click.option("--port", required=False, default=8080)
44
+ @click.option("--api-server-count", type=int, required=False, default=None)
45
+ @click.option("--load-from-disk", is_flag=True, show_default=True, default=False)
46
+ def serve(
47
+ model_id: str,
48
+ language: str,
49
+ port: int,
50
+ api_server_count: Optional[int],
51
+ load_from_disk: bool = False,
52
+ ):
53
+ """
54
+ Start a local JSL Inference Server for development and testing.
55
+
56
+ This command launches a local inference server that can be used for development,
57
+ testing, and prototyping with John Snow Labs models. The server provides REST
58
+ API endpoints for model inference and can be accessed via HTTP requests.
59
+
60
+ Args:
61
+ model_id: The identifier of the JSL model to serve. This should be a valid
62
+ model name from the John Snow Labs model repository.
63
+
64
+ Options:
65
+ --language: The language variant of the model (default: "en").
66
+ --port: The port number for the local server (default: 8080).
67
+ --api-server-count: Number of Uvicorn workers.
68
+ --load-from-disk: Download the model to MODEL_LOCATION (/opt/ml/model) and
69
+ load it from disk (default: False).
70
+
71
+ Examples:
72
+ # Start server with default settings
73
+ endpoints serve ner_dl_bert
74
+
75
+ # Start server on custom port with Spanish model
76
+ endpoints serve ner_dl_bert --language es --port 9000
77
+
78
+ # Start multilingual model
79
+ endpoints serve multilingual_ner --language xx
80
+ """
81
+ try:
82
+ internals.run_local(
83
+ model_id=model_id,
84
+ language=language,
85
+ platform=Platform.LOCAL,
86
+ port=port,
87
+ api_server_count=api_server_count,
88
+ load_from_disk=load_from_disk,
89
+ )
90
+ except ModelRegistryException as e:
91
+ click.echo(e)
92
+
93
+
94
+ @cli.command()
95
+ @click.option(
96
+ "--language", required=False, default=None, help="The language of the model"
97
+ )
98
+ @click.option("--type", required=False, default=None)
99
+ def list_models(language: str, type: str):
100
+ """
101
+ List models registered in models registry.
102
+
103
+ Options:
104
+ --language: The language variant of the model (example: "en", "it", "es").
105
+ --type: Model type. One of the following: local, pretrained_healthcare, pretrained_visual, chromadb_resolver
106
+
107
+ Examples:
108
+ # List models registered in models registry
109
+ jsl_inference list-models
110
+ # Filter by type
111
+ jsl_inference list-models --type local
112
+ # Filter by language
113
+ jsl_inference list-models --language en
114
+ """
115
+ results = internals.list_models(language=language, type=type)
116
+ click.echo_via_pager("\n".join(results))
117
+
118
+
119
+ cli.add_command(sagemaker)
120
+
121
+ try:
122
+ from endpoints.snowflake.cli import snowflake
123
+
124
+ cli.add_command(snowflake)
125
+ except ImportError:
126
+ pass
127
+
128
+ if __name__ == "__main__":
129
+ from endpoints.cli import *
130
+
131
+ cli()
@@ -0,0 +1,80 @@
1
+ from difflib import get_close_matches
2
+ from typing import List, Optional
3
+
4
+ from endpoints import Platform
5
+ from endpoints.core.exceptions import ModelRegistryException
6
+
7
+
8
+ def run_local(
9
+ model_id: str,
10
+ language: str,
11
+ platform: Platform,
12
+ port: int = 8080,
13
+ api_server_count: Optional[int] = None,
14
+ load_from_disk: bool = False,
15
+ ) -> None:
16
+ """Run a model locally using the endpoints server.
17
+
18
+ Args:
19
+ model_id: Identifier of the model to run.
20
+ language: Language key used to resolve the model.
21
+ platform: Platform configuration used for local serving.
22
+ port: Port number for the local server.
23
+ api_server_count: Number of API workers to start.
24
+
25
+ Returns:
26
+ None
27
+ """
28
+ from endpoints.core import ModelRegistry
29
+ from endpoints.server import serve, setup_env
30
+
31
+ try:
32
+ model = ModelRegistry.find(model_id, language)
33
+ setup_env(model=model, platform=platform, store_model=load_from_disk)
34
+
35
+ serve(model=model, platform=platform, port=port, workers=api_server_count)
36
+ except ModelRegistryException as e:
37
+ matches = get_close_matches(
38
+ model_id, ModelRegistry._key_to_models.keys(), n=3, cutoff=0.5
39
+ )
40
+ matched_model = [ModelRegistry.get_by_key(match) for match in matches]
41
+ similar_strings = "\n- ".join(
42
+ [
43
+ f"ModelId: {model.model_id} Language: {model.language}"
44
+ for model in matched_model
45
+ ]
46
+ )
47
+ raise ModelRegistryException(
48
+ f"Model {model_id} not found. Did you mean? \n- {similar_strings}"
49
+ )
50
+
51
+
52
+ def list_models(type: str, language: str) -> List[str]:
53
+ """List registered models
54
+
55
+ Args:
56
+ type: Type of model.
57
+ language: Language of model.
58
+
59
+ Returns:
60
+ List mode model.key
61
+ """
62
+ from endpoints.core import ModelRegistry
63
+
64
+ if type:
65
+ from endpoints import ModelType
66
+
67
+ t_enum = ModelType(type)
68
+ else:
69
+ t_enum = None
70
+
71
+ models = ModelRegistry.filter(model_type=t_enum, language=language)
72
+ models = [
73
+ (
74
+ f"Model ID:{model.model_id}"
75
+ if model.language == "en"
76
+ else f"Model ID:{model.model_id}, Language: {model.language}"
77
+ )
78
+ for model in models
79
+ ]
80
+ return models
@@ -0,0 +1,32 @@
1
+ import click
2
+
3
+ from endpoints.settings import DEFAULT_JOHNSNOWLABS_VERSION
4
+
5
+
6
+ def common_options(f):
7
+ """
8
+ A decorator to add common CLI options for SageMaker commands, including:
9
+ - Model argument (required).
10
+ - John Snow Labs version.
11
+ - Flags to store license and model in the Docker image.
12
+ """
13
+ f = click.argument("model_id")(f)
14
+ f = click.option(
15
+ "--johnsnowlabs-version",
16
+ default=DEFAULT_JOHNSNOWLABS_VERSION,
17
+ help=f"Version of the John Snow Labs library (default: {DEFAULT_JOHNSNOWLABS_VERSION})",
18
+ )(f)
19
+ f = click.option(
20
+ "--language",
21
+ default="en",
22
+ help="Language of the model (default: en)",
23
+ )(f)
24
+ f = click.option(
25
+ "--no-license",
26
+ is_flag=True,
27
+ default=False,
28
+ show_default=True,
29
+ help="Do not include the license file in the Docker image. Default: False",
30
+ )(f)
31
+
32
+ return f
@@ -0,0 +1,45 @@
1
+ FROM ubuntu:22.04 AS jsl_build
2
+ ENV PYSPARK_PYTHON=python3
3
+ ENV PYSPARK_DRIVER_PYTHON=python3
4
+ ENV DEBIAN_FRONTEND=noninteractive
5
+ ENV TF_CPP_MIN_LOG_LEVEL='3'
6
+ ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64/
7
+ RUN echo "export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64/" >> ~/.bashrc
8
+ ENV LC_ALL=C.UTF-8 LANG=C.UTF-8
9
+
10
+ RUN apt-get update && apt-get install --no-install-recommends -y \
11
+ openjdk-17-jdk-headless \
12
+ python3 python3-pip python3-packaging\
13
+ curl && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
14
+
15
+ COPY requirements.txt .
16
+ RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt
17
+ RUN rm -rf /root/.cache
18
+
19
+
20
+ FROM jsl_build AS dependencies
21
+ ENV JSL_MODEL_REGISTRY_HOME=/root/.jsl_inference/model_registry/
22
+ RUN mkdir -p /opt/ml/model
23
+
24
+ {{COPY_ARTIFACTS_INSTRUCTION}}
25
+
26
+ COPY --from=jsl_model_registry . $JSL_MODEL_REGISTRY_HOME
27
+
28
+ RUN --mount=type=secret,id=license --mount=type=bind,rw,from=jsl_cache_pretrained,source=.,target=/root/cache_pretrained {{SETUP_ENVIRONMENT}}
29
+
30
+
31
+ FROM jsl_build AS final_build
32
+ {{ENVIRONMENT_VARIABLES}}
33
+
34
+ WORKDIR /app
35
+ ENV JSL_MODEL_REGISTRY_HOME=/root/.jsl_inference/model_registry/
36
+ COPY LICENSE .
37
+ ENV PYTHONPATH=/app
38
+ COPY --from=jsl_model_registry . $JSL_MODEL_REGISTRY_HOME
39
+ COPY --from=dependencies /usr/local/lib/python3.10/dist-packages/ /usr/local/lib/python3.10/dist-packages/
40
+ COPY --from=dependencies /root/.johnsnowlabs/ /root/.johnsnowlabs
41
+ COPY --from=dependencies /opt/ml/model/ /opt/ml/model/
42
+ RUN pip install pyspark==3.5.0 --upgrade
43
+ RUN rm /usr/local/lib/python3.10/dist-packages/pyspark/jars/libthrift-0.12.0.jar
44
+
45
+ {{ENTRYPOINT}}
@@ -0,0 +1,66 @@
1
+ """Container module for serving inference models in Docker environments.
2
+
3
+ This module provides functionality for containerizing and serving machine learning
4
+ models using Docker. It includes utilities for building Docker images, generating
5
+ Docker files, and setting up container environments for model inference.
6
+
7
+ The module supports various deployment platforms and provides a standardized way
8
+ to package and deploy models in containerized environments.
9
+ """
10
+
11
+ from typing import Optional
12
+
13
+ from endpoints.server import find_model_to_serve, serve
14
+ from endpoints.settings import config
15
+
16
+ from .setup import setup_container_env
17
+ from .utils import (
18
+ build_docker_image,
19
+ format_docker_image_name,
20
+ format_image_tag,
21
+ generate_docker_files,
22
+ validate_docker_image_name,
23
+ validate_image_tag,
24
+ )
25
+
26
+
27
+ # Default entrypoint for the Docker containers
28
+ def _init(command, model_id: Optional[str], language: Optional[str]):
29
+ """Initialize and execute commands for containerized model serving.
30
+
31
+ This function serves as the main entrypoint for Docker containers, handling
32
+ different commands for model operations. Currently supports serving models
33
+ for inference.
34
+
35
+ Args:
36
+ command: The command to execute ('serve' for model serving).
37
+ model_id (str): Unique identifier for the model to be loaded.
38
+ language (str): Programming language or model language specification.
39
+
40
+ Raises:
41
+ NotImplementedError: If the provided command is not implemented.
42
+
43
+ Example:
44
+ >>> _init('serve', 'bert-base-uncased', 'en')
45
+ # Starts serving the specified model
46
+ """
47
+ # For Sagemaker, serve and train are the possible commands
48
+ if command == "serve":
49
+ model = find_model_to_serve(model_id=model_id, language=language)
50
+ serve(
51
+ model=model,
52
+ platform=config.platform,
53
+ )
54
+ else:
55
+ raise NotImplementedError("Command not implemented")
56
+
57
+
58
+ __all__ = [
59
+ "build_docker_image",
60
+ "generate_docker_files",
61
+ "setup_container_env",
62
+ "format_image_tag",
63
+ "format_docker_image_name",
64
+ "validate_docker_image_name",
65
+ "validate_image_tag",
66
+ ]
@@ -0,0 +1,27 @@
1
+ import dataclasses
2
+ from uuid import uuid4
3
+
4
+ from endpoints import Platform
5
+ from endpoints.core import ModelInfo
6
+ from endpoints.settings import DEFAULT_JOHNSNOWLABS_VERSION
7
+
8
+
9
+ @dataclasses.dataclass
10
+ class CommonParams:
11
+ model: ModelInfo
12
+ johnsnowlabs_version: str = DEFAULT_JOHNSNOWLABS_VERSION
13
+ no_license: bool = False
14
+ store_model: bool = False
15
+ language: str = "en"
16
+ platform: Platform = Platform.SAGEMAKER
17
+
18
+
19
+ @dataclasses.dataclass(init=False)
20
+ class GenerateDockerFilesRequest(CommonParams):
21
+ output_dir: str = f"/tmp/{uuid4()}"
22
+
23
+ def __init__(self, **kwargs):
24
+ names = set([f.name for f in dataclasses.fields(self)])
25
+ for k, v in kwargs.items():
26
+ if k in names and v is not None:
27
+ setattr(self, k, v)