Exemple #1
0
def main():
    import threading
    import webbrowser

    global input_args

    input_args = parse_input_args()

    import label_studio.utils.functions
    label_studio.utils.functions.HOSTNAME = 'http://localhost:' + str(input_args.port)

    # On `init` command, create directory args.project_name with initial project state and exit
    if input_args.command == 'init':
        Project.create_project_dir(input_args.project_name, input_args)
        return

    elif input_args.command == 'start':

        # If `start --init` option is specified, do the same as with `init` command, but continue to run app
        if input_args.init:
            Project.create_project_dir(input_args.project_name, input_args)

    # On `start` command, launch browser if --no-browser is not specified and start label studio server
    if input_args.command == 'start':
        if not input_args.no_browser:
            browser_url = 'http://127.0.0.1:' + str(input_args.port) + '/welcome'
            threading.Timer(2.5, lambda: webbrowser.open(browser_url)).start()
            print('Start browser at URL: ' + browser_url)

        app.run(host='0.0.0.0', port=input_args.port, debug=input_args.debug)

    # On `start-multi-session` command, server creates one project per each browser sessions
    elif input_args.command == 'start-multi-session':
        app.run(host='0.0.0.0', port=input_args.port, debug=input_args.debug)
Exemple #2
0
def main():
    import threading
    import webbrowser

    global input_args

    app.jinja_env.filters['str2datetime'] = str2datetime

    input_args = parse_input_args()

    #####
    app.wsgi_app = WvProxyFix(app.wsgi_app, int(input_args.port) - 9000)
    #####

    # setup logging level
    if input_args.log_level:
        logging.root.setLevel(input_args.log_level)

    import label_studio.utils.functions
    label_studio.utils.functions.HOSTNAME = 'http://localhost:' + str(
        input_args.port)

    # On `init` command, create directory args.project_name with initial project state and exit
    if input_args.command == 'init':
        Project.create_project_dir(input_args.project_name, input_args)
        return

    elif input_args.command == 'start':

        # If `start --init` option is specified, do the same as with `init` command, but continue to run app
        if input_args.init:
            Project.create_project_dir(input_args.project_name, input_args)

        if not os.path.exists(
                Project.get_project_dir(input_args.project_name, input_args)):
            raise FileNotFoundError(
                'Project directory "{pdir}" not found. '
                'Did you miss create it first with `label-studio init {pdir}` ?'
                .format(pdir=Project.get_project_dir(input_args.project_name,
                                                     input_args)))

    # On `start` command, launch browser if --no-browser is not specified and start label studio server
    if input_args.command == 'start':
        if not input_args.no_browser:
            browser_url = label_studio.utils.functions.HOSTNAME + '/welcome'
            threading.Timer(2.5, lambda: webbrowser.open(browser_url)).start()
            print('Start browser at URL: ' + browser_url)

        app.run(host=input_args.host,
                port=input_args.port,
                debug=input_args.debug)

    # On `start-multi-session` command, server creates one project per each browser sessions
    elif input_args.command == 'start-multi-session':
        app.run(host=input_args.host,
                port=input_args.port,
                debug=input_args.debug)
Exemple #3
0
def main():
    global input_args

    app.jinja_env.filters['str2datetime'] = str2datetime

    input_args = parse_input_args()

    # setup logging level
    if input_args.log_level:
        logging.root.setLevel(input_args.log_level)

    # On `init` command, create directory args.project_name with initial project state and exit
    if input_args.command == 'init':
        Project.create_project_dir(input_args.project_name, input_args)
        return

    elif input_args.command == 'start':

        # If `start --init` option is specified, do the same as with `init` command, but continue to run app
        if input_args.init:
            Project.create_project_dir(input_args.project_name, input_args)

        if not os.path.exists(Project.get_project_dir(input_args.project_name, input_args)):
            raise FileNotFoundError(
                'Project directory "{pdir}" not found. '
                'Did you miss create it first with `label-studio init {pdir}` ?'.format(
                    pdir=Project.get_project_dir(input_args.project_name, input_args)))

    # On `start` command, launch browser if --no-browser is not specified and start label studio server
    if input_args.command == 'start':
        import label_studio.utils.functions

        config = Project.get_config(input_args.project_name, input_args)
        host = input_args.host or config.get('host', 'localhost')
        port = input_args.port or config.get('port', 8080)
        label_studio.utils.functions.HOSTNAME = 'http://localhost:' + str(port)

        try:
            start_browser(label_studio.utils.functions.HOSTNAME, input_args.no_browser)
            app.run(host=host, port=port, debug=input_args.debug)
        except OSError as e:
            # address already is in use
            if e.errno == 98:
                new_port = int(port) + 1
                print('\n*** WARNING! ***\n* Port ' + str(port) + ' is in use.\n'
                      '* Try to start at ' + str(new_port) + '\n****************\n')
                label_studio.utils.functions.HOSTNAME = 'http://localhost:' + str(new_port)
                start_browser(label_studio.utils.functions.HOSTNAME, input_args.no_browser)
                app.run(host=host, port=new_port, debug=input_args.debug)
            else:
                raise e

    # On `start-multi-session` command, server creates one project per each browser sessions
    elif input_args.command == 'start-multi-session':
        app.run(host=input_args.host or '0.0.0.0', port=input_args.port or 8080, debug=input_args.debug)
