Hydrospheredata / hydro-serving-python

Python runtime for the Hydrosphere.io project.

Home Page:http://docs.hydrosphere.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hydro-serving-python

Python runtime for Hydrosphere Serving. Provides a GRPC API for Python scripts.

Supported versions are: python-3.7 python-3.8

Build commands

  • make test
  • 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:

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:

    return {"income": TensorProto(int_val=[int(predicted)],
                                  dtype=DT_INT32,
                                  tensor_shape=TensorShapeProto())}

About

Python runtime for the Hydrosphere.io project.

http://docs.hydrosphere.io

License:Apache License 2.0


Languages

Language:Python 49.7%Language:Groovy 39.2%Language:Dockerfile 8.6%Language:Makefile 2.1%Language:Shell 0.4%