Example #1
0
def cli_generate_raml(settings, datasource_name):
    """Generate and print RAML template from DATASOURCE_NAME.

    The datasource named DATASOURCE_NAME in the config will be used
    to create the API's query parameters (from columns), types, and examples.
    """
    print(generate_raml(settings.config, data_source_name=datasource_name))
Example #2
0
def test_generate_raml():
    df = pd.DataFrame({"c1": [1, 2, 3], "c2": ["a", "b", "c"]})

    out = api.generate_raml(minimal_config,
                            data_frame=df,
                            resource_name="findme")

    # Should be parseable
    parsed_raml(out)
    assert "/findme" in out
Example #3
0
def main():
    fullCmdArguments = sys.argv
    argumentList = fullCmdArguments[1:]
    unixOptions = "hvtrpac:l:g:"
    gnuOptions = [
        "help",
        "version",
        "train",
        "retest",
        "predict",
        "api",
        "config=",
        "logconfig=",
        "generateraml=",
    ]
    try:
        arguments, values = getopt.getopt(argumentList, unixOptions,
                                          gnuOptions)
    except getopt.error as err:
        # output error, and return with an error code
        print(str(err), file=sys.stderr)
        sys.exit(2)
    # evaluate given options
    cmd = None
    conf = None
    logger = None
    raml_ds = None
    for currentArgument, currentValue in arguments:
        if currentArgument in ("-c", "--config"):
            conf = lp.get_validated_config(currentValue)
        elif currentArgument in ("-l", "--logconfig"):
            logger = logutil.init_logging(currentValue)
        elif currentArgument in ("-t", "--train"):
            cmd = "train"
        elif currentArgument in ("-r", "--retest"):
            cmd = "retest"
        elif currentArgument in ("-p", "--predict"):
            cmd = "predict"
        elif currentArgument in ("-a", "--api"):
            cmd = "api"
        elif currentArgument in ("-g", "--generateraml"):
            cmd = "genraml"
            raml_ds = currentValue
        elif currentArgument in ("-h", "--help"):
            print(HELP_STRING, file=sys.stderr)
            exit(0)
        elif currentArgument in ("-v", "--version"):
            print("ML Launchpad version " + lp.__version__, file=sys.stderr)
            exit(0)

    if cmd is None:
        print("\nNo command given.", file=sys.stderr)
        print(HELP_STRING, file=sys.stderr)
        exit(1)

    logger = logger or logutil.init_logging()
    conf = conf or lp.get_validated_config()
    if cmd == "train":
        model, metrics = lp.train_model(conf)
    elif cmd == "retest":
        _ = lp.retest(conf)
    elif cmd == "predict":
        # TODO decide: get batch args from config? Don't support arguments?
        _ = lp.predict(conf, arg_dict={})
    elif cmd == "api":
        logger.warning(
            "Starting Flask debug server. In production, please "
            "use a WSGI server, e.g. "
            "'export LAUNCHPAD_CFG=addition_cfg.yml'"
            "'gunicorn -w 4 -b 127.0.0.1:5000 mllaunchpad.wsgi:application'")
        app = Flask(__name__)
        ModelApi(conf, app)
        app.run(debug=True)
    elif cmd == "genraml":
        print(generate_raml(conf, data_source_name=raml_ds))