Exemple #4
0
def main():
    """Runs label studio server using given config."""
    global input_args

    input_args = parse_input_args()
    server.input_args = input_args

    # setup logging level
    if input_args.log_level:
        print(f"log level is {input_args.log_level}")
        logging.root.setLevel(input_args.log_level)

    label_studio.utils.functions.HOSTNAME = 'http://localhost:' + str(input_args.port)

    if input_args.command != 'start-multi-session':
        exit("Only multi user session is supported!")
    # Lets start the server
    app.run(host='0.0.0.0', port=input_args.port, debug=input_args.debug)
def main():
    # this will avoid looped imports and will register deprecated endpoints in the blueprint
    import label_studio.deprecated

    input_args = parse_input_args()
    app = create_app(LabelStudioConfig(input_args=input_args))

    # setup logging level
    if input_args.log_level:
        logging.root.setLevel(input_args.log_level)

    # On `init` command, create directory args.project_name with initial project state and exit
    if input_args.command == 'init':
        Project.create_project_dir(input_args.project_name, input_args)
        return

    elif input_args.command == 'start':

        # If `start --init` option is specified, do the same as with `init` command, but continue to run app
        if input_args.init:
            Project.create_project_dir(input_args.project_name, input_args)

        if not os.path.exists(
                Project.get_project_dir(input_args.project_name, input_args)):
            raise FileNotFoundError(
                'Project directory "{pdir}" not found. '
                'Did you miss create it first with `label-studio init {pdir}` ?'
                .format(pdir=Project.get_project_dir(input_args.project_name,
                                                     input_args)))

    # On `start` command, launch browser if --no-browser is not specified and start label studio server
    if input_args.command == 'start':
        import label_studio.utils.functions
        import label_studio.utils.auth
        config = Project.get_config(input_args.project_name, input_args)

        # set username and password
        label_studio.utils.auth.USERNAME = input_args.username or \
            config.get('username') or label_studio.utils.auth.USERNAME
        label_studio.utils.auth.PASSWORD = input_args.password or config.get(
            'password', '')

        # set host name
        host = input_args.host or config.get('host', 'localhost')
        port = input_args.port or config.get('port', 8080)
        server_host = 'localhost' if host == 'localhost' else '0.0.0.0'  # web server host

        # ssl certificate and key
        cert_file = input_args.cert_file or config.get('cert')
        key_file = input_args.key_file or config.get('key')
        ssl_context = None
        if cert_file and key_file:
            config['protocol'] = 'https://'
            ssl_context = (cert_file, key_file)

        # check port is busy
        if not input_args.debug and check_port_in_use('localhost', port):
            old_port = port
            port = int(port) + 1
            print('\n*** WARNING! ***\n* Port ' + str(old_port) +
                  ' is in use.\n' + '* Trying to start at ' + str(port) +
                  '\n****************\n')

        # external hostname is used for data import paths, they must be absolute always,
        # otherwise machine learning backends couldn't access them
        set_web_protocol(input_args.protocol
                         or config.get('protocol', 'http://'))
        external_hostname = get_web_protocol() + host.replace(
            '0.0.0.0', 'localhost')
        if host in ['0.0.0.0', 'localhost', '127.0.0.1']:
            external_hostname += ':' + str(port)
        set_external_hostname(external_hostname)

        start_browser('http://localhost:' + str(port), input_args.no_browser)
        if input_args.use_gevent:
            app.debug = input_args.debug
            ssl_args = {
                'keyfile': key_file,
                'certfile': cert_file
            } if ssl_context else {}
            http_server = WSGIServer((server_host, port),
                                     app,
                                     log=app.logger,
                                     **ssl_args)
            http_server.serve_forever()
        else:
            app.run(host=server_host,
                    port=port,
                    debug=input_args.debug,
                    ssl_context=ssl_context)

    # On `start-multi-session` command, server creates one project per each browser sessions
    elif input_args.command == 'start-multi-session':
        server_host = input_args.host or '0.0.0.0'
        port = input_args.port or 8080

        if input_args.use_gevent:
            app.debug = input_args.debug
            http_server = WSGIServer((server_host, port), app, log=app.logger)
            http_server.serve_forever()
        else:
            app.run(host=server_host, port=port, debug=input_args.debug)
