Example #1
0
def main():
    parser = argparse.ArgumentParser()
    arg = parser.add_argument
    arg("model_root", type=Path)
    arg("--port", type=int, default=8000)
    arg("--host", default="localhost")
    args = parser.parse_args()

    template_root = Path(lm_web_ui.__file__).parent / "templates"
    aiohttp_jinja2.setup(app,
                         loader=jinja2.FileSystemLoader(str(template_root)))
    app["model"] = ModelWrapper.load(args.model_root)
    app.add_routes([web.get("/", index)])
    web.run_app(app, host=args.host, port=args.port)
Example #2
0
def main():
    parser = argparse.ArgumentParser()
    arg = parser.add_argument
    arg('model_root', type=Path)
    arg('--port', type=int, default=8000)
    arg('--host', default='localhost')
    args = parser.parse_args()

    template_root = Path(lm_web_ui.__file__).parent / 'templates'
    aiohttp_jinja2.setup(app,
                         loader=jinja2.FileSystemLoader(str(template_root)))
    app['model'] = ModelWrapper.load(args.model_root)
    app['model_params'] = (args.model_root / 'params.json').read_text()
    app.add_routes([web.get('/', index)])
    app.add_routes([web.get('/about', about)])
    web.run_app(app, host=args.host, port=args.port)
Example #3
0
def load_model() -> ModelWrapper:
    logging.info(f'Loading model s3://{MODEL_S3_BUCKET}/{MODEL_S3_PREFIX}')
    s3 = boto3.resource('s3')
    model_path = Path('/tmp/model/')
    model_path.mkdir(exist_ok=True)
    files = ['params.json', 'sp.model', 'model.pt']
    for f in files:
        target = model_path / f
        if not target.exists():
            logging.info('Downloading {f}')
            s3.Bucket(MODEL_S3_BUCKET).download_file(MODEL_S3_PREFIX + f,
                                                     str(target))
    logging.info('Initializing model')
    model = ModelWrapper.load(model_path)
    logging.info('Cleaning up temporary storage')
    shutil.rmtree(model_path)
    logging.info('Model loaded, vocab')
    return model
Example #4
0
def load_model() -> ModelWrapper:
    logging.info(
        f"Loading model s3://{MODEL_S3_BUCKET}/{MODEL_S3_PREFIX}"
    )
    s3 = boto3.resource("s3")
    model_path = Path("/tmp/model/")
    model_path.mkdir(exist_ok=True)
    files = ["params.json", "sp.model", "model.pt"]
    for f in files:
        target = model_path / f
        if not target.exists():
            logging.info("Downloading {f}")
            s3.Bucket(MODEL_S3_BUCKET).download_file(
                MODEL_S3_PREFIX + f, str(target)
            )
    logging.info("Initializing model")
    model = ModelWrapper.load(model_path)
    logging.info("Cleaning up temporary storage")
    shutil.rmtree(model_path)
    logging.info("Model loaded, vocab")
    return model
Example #5
0
def model_fn(model_dir):
    return ModelWrapper.load(Path(model_dir))