Skip to content
🏌️‍♂️Model Template: Basic template structure of a Runway model.
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Updates ahead of the public SDK launch. Apr 17, 2019
LICENSE Create LICENSE Apr 17, 2019 Link Model Importing tutorial. Apr 22, 2019 s/3.7/3.6/ Apr 17, 2019
requirements.txt Updates ahead of the public SDK launch. Apr 17, 2019
runway.yml Fix typo in runway.yml May 17, 2019 Add parameters to image output. Apr 18, 2019

Runway Model Template

This repository contains an example model template that can be used as reference when porting machine learning models to Runway. This template uses the Runway Model SDK Python module, check out the module documentation for more info.

See the Importing Models into Runway tutorial for a walk-through illustrating how to port a model to Runway.

Each Runway model consists of two special files:

  • A Python script that imports the runway module (SDK) and exposes its interface via one or more @runway.command() functions. This file is used as the entrypoint to your model.
  • runway.yml: A configuration file that describes dependencies and build steps needed to build and run the model.

The Entrypoint File

The entrypoint file is the file the Runway app will use to query the model. This file can have any name you want, but we recommend calling it

Basic Structure

All Runway models expose a standard interface that allows the Runway desktop application to interact with them over HTTP. This is accomplished using three functions: @runway.setup(), @runway.command(), and

import runway
from runway.data_types import number, text, image
from example_model import ExampleModel

# Setup the model, initialize weights, set the configs of the model, etc.
# Every model will have a different set of configurations and requirements.
# Check to see a complete list of
# supported configs. The setup function should return the model ready to be
# used.
setup_options = {
    'truncation': number(min=5, max=100, step=1, default=10),
    'seed': number(min=0, max=1000000)
def setup(opts):
    msg = '[SETUP] Run with options: seed = {}, truncation = {}'
    print(msg.format(opts['seed'], opts['truncation']))
    model = ExampleModel(opts)
    return model

# Every model needs to have at least one command. Every command allows to send
# inputs and process outputs. To see a complete list of supported inputs and
# outputs data types:
                inputs={ 'caption': text() },
                outputs={ 'image': image(width=512, height=512) })
def generate(model, args):
    print('[GENERATE] Ran with caption value "{}"'.format(args['caption']))
    # Generate a PIL or Numpy image based on the input caption, and return it
    output_image = model.run_on_input(args['caption'])
    return {
        'image': output_image

if __name__ == '__main__':
    # run the model server using the default network interface and ports,
    # displayed here for convenience'', port=8000)

See the file for the simple ExampleModel class used in the example above.

The runway.yml Config File

Each Runway model must have a runway.yml configuration file in its root directory. This file defines the steps needed to build and run your model for use with Runway. This file is written in YAML, a human-readable superset of JSON. Below is an example of a runway.yml file. This example file illustrates how you can provision your model’s environment.

version: 0.1
python: 3.6
entrypoint: python
cuda: 9.2
framework: tensorflow
        - image_dataset/*
    - pip install runway-python==0.1.0
    - pip install -r requirements.txt

Testing your Model

While you're developing your model it's useful to run and test it locally.

## Optionally create and activate a Python 3 virtual environment
# virtualenv -p python3 venv && source venv/bin/activate

# Install the Runway Model SDK (`pip install runway-python`) and the Pillow
# image library, used in this example.
pip install -r requirements.txt

# Run the entrypoint script

You should see an output similar to this, indicating your model is running.

Setting up model...
[SETUP] Ran with options: seed = 0, truncation = 10
Starting model server at

You can test your model once its running by POSTing a caption argument to the the /generate command.

curl \
    -H "content-type: application/json" \
    -d '{ "caption": "red" }' \

You should receive a JSON object back, containing a cryptic base64 encoded URI string that represents a red image:

{"image": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQ..."}
You can’t perform that action at this time.