Exemple #6
0
def main():
    global input_args

    app.jinja_env.filters['str2datetime'] = str2datetime

    input_args = parse_input_args()

    # setup logging level
    if input_args.log_level:
        logging.root.setLevel(input_args.log_level)

    # On `init` command, create directory args.project_name with initial project state and exit
    if input_args.command == 'init':
        Project.create_project_dir(input_args.project_name, input_args)
        return

    elif input_args.command == 'start':

        # If `start --init` option is specified, do the same as with `init` command, but continue to run app
        if input_args.init:
            Project.create_project_dir(input_args.project_name, input_args)

        if not os.path.exists(
                Project.get_project_dir(input_args.project_name, input_args)):
            raise FileNotFoundError(
                'Project directory "{pdir}" not found. '
                'Did you miss create it first with `label-studio init {pdir}` ?'
                .format(pdir=Project.get_project_dir(input_args.project_name,
                                                     input_args)))

    # On `start` command, launch browser if --no-browser is not specified and start label studio server
    if input_args.command == 'start':
        import label_studio.utils.functions
        import label_studio.utils.auth
        config = Project.get_config(input_args.project_name, input_args)

        # set username and password
        label_studio.utils.auth.USERNAME = input_args.username or \
            config.get('username') or label_studio.utils.auth.USERNAME
        label_studio.utils.auth.PASSWORD = input_args.password or config.get(
            'password', '')

        # set host name
        host = input_args.host or config.get(
            'host', 'localhost')  # name for external links generation
        port = input_args.port or config.get('port', 8080)
        server_host = 'localhost' if host == 'localhost' else '0.0.0.0'  # web server host

        # ssl certificate and key
        cert_file = input_args.cert_file or config.get('cert')
        key_file = input_args.key_file or config.get('key')
        ssl_context = None
        if cert_file and key_file:
            config['protocol'] = 'https://'
            ssl_context = (cert_file, key_file)

        # check port is busy
        if not input_args.debug and check_port_in_use('localhost', port):
            old_port = port
            port = int(port) + 1
            print('\n*** WARNING! ***\n* Port ' + str(old_port) +
                  ' is in use.\n' + '* Trying to start at ' + str(port) +
                  '\n****************\n')

        set_web_protocol(input_args.protocol
                         or config.get('protocol', 'http://'))
        set_full_hostname(get_web_protocol() +
                          host.replace('0.0.0.0', 'localhost') + ':' +
                          str(port))

        start_browser('http://localhost:' + str(port), input_args.no_browser)
        if input_args.use_gevent:
            app.debug = input_args.debug
            ssl_args = {
                'keyfile': key_file,
                'certfile': cert_file
            } if ssl_context else {}
            http_server = WSGIServer((server_host, port),
                                     app,
                                     log=app.logger,
                                     **ssl_args)
            http_server.serve_forever()
        else:
            app.run(host=server_host,
                    port=port,
                    debug=input_args.debug,
                    ssl_context=ssl_context)

    # On `start-multi-session` command, server creates one project per each browser sessions
    elif input_args.command == 'start-multi-session':
        server_host = input_args.host or '0.0.0.0'
        port = input_args.port or 8080

        if input_args.use_gevent:
            app.debug = input_args.debug
            http_server = WSGIServer((server_host, port), app, log=app.logger)
            http_server.serve_forever()
        else:
            app.run(host=server_host, port=port, debug=input_args.debug)
Exemple #7
0
def main():
    global input_args

    app.jinja_env.filters['str2datetime'] = str2datetime

    input_args = parse_input_args()

    # setup logging level
    if input_args.log_level:
        logging.root.setLevel(input_args.log_level)

    # On `init` command, create directory args.project_name with initial project state and exit
    if input_args.command == 'init':
        Project.create_project_dir(input_args.project_name, input_args)
        return

    elif input_args.command == 'start':

        # If `start --init` option is specified, do the same as with `init` command, but continue to run app
        if input_args.init:
            Project.create_project_dir(input_args.project_name, input_args)

        if not os.path.exists(
                Project.get_project_dir(input_args.project_name, input_args)):
            raise FileNotFoundError(
                'Project directory "{pdir}" not found. '
                'Did you miss create it first with `label-studio init {pdir}` ?'
                .format(pdir=Project.get_project_dir(input_args.project_name,
                                                     input_args)))

    # On `start` command, launch browser if --no-browser is not specified and start label studio server
    if input_args.command == 'start':
        import label_studio.utils.functions
        import label_studio.utils.auth
        config = Project.get_config(input_args.project_name, input_args)

        # set username and password
        label_studio.utils.auth.USERNAME = input_args.username or \
            config.get('username') or label_studio.utils.auth.USERNAME
        label_studio.utils.auth.PASSWORD = input_args.password or config.get(
            'password', '')

        # set host name
        host = input_args.host or config.get('host', 'localhost')
        port = input_args.port or config.get('port', 8080)

        if not input_args.debug and check_port_in_use('localhost', port):
            old_port = port
            port = int(port) + 1
            print('\n*** WARNING! ***\n* Port ' + str(old_port) +
                  ' is in use.\n' + '* Trying to start at ' + str(port) +
                  '\n****************\n')

        set_web_protocol(config.get('protocol', 'http://'))
        set_full_hostname(get_web_protocol() +
                          host.replace('0.0.0.0', 'localhost') + ':' +
                          str(port))

        start_browser('http://localhost:' + str(port), input_args.no_browser)
        app.run(host=host, port=port, debug=input_args.debug)

    # On `start-multi-session` command, server creates one project per each browser sessions
    elif input_args.command == 'start-multi-session':
        app.run(host=input_args.host or '0.0.0.0',
                port=input_args.port or 8080,
                debug=input_args.debug)
