-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to the latest version of hydrosdk (#6)
* Update to the latest version of hydrosdk (2.3.2) to fix automatic numpy conversion * Allow returning TensorProto as well as Numpy arrays/scalars in a dict from a runtime executable * add usage example to the README file
- Loading branch information
1 parent
14e0482
commit e838953
Showing
4 changed files
with
48 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,44 @@ | ||
# hydro-serving-python | ||
Python runtime for [Hydrosphere Serving](https://github.com/Hydrospheredata/hydro-serving). | ||
Provides GRPC API for a Python scripts. | ||
Supported versions are: python-3.4 python-3.5 python-3.6 | ||
Provides a GRPC API for Python scripts. | ||
|
||
Supported versions are: python-3.6 python-3.7 python-3.8 | ||
|
||
## Build commands | ||
- `make test` | ||
- `make python` - build docker runtime with python:latest-alpine base image | ||
- `make python-${VERSION}` - build docker runtime with python:${VERSION}-alpine base image | ||
- `make clean` - clean repository from temp files | ||
|
||
## Usage | ||
|
||
This runtime uses `src/func_main.py` script as an entry point. | ||
You may create any arbitrary Python application within, | ||
just keep in mind that the entry point of your script has to be located in | ||
`src/func_main.py`. | ||
|
||
|
||
Example of a `func_main.py`: | ||
|
||
```python | ||
import pandas as pd | ||
from joblib import load | ||
|
||
# Load an ML model during runtime initialisation | ||
clf = load('/model/files/classification_model.joblib') | ||
|
||
# This function is called on each request | ||
# Input and output must comply with your model's signature | ||
def predict(**kwargs): | ||
# kwargs is a dict with Numpy arrays or scalars you've specified in a signature | ||
x = pd.DataFrame.from_dict({"request": kwargs}).T | ||
predicted = clf.predict(x) | ||
return {"income": int(predicted)} | ||
``` | ||
|
||
or if you wish to work with proto messages: | ||
```python | ||
return {"income": TensorProto(int_val=[int(predicted)], | ||
dtype=DT_INT32, | ||
tensor_shape=TensorShapeProto())} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
grpcio~=1.19 | ||
hydro-serving-grpc==2.1.0rc1 | ||
hydro-serving-grpc==2.2.1 | ||
docker~=3.0 | ||
pytest | ||
hydrosdk==2.3.1 | ||
|
||
hydrosdk==2.3.2 | ||
pandas~=1.0.3 | ||
numpy~=1.18.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.3.1 | ||
2.3.2 |