#!/usr/bin/env python

import argparse
import sys
import netron
import os

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Viewer for neural network models.')
    parser.add_argument('file', metavar='MODEL_FILE', help='model file to serve', nargs='?', default=None)
    parser.add_argument('-v', '--verbose', help='log details to console', action='store_true')
    parser.add_argument('--port', help='port to serve (default: 8080)', type=int, default=8080)
    parser.add_argument('--host', help='host to serve (default: localhost)', default='localhost')
    parser.add_argument('--browse', help='launch web browser', action='store_true')
    args = parser.parse_args()
    if args.file and not os.path.exists(args.file):
        print("Model file '" + args.file + "' does not exist.")
        sys.exit(2)
    netron.serve_file(args.file, verbose=args.verbose, browse=args.browse, port=args.port, host=args.host)
    sys.exit(0)
