How to use the runway.model.RunwayModel function in runway

To help you get started, we’ve selected a few runway examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github runwayml / model-sdk / tests / test_model.py View on Github external
def test_meta(capsys):

    rw = RunwayModel()

    @rw.setup(options={'initialization_array': array(item_type=text)})
    def setup(opts):
        pass

    kwargs_1 = {
        'inputs': {
            'image': image,
            'vector': vector(length=5)
        },
        'outputs': {
            'label': text
        }
    }
    @rw.command('command_1', **kwargs_1)
    def command_1(opts):
github runwayml / model-sdk / tests / test_model.py View on Github external
def test_post_command_form_encoding():

    rw = RunwayModel()

    @rw.command('times_two', inputs={ 'input': number }, outputs={ 'output': number })
    def times_two(model, args):
        return args['input'] * 2

    rw.run(debug=True)

    client = get_test_client(rw)

    content_type='application/x-www-form-urlencoded'
    response = client.post('/times_two', data='input=5', content_type=content_type)
    assert response.is_json
    assert response.status_code == 400

    expect = { 'error': 'The body of all POST requests must contain JSON' }
    assert json.loads(response.data) == expect
github runwayml / model-sdk / tests / test_model.py View on Github external
def test_model_healthcheck():
    rw = RunwayModel()
    rw.run(debug=True)
    client = get_test_client(rw)
    response = client.get('/healthcheck')
    assert response.is_json
    assert response.json == { 'status': 'RUNNING' }
github runwayml / model-sdk / tests / test_model.py View on Github external
def test_post_command_json_no_mime_type():

    rw = RunwayModel()

    @rw.command('times_two', inputs={ 'input': number }, outputs={ 'output': number })
    def times_two(model, args):
        return args['input'] * 2

    rw.run(debug=True)

    client = get_test_client(rw)
    response = client.post('/times_two', data='{ "input": 5 }')
    assert response.is_json
    assert json.loads(response.data) == { 'output': 10 }
github runwayml / model-sdk / tests / test_model.py View on Github external
def test_setup_error_setup_no_args():

    rw = RunwayModel()

    @rw.setup
    def setup():
        raise Exception('test exception, thrown from inside a wrapped setup() function')

    with pytest.raises(SystemExit):
        with pytest.raises(SetupError):
            rw.run(debug=True)
github runwayml / model-sdk / tests / test_model.py View on Github external
def test_millis_since_run_increases_over_time():

    rw = RunwayModel()
    client = get_test_client(rw)
    rw.run(debug=True)

    last_time = get_manifest(client)['millisRunning']
    assert type(last_time) == int
    for i in range(3):
        sleep(0.01)
        millis_running = get_manifest(client)['millisRunning']
        assert millis_running > last_time
        last_time = millis_running
github runwayml / model-sdk / tests / test_model.py View on Github external
def test_model_setup_no_arguments():

    # use a dict to share state across function scopes. This makes up for the
    # fact that Python 2.x doesn't have support for the 'nonlocal' keyword.
    closure = dict(setup_ran = False)

    rw = RunwayModel()

    # Any reason @rw.setup called with no arguments requires the decorated
    # function NOT to have arguments? This seems a bit like an idiosyncracy to
    # me. Why not keep the function signature of the wrapped function the
    # same regardless and simply pass an empty dict in the case of no options?
    @rw.setup
    def setup():
        closure['setup_ran'] = True

    rw.run(debug=True)
    assert closure['setup_ran'] == True
github runwayml / model-sdk / tests / test_model.py View on Github external
def test_inference_async_failure():
    rw = RunwayModel()

    @rw.command('test_command', inputs={ 'input': number }, outputs = { 'output': text })
    def test_command(model, inputs):
        raise Exception

    try:
        os.environ['RW_NO_SERVE'] = '0'
        proc = Process(target=rw.run)
        proc.start()

        time.sleep(0.5)
        ws = get_test_ws_client(rw)

        ws.send(create_ws_message('submit', dict(command='test_command', inputData={'input': 5})))

        response = json.loads(ws.recv())
github runwayml / model-sdk / tests / test_model.py View on Github external
def test_405_method_not_allowed():

    rw = RunwayModel()

    @rw.setup(options={'input': text})
    def setup(opts):
        pass

    rw.run(debug=True)

    client = get_test_client(rw)
    response = client.put('/setup', json= { 'input': 'test input'})

    assert response.is_json
    assert response.status_code == 405
    assert response.json == { 'error': 'Method not allowed.' }
github runwayml / model-sdk / runway / __init__.py View on Github external
from .model import RunwayModel
from .data_types import *
import sys

__version__ = '0.1.0'

__defaultmodel__ = RunwayModel()
setup = __defaultmodel__.setup
command = __defaultmodel__.command
run = __defaultmodel__.run