def test_python_script_prediction():
    work_dir = os.path.abspath(".")

    python_config = PythonConfig(
        python_path=default_python_path(work_dir),
        python_code_path=os.path.join(work_dir, "simple.py"),
        python_inputs={"first": "NDARRAY"},
        python_outputs={"second": "NDARRAY"},
    )

    step = PythonStep().step(python_config)
    server = Server(steps=step, serving_config=ServingConfig())
    _, port, started = server.start()

    assert started
    assert is_port_in_use(port)

    client = Client(port=port)

    try:
        input_array = np.load("../data/input-0.npy")
        predicted = client.predict(input_array)
        print(predicted)
        server.stop()
    except Exception as e:
        print(e)
        server.stop()
def test_python_script_prediction():
    port = 1337
    serving_config = ServingConfig(http_port=port)
    work_dir = os.path.abspath(".")

    python_config = PythonConfig(
        python_path=default_python_path(work_dir),
        python_code_path=os.path.join(work_dir, "simple.py"),
        python_inputs={"first": "NDARRAY"},
        python_outputs={"second": "NDARRAY"},
    )

    step = PythonStep().step(python_config)
    server = Server(steps=step, serving_config=serving_config)
    server.start()

    client = Client(port=port)

    if is_port_in_use(port):
        input_array = np.load("../data/input-0.npy")
        predicted = client.predict(input_array)
        print(predicted)
        server.stop()
    else:
        server.stop()
        raise Exception("Server not running on specified port")
Example #3
0
import cv2
import os
from konduit import *
from konduit.server import Server
from konduit.utils import default_python_path

# Set the working directory to this folder and register
# the "detect_image.py" script as code to be executed by konduit.
work_dir = os.path.abspath(".")
python_config = PythonConfig(
    python_path=default_python_path(work_dir),
    python_code_path=os.path.join(work_dir, "detect_image.py"),
    python_inputs={"image": "NDARRAY"},
    python_outputs={"num_boxes": "NDARRAY"},
)

# Configure a Python pipeline step for your Python code. Internally, konduit will take numpy arrays as input and
# return data in JSON format. Note that the Python variable 'image' and the Konduit step name 'image_data' are separate
# things here.
step_input_name = "image_data"
python_pipeline_step = PythonStep().step(python_config,
                                         input_name=step_input_name)
serving_config = ServingConfig(http_port=1337, output_data_format="JSON")

# Start a konduit server and wait for it to start
server = Server(serving_config=serving_config, steps=[python_pipeline_step])
server.start()

client = Client(port="1337", timeout=30)

encoded_image = cv2.cvtColor(