def setup_page(): """ Setup labeling config """ input_values = {} project = g.project input_args = current_app.label_studio.input_args g.project.description = project.get_config(project.name, input_args).get( 'description', 'Untitled') # evaluate all projects for this user: user_projects + shared_projects if project.config.get("show_project_links_in_multisession", True) and hasattr(g, 'user'): user = g.user project_ids = g.project.get_user_projects(user, input_args.root_dir) # own projects project_names = [os.path.join(user, uuid) for uuid in project_ids] project_desc = [ Project.get_config(name, input_args).get('description', 'Untitled') for name in project_names ] own_projects = dict(zip(project_ids, project_desc)) # shared projects shared_projects = {} for uuid in session.get('shared_projects', []): tmp_user = Project.get_user_by_project(uuid, input_args.root_dir) project_name = os.path.join(tmp_user, uuid) project_desc = Project.get_config(project_name, input_args).get( 'description', 'Untitled') shared_projects[uuid] = project_desc else: own_projects, shared_projects = {}, {} # this is useful for the transfer to playground templates template_mode = request.args.get('template_mode') page = 'includes/setup_templates.html' if template_mode else 'setup.html' templates = get_config_templates(g.project.config) return flask.render_template( page, config=g.project.config, project=g.project, label_config_full=g.project.label_config_full, templates=templates, input_values=input_values, multi_session=input_args.command == 'start-multi-session', own_projects=own_projects, shared_projects=shared_projects, template_mode=template_mode, serialized_project=g.project.serialize())
def setup_page(): """ Setup label config """ input_values = {} project = g.project g.project.description = project.get_config(project.name, input_args).get( 'description', 'Untitled') # evaluate all projects for this user: user_projects + shared_projects if project.config.get("show_project_links_in_multisession", True) and hasattr(g, 'user'): user = g.user project_ids = g.project.get_user_projects(user, input_args.root_dir) # own projects project_names = [os.path.join(user, uuid) for uuid in project_ids] project_desc = [ Project.get_config(name, input_args).get('description', 'Untitled') for name in project_names ] own_projects = dict(zip(project_ids, project_desc)) # shared projects shared_projects = {} for uuid in session.get('shared_projects', []): tmp_user = Project.get_user_by_project(uuid, input_args.root_dir) project_name = os.path.join(tmp_user, uuid) project_desc = Project.get_config(project_name, input_args).get( 'description', 'Untitled') shared_projects[uuid] = project_desc else: own_projects, shared_projects = {}, {} templates = get_config_templates(g.project.config) return flask.render_template( 'setup.html', config=g.project.config, project=g.project, label_config_full=g.project.label_config_full, templates=templates, input_values=input_values, multi_session=input_args.command == 'start-multi-session', own_projects=own_projects, shared_projects=shared_projects)
def main(): import threading import webbrowser 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) 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=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, port=input_args.port, debug=input_args.debug)
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)
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)
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)
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)
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)