diff --git a/label_studio/project.py b/label_studio/project.py index 6d93233b6482..4d49290bf203 100644 --- a/label_studio/project.py +++ b/label_studio/project.py @@ -528,6 +528,8 @@ def already_exists_error(what, path): else: config['ml_backend']['name'] = str(uuid4()) + config['sampling'] = args.sampling + # create config.json config_json = 'config.json' config_json_path = os.path.join(dir, config_json) diff --git a/label_studio/server.py b/label_studio/server.py index 0b591328203c..2129874219de 100644 --- a/label_studio/server.py +++ b/label_studio/server.py @@ -550,6 +550,19 @@ def api_completions(task_id): return make_response('Incorrect request method', 500) +@app.route('/api/tasks//cancel', methods=['POST']) +@exception_treatment +def api_tasks_cancel(task_id): + project = project_get_or_create() + skipped_completion = { + 'result': [], + 'skipped': True + } + completion_id = project.save_completion(task_id, skipped_completion) + project.analytics.send(getframeinfo(currentframe()).function) + return make_response(json.dumps({'id': completion_id}), 201) + + @app.route('/api/tasks//completions//', methods=['DELETE']) @exception_treatment def api_completion_by_id(task_id, completion_id): @@ -647,10 +660,11 @@ def main(): if input_args.init: Project.create_project_dir(input_args.project_name, input_args) - if not os.path.exists(input_args.project_name): + 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=input_args.project_name)) + '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': diff --git a/label_studio/static/js/lsb.js b/label_studio/static/js/lsb.js index b6730bd44836..fa1542389666 100644 --- a/label_studio/static/js/lsb.js +++ b/label_studio/static/js/lsb.js @@ -189,6 +189,7 @@ const LSB = function(elid, config, task) { "completions:add-new", "completions:delete", "side-column", // entity + "skip" ], onSubmitCompletion: function(ls, c) { @@ -236,18 +237,22 @@ const LSB = function(elid, config, task) { onSkipTask: function(ls, completion) { ls.setFlags({ loading: true }); - try { - const json = Requests.post( - `${API_URL.MAIN}${API_URL.TASKS}/${self.task.id}${API_URL.CANCEL}`, - JSON.stringify({ data: JSON.stringify({ error: "cancelled" }) }), - ); + Requests.poster( + `${API_URL.MAIN}${API_URL.TASKS}/${ls.task.id}${API_URL.CANCEL}`, + JSON.stringify(completion), + ).then(function(response) { + response.json().then(function (res) { + // if (res && res.id) completion.updatePersonalKey(res.id.toString()); - self.resetState(); + if (task) { + ls.setFlags({ isLoading: false }); + } else { + loadNext(ls); + } + }) + }); - return loadTask(); - } catch (err) { - console.error("Failed to skip task ", err); - } + return true; }, onGroundTruth: function(ls, c, value) { diff --git a/label_studio/templates/tasks.html b/label_studio/templates/tasks.html index 4ad9c9deddb7..455c3f638a7f 100644 --- a/label_studio/templates/tasks.html +++ b/label_studio/templates/tasks.html @@ -6,7 +6,7 @@
- +
{{ task_ids|length }} @@ -25,20 +25,25 @@ {% endif %}
+
-
+
+
+

Tasks sampling: {{ config['sampling'] }}

+
+
+ +
{% if task_ids|length > 0 %} Start Labeling Delete All Tasks {% else %} Import Tasks {% endif %} -

- - + diff --git a/label_studio/utils/argparser.py b/label_studio/utils/argparser.py index 8e007db2b323..8e2d61c56c5a 100644 --- a/label_studio/utils/argparser.py +++ b/label_studio/utils/argparser.py @@ -64,6 +64,10 @@ def valid_filepath(filepath): root_parser.add_argument( '--ml-backend-name', dest='ml_backend_name', help='Machine learning backend name') + root_parser.add_argument( + '--sampling', dest='sampling', choices=['sequential', 'uniform'], default='uniform', + help='Sampling type that defines tasks order' + ) root_parser.add_argument( '-p', '--port', dest='port', default=8200, type=int, help='Server port') diff --git a/requirements.txt b/requirements.txt index d73098e1d4ec..16ab96ba82f2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -28,4 +28,4 @@ flask_api>=2.0 pandas>=0.24.0 jsonschema>=3.2.0 xmljson==0.2.0 -label-studio-converter>=0.0.11 +label-studio-converter>=0.0.12 diff --git a/setup.py b/setup.py index dc49c7ebf9d8..819e548a8ed6 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ import setuptools # Package version -version = '0.5.0' +version = '0.5.1' # Readme with open('README.md', 'r') as f: