Example #1
0
    def reload(self):
        self.tasks = None
        self.derived_input_schema = []
        self.derived_output_schema = {
            'from_name_to_name_type': set(),
            'labels': defaultdict(set)
        }

        self._init()

        self.label_config_full = config_comments_free(
            open(self.config['label_config']).read())
        self.label_config_line = config_line_stripped(self.label_config_full)

        if self.analytics is None:
            self.analytics = Analytics(
                self.label_config_line,
                self.config.get('collect_analytics', True), self.name)
        else:
            self.analytics.update_info(
                self.label_config_line,
                self.config.get('collect_analytics', True), self.name)

        # configure project
        self.project_obj = ProjectObj(label_config=self.label_config_line,
                                      label_config_full=self.label_config_full)

        # configure machine learning backend
        if self.ml_backend is None:
            ml_backend_params = self.config.get('ml_backend')
            if ml_backend_params:
                ml_backend = MLBackend.from_params(ml_backend_params)
                self.project_obj.connect(ml_backend)

        self.converter = Converter(self.label_config_full)
Example #2
0
def api_render_label_studio():
    """ Label studio frontend rendering for iframe
    """
    # get args
    project = project_get_or_create()

    config = request.args.get('config', request.form.get('config', ''))
    config = unquote(config)
    if not config:
        return make_response('No config in POST',
                             status.HTTP_417_EXPECTATION_FAILED)

    # prepare example
    task_data = generate_sample_task_without_check(config,
                                                   mode='editor_preview')
    example_task_data = {
        'id': 1764,
        'data': task_data,
        'project': project.id,
        'created_at': '2019-02-06T14:06:42.000420Z',
        'updated_at': '2019-02-06T14:06:42.000420Z'
    }

    # prepare context for html
    config_line = config_line_stripped(config)
    response = {
        'label_config_line': config_line,
        'task_ser': example_task_data
    }
    response.update(find_editor_files())

    project.analytics.send(getframeinfo(currentframe()).function)
    return flask.render_template('render_ls.html', **response)
Example #3
0
def api_render_label_studio():
    """ Label studio frontend rendering for iframe
    """
    config = request.args.get('config', request.form.get('config', ''))
    config = unquote(config)
    if not config:
        return make_response('No config in POST',
                             status.HTTP_417_EXPECTATION_FAILED)

    task_data, completions, predictions = get_sample_task(config)

    example_task_data = {
        'id': 42,
        'data': task_data,
        'completions': completions,
        'predictions': predictions,
        'project': g.project.id,
        'created_at': '2019-02-06T14:06:42.000420Z',
        'updated_at': '2019-02-06T14:06:42.000420Z'
    }

    # prepare context for html
    config_line = config_line_stripped(config)
    response = {
        'label_config_line': config_line,
        'task_ser': example_task_data
    }
    response.update(find_editor_files())

    return flask.render_template('render_ls.html', **response)
Example #4
0
def api_render_label_studio():
    """Label studio frontend rendering for iframe"""
    config = request.args.get("config", request.form.get("config", ""))
    config = unquote(config)
    if not config:
        return make_response("No config in POST",
                             status.HTTP_417_EXPECTATION_FAILED)

    task_data, completions, predictions = get_sample_task(config)

    example_task_data = {
        "id": 42,
        "data": task_data,
        "completions": completions,
        "predictions": predictions,
        "project": g.project.id,
        "created_at": "2019-02-06T14:06:42.000420Z",
        "updated_at": "2019-02-06T14:06:42.000420Z",
    }

    # prepare context for html
    config_line = config_line_stripped(config)
    response = {
        "label_config_line": config_line,
        "task_ser": example_task_data
    }
    response.update(find_editor_files())

    return flask.render_template("render_ls.html", **response)
Example #5
0
 def load_label_config(self):
     with open(self.label_config_path, encoding='utf8') as f:
         self.label_config_full = config_comments_free(f.read())
     self.label_config_line = config_line_stripped(self.label_config_full)
     self.parsed_label_config = parse_config(self.label_config_line)
     self.config_input_tags = self.get_config_input_tags(
         self.label_config_line)
Example #6
0
def reload_config(prompt_inputs=False, force=False):
    global c
    global label_config_line
    global analytics
    global ml_backend
    global project
    global config_path

    # Read config from config.json & input arguments
    c = json.load(open(config_path))
    c['port'] = input_args.port if input_args.port else c['port']
    c['label_config'] = input_args.label_config if input_args.label_config else c[
        'label_config']
    c['input_path'] = input_args.input_path if input_args.input_path else c[
        'input_path']
    c['output_dir'] = input_args.output_dir if input_args.output_dir else c[
        'output_dir']
    c['debug'] = input_args.debug if input_args.debug is not None else c[
        'debug']

    # If specified, prompt user in console about specific inputs
    if prompt_inputs:
        iprompt = LabelStudioConfigPrompt(c)
        c['input_data'] = iprompt.ask_input_path()
        c['output_dir'] = iprompt.ask_output_dir()
        c['label_config'] = iprompt.ask_label_config()

    # Initialize DBs
    db.re_init(c)

    label_config_full = config_comments_free(open(c['label_config']).read())
    label_config_line = config_line_stripped(label_config_full)
    if analytics is None:
        analytics = Analytics(label_config_line,
                              c.get('collect_analytics', True))
    else:
        analytics.update_info(label_config_line,
                              c.get('collect_analytics', True))
    # configure project
    if project is None or force:
        project = Project(label_config=label_config_line,
                          label_config_full=label_config_full)
    # configure machine learning backend
    if ml_backend is None or force:
        ml_backend_params = c.get('ml_backend')
        if ml_backend_params:
            ml_backend = MLBackend.from_params(ml_backend_params)
            project.connect(ml_backend)

    return True
Example #7
0
def api_render_label_studio():
    """ Label studio frontend rendering for iframe
    """
    global c
    global label_config_line

    # reload config at each page reload (for fast changing of config/input_path/output_path)
    reload_config()

    # get args
    full_editor = request.args.get('full_editor', False)
    config = request.args.get('config', request.form.get('config', ''))
    config = unquote(config)
    if not config:
        return make_response('No config in POST',
                             status.HTTP_417_EXPECTATION_FAILED)

    # prepare example
    examples = data_examples(mode='editor_preview')
    task_data = {
        data_key: examples.get(data_type, '')
        for data_key, data_type in Project.extract_data_types(config).items()
    }
    example_task_data = {
        'id': 1764,
        'data': task_data,
        'project': DEFAULT_PROJECT_ID,
        'created_at': '2019-02-06T14:06:42.000420Z',
        'updated_at': '2019-02-06T14:06:42.000420Z'
    }

    # prepare context for html
    config_line = config_line_stripped(config)
    response = {
        'label_config_line': config_line,
        'task_ser': example_task_data
    }
    response.update(find_editor_files())
    analytics.send(getframeinfo(currentframe()).function)
    return flask.render_template('render_ls.html', **response)
Example #8
0
 def load_label_config(self):
     self.label_config_full = config_comments_free(
         open(self.config["label_config"], encoding="utf8").read())
     self.label_config_line = config_line_stripped(self.label_config_full)
     self.parsed_label_config = parse_config(self.label_config_line)
     self.input_data_tags = self.get_input_data_tags(self.label_config_line)
Example #9
0
 def load_label_config(self):
     self.label_config_full = config_comments_free(
         open(self.config['label_config']).read())
     self.label_config_line = config_line_stripped(self.label_config_full)
     self.input_data_tags = self.get_input_data_tags(self.label_config_line)