示例#1
0
def labeling_page():
    """ Label studio frontend: task labeling
    """
    project = project_get_or_create()
    if len(project.tasks) == 0:
        return redirect('/welcome')

    # task data: load task or task with completions if it exists
    task_data = None
    task_id = request.args.get('task_id', None)

    if task_id is not None:
        task_data = project.get_task_with_completions(
            task_id) or project.get_task(task_id)
        if project.ml_backend:
            task_data = deepcopy(task_data)
            task_data['predictions'] = project.ml_backend.make_predictions(
                task_data, project)

    project.analytics.send(getframeinfo(currentframe()).function)
    return flask.render_template('labeling.html',
                                 config=project.config,
                                 label_config_line=project.label_config_line,
                                 task_id=task_id,
                                 task_data=task_data,
                                 **find_editor_files())
示例#2
0
def labeling_page():
    """ Label studio frontend: task labeling
    """
    project = project_get_or_create()
    if project.no_tasks():
        return redirect('/welcome')

    # task data: load task or task with completions if it exists
    task_data = None
    task_id = request.args.get('task_id', None)

    if task_id is not None:
        task_id = int(task_id)
        # Task explore mode
        task_data = project.get_task_with_completions(
            task_id) or project.source_storage.get(task_id)
        task_data = resolve_task_data_uri(task_data)

        if project.ml_backends_connected:
            task_data = project.make_predictions(task_data)

    project.analytics.send(getframeinfo(currentframe()).function)
    return flask.render_template('labeling.html',
                                 project=project,
                                 config=project.config,
                                 label_config_line=project.label_config_line,
                                 task_id=task_id,
                                 task_data=task_data,
                                 **find_editor_files())
示例#3
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)
示例#4
0
def labeling_page():
    """ Label stream for tasks
    """
    if g.project.no_tasks():
        return redirect(url_for('label_studio.welcome_page'))

    # task data: load task or task with completions if it exists
    task_data = None
    task_id = request.args.get('task_id', None)

    if task_id is not None:
        task_id = int(task_id)
        # Task explore mode
        task_data = g.project.get_task_with_completions(
            task_id) or g.project.source_storage.get(task_id)
        task_data = resolve_task_data_uri(task_data, project=g.project)

        if g.project.ml_backends_connected:
            task_data = g.project.make_predictions(task_data)

    return flask.render_template('labeling.html',
                                 project=g.project,
                                 config=g.project.config,
                                 label_config_line=g.project.label_config_line,
                                 task_id=task_id,
                                 task_data=task_data,
                                 **find_editor_files())
示例#5
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)
示例#6
0
def labeling_page():
    """ Label studio frontend: task labeling
    """
    global c
    global label_config_line

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

    # task data: load task or task with completions if it exists
    task_data = None
    task_id = request.args.get('task_id', None)

    if task_id is not None:
        task_data = db.get_task_with_completions(task_id) or db.get_task(
            task_id)
        if ml_backend:
            task_data = deepcopy(task_data)
            task_data['predictions'] = ml_backend.make_predictions(
                task_data, project)

    analytics.send(getframeinfo(currentframe()).function)
    return flask.render_template('labeling.html',
                                 config=c,
                                 label_config_line=label_config_line,
                                 task_id=task_id,
                                 task_data=task_data,
                                 **find_editor_files())
示例#7
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)
示例#8
0
def labeling_page():
    """ Label stream for tasks
    """
    if g.project.no_tasks():
        return redirect(url_for('label_studio.welcome_page'))

    # task data: load task or task with completions if it exists
    task_id = request.args.get('task_id', None)
    task_data = None

    # open separated LSF for task
    if task_id is not None:
        task_id = int(task_id)
        # Task explore mode
        task_data = g.project.get_task_with_completions(
            task_id) or g.project.source_storage.get(task_id)
        task_data = resolve_task_data_uri(task_data, project=g.project)

        if g.project.ml_backends_connected:
            task_data = g.project.make_predictions(task_data)

    # data manager if no task id to open
    elif 'label-old' not in request.url:
        return redirect(url_for('data_manager_blueprint.tasks_page'))

    return flask.render_template('labeling.html',
                                 project=g.project,
                                 config=g.project.config,
                                 label_config_line=g.project.label_config_line,
                                 task_id=task_id,
                                 task_data=task_data,
                                 version=label_studio.__version__,
                                 **find_editor_files())
示例#9
0
def tasks_page():
    """ Tasks and completions page
    """
    return flask.render_template(
        'tasks.html',
        config=g.project.config,
        project=g.project,
        version=label_studio.__version__,
        **find_editor_files()
    )
