def api_generate_next_task(): """ Generate next task to label """ # try to find task is not presented in completions completions = db.get_completions_ids() for (task_id, task) in db.get_tasks().items(): if task_id not in completions: log.info(msg='New task for labeling', extra=task) analytics.send(getframeinfo(currentframe()).function) return make_response(jsonify(task), 200) # no tasks found analytics.send(getframeinfo(currentframe()).function, error=404) return make_response('', 404)
def api_completion_update(task_id, completion_id): """ Rewrite existing completion with patch. This is technical api call for editor testing only. It's used for Rewrite button in editor. """ global c completion = request.json completion.pop('state', None) # remove editor state completion['id'] = int(completion_id) db.save_completion(task_id, completion) log.info(msg='Completion saved', extra={ 'task_id': task_id, 'output': request.json }) analytics.send(getframeinfo(currentframe()).function) return make_response('ok', 201)
def api_generate_next_task(): """ Generate next task to label """ # try to find task is not presented in completions completions = db.get_completions_ids() for task_id, task in db.iter_tasks(): if task_id not in completions: log.info(msg='New task for labeling', extra=task) analytics.send(getframeinfo(currentframe()).function) # try to use ml backend for predictions if ml_backend: task = deepcopy(task) task['predictions'] = ml_backend.make_predictions( task, project) return make_response(jsonify(task), 200) # no tasks found analytics.send(getframeinfo(currentframe()).function, error=404) return make_response('', 404)
def api_completions(task_id): """ Delete or save new completion to output_dir with the same name as task_id """ global c if request.method == 'POST': completion = request.json completion.pop('state', None) # remove editor state completion_id = db.save_completion(task_id, completion) log.info(msg='Completion saved', extra={ 'task_id': task_id, 'output': request.json }) analytics.send(getframeinfo(currentframe()).function) return make_response(json.dumps({'id': completion_id}), 201) else: analytics.send(getframeinfo(currentframe()).function, error=500) return make_response('Incorrect request method', 500)