Exemple #8
0
def main():
    # this will avoid looped imports and will register deprecated endpoints in the blueprint
    import label_studio.deprecated

    input_args = parse_input_args()
    app = create_app(LabelStudioConfig(input_args=input_args))

    # setup logging level
    if input_args.log_level:
        logging.root.setLevel(input_args.log_level)

    # On `init` command, create directory args.project_name with initial project state and exit
    if input_args.command == "init":
        Project.create_project_dir(input_args.project_name, input_args)
        return

    elif input_args.command == "start":

        # If `start --init` option is specified, do the same as with `init` command, but continue to run app
        if input_args.init:
            Project.create_project_dir(input_args.project_name, input_args)

        if not os.path.exists(
                Project.get_project_dir(input_args.project_name, input_args)):
            raise FileNotFoundError(
                'Project directory "{pdir}" not found. '
                "Did you miss create it first with `label-studio init {pdir}` ?"
                .format(pdir=Project.get_project_dir(input_args.project_name,
                                                     input_args)))

    # On `start` command, launch browser if --no-browser is not specified and start label studio server
    if input_args.command == "start":
        import label_studio.utils.functions
        import label_studio.utils.auth

        config = Project.get_config(input_args.project_name, input_args)

        # set username and password
        label_studio.utils.auth.USERNAME = (input_args.username
                                            or config.get("username") or
                                            label_studio.utils.auth.USERNAME)
        label_studio.utils.auth.PASSWORD = input_args.password or config.get(
            "password", "")

        # set host name
        host = input_args.host or config.get("host", "localhost")
        port = input_args.port or config.get("port", 8080)
        server_host = ("localhost" if host == "localhost" else "0.0.0.0"
                       )  # web server host

        # ssl certificate and key
        cert_file = input_args.cert_file or config.get("cert")
        key_file = input_args.key_file or config.get("key")
        ssl_context = None
        if cert_file and key_file:
            config["protocol"] = "https://"
            ssl_context = (cert_file, key_file)

        # check port is busy
        if not input_args.debug and check_port_in_use("localhost", port):
            old_port = port
            port = int(port) + 1
            print("\n*** WARNING! ***\n* Port " + str(old_port) +
                  " is in use.\n" + "* Trying to start at " + str(port) +
                  "\n****************\n")

        # external hostname is used for data import paths, they must be absolute always,
        # otherwise machine learning backends couldn't access them
        set_web_protocol(input_args.protocol
                         or config.get("protocol", "http://"))
        external_hostname = get_web_protocol() + host.replace(
            "0.0.0.0", "localhost")
        if host in ["0.0.0.0", "localhost", "127.0.0.1"]:
            external_hostname += ":" + str(port)
        set_external_hostname(external_hostname)

        start_browser("http://localhost:" + str(port), input_args.no_browser)
        if input_args.use_gevent:
            app.debug = input_args.debug
            ssl_args = ({
                "keyfile": key_file,
                "certfile": cert_file
            } if ssl_context else {})
            http_server = WSGIServer((server_host, port),
                                     app,
                                     log=app.logger,
                                     **ssl_args)
            http_server.serve_forever()
        else:
            app.run(
                host=server_host,
                port=port,
                debug=input_args.debug,
                ssl_context=ssl_context,
            )

    # On `start-multi-session` command, server creates one project per each browser sessions
    elif input_args.command == "start-multi-session":
        server_host = input_args.host or "0.0.0.0"
        port = input_args.port or 8080

        if input_args.use_gevent:
            app.debug = input_args.debug
            http_server = WSGIServer((server_host, port), app, log=app.logger)
            http_server.serve_forever()
        else:
            app.run(host=server_host, port=port, debug=input_args.debug)