示例#10
0
def tasks_page():
    """Tasks and completions page"""
    serialized_project = g.project.serialize()
    serialized_project["multi_session_mode"] = (
        current_app.label_studio.input_args.command != "start-multi-session")
    return flask.render_template("tasks.html",
                                 config=g.project.config,
                                 project=g.project,
                                 serialized_project=serialized_project,
                                 **find_editor_files())
示例#11
0
def tasks_page():
    """ Tasks and completions page
    """
    serialized_project = g.project.serialize()
    serialized_project[
        'multi_session_mode'] = input_args.command != 'start-multi-session'
    return flask.render_template('tasks.html',
                                 config=g.project.config,
                                 project=g.project,
                                 serialized_project=serialized_project,
                                 **find_editor_files())
示例#12
0
def tasks_old_page():
    """ Tasks and completions page
    """
    serialized_project = g.project.serialize()
    serialized_project['multi_session_mode'] = current_app.label_studio.input_args.command == 'start-multi-session'
    return flask.render_template(
        'tasks_old.html',
        config=g.project.config,
        project=g.project,
        serialized_project=serialized_project,
        version=label_studio.__version__,
        **find_editor_files()
    )
示例#13
0
def tasks_page():
    """ Tasks and completions page
    """
    project = project_get_or_create()
    serialized_project = project.serialize()
    serialized_project[
        'multi_session_mode'] = input_args.command != 'start-multi-session'
    project.analytics.send(getframeinfo(currentframe()).function)
    return flask.render_template('tasks.html',
                                 config=project.config,
                                 project=project,
                                 serialized_project=serialized_project,
                                 **find_editor_files())
示例#14
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)
示例#15
0
def labelit_labeling_page():
    """ Label studio frontend: task labeling
    This is a modification of labeling page view provided by label studio.
    Our modifications make sure we call the right API URLs as label studio is
    running behind labelit/django.
    """
    set_details_from_headers(request.headers)

    project = server.project_get_or_create()
    if len(project.tasks) == 0:
        return redirect('/welcome') # need to fix this. not sure if this is needed

    # task data: load task or task with completions if it exists
    task_data = None
    task_id = request.args.get('task_id', None)

    if task_id is not None:
        task_data = project.get_task_with_completions(task_id) or project.get_task(task_id)
        """
        # Disabling ML backend for now
        if project.ml_backend:
            task_data = deepcopy(task_data)
            task_data['predictions'] = project.ml_backend.make_predictions(task_data, project.project_obj)
        """
    # Get project name from session
    project_name = session['project']

    return render_template(
        'label_home.html',
        project=project_name,
        config=project.config,
        label_config_line=project.label_config_line,
        task_id=task_id,
        task_data=task_data,
        **find_editor_files()
    )
示例#16
0
def labeling_page():
    """ Label studio frontend: task labeling
    """
    project = project_get_or_create()
    if len(project.tasks) == 0:
        return redirect('/tasks')

    # task data: load task or task with completions if it exists
    task_data = None
    task_id = request.args.get('task_id', None)

    #added code
    num_workers= db.session.execute('select count(id) as c from user where role="worker" ').scalar()
    num_tasks = len(project.tasks)
    num_each = num_tasks//num_workers
    remain = num_tasks % num_workers

    lower_bound = 0
    upper_bound = num_tasks

    task_queue = make_task_queue(num_tasks)

    if(current_user.role == "worker"):
        cur_id = current_user.id
        if(cur_id > len(task_queue)):
            return flask.render_template('closed.html')
        if(len(task_queue) != 0):
            lower_bound = task_queue[cur_id % len(task_queue)][0]
            upper_bound = task_queue[cur_id % len(task_queue)][len(task_queue[cur_id % len(task_queue)]) - 1]

    if task_id is not None:
        task_data = project.get_task_with_completions(task_id) or project.get_task(task_id)
        if project.ml_backend:
            task_data = deepcopy(task_data)
            task_data['predictions'] = project.ml_backend.make_predictions(task_data, project)

    project.analytics.send(getframeinfo(currentframe()).function)


    #Add to admin database if not in yet

    user_count = get_db().execute('select user FROM num_completed where user = :u', {'u':current_user.name})

    fin_count = user_count.fetchall()

    print(len(fin_count))
    if(len(fin_count) == 0):
        get_db().execute('INSERT INTO num_completed (user,num) VALUES (:u,0)', {'u':current_user.name})
        get_db().commit()



    return flask.render_template(
        'labeling.html',
        config=project.config,
        role=current_user.role,
        label_config_line=project.label_config_line,
        task_id=task_id,
        task_data=task_data,
        **find_editor_files()
    )