Skip to content

Commit

Permalink
CMD opt sampling, skip button, root_dir fix (#242)
Browse files Browse the repository at this point in the history
* cmd opt sampling, skip button, root_dir fix

* update converter reqs

* upgrade version

Co-authored-by: nik <[email protected]>
  • Loading branch information
niklub and nik authored Mar 30, 2020
1 parent c9d1935 commit c388de1
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 19 deletions.
2 changes: 2 additions & 0 deletions label_studio/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 16 additions & 2 deletions label_studio/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,19 @@ def api_completions(task_id):
return make_response('Incorrect request method', 500)


@app.route('/api/tasks/<task_id>/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/<task_id>/completions/<completion_id>/', methods=['DELETE'])
@exception_treatment
def api_completion_by_id(task_id, completion_id):
Expand Down Expand Up @@ -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':
Expand Down
25 changes: 15 additions & 10 deletions label_studio/static/js/lsb.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ const LSB = function(elid, config, task) {
"completions:add-new",
"completions:delete",
"side-column", // entity
"skip"
],

onSubmitCompletion: function(ls, c) {
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 10 additions & 5 deletions label_studio/templates/tasks.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<!-- Statistics -->
<div class="ui two column centered grid">

<div class="row">
<div class="column center aligned">
<div class="ui statistic">
<span class="value">{{ task_ids|length }}</span>
Expand All @@ -25,20 +25,25 @@
{% endif %}
</div>
</div>
</div>

<div class="two column center aligned clearing task-buttons">
<div class="row">
<div class="ui message">
<p>Tasks sampling: <span class="ui orange horizontal label">{{ config['sampling'] }}</span> </p>
</div>
</div>

<div class="row">
{% if task_ids|length > 0 %}
<a class="ui button positive" href="/">Start Labeling</a>
<a id="clear-tasks-button" class="ui button red">Delete All Tasks</a>
{% else %}
<a class="ui button positive" href="/import">Import Tasks</a>
{% endif %}
<br/><br/>
</div>

</div>


<div class="ui divider hidden"></div>
<!-- Table -->
<table>
<tr>
Expand Down
4 changes: 4 additions & 0 deletions label_studio/utils/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import setuptools

# Package version
version = '0.5.0'
version = '0.5.1'

# Readme
with open('README.md', 'r') as f:
Expand Down

0 comments on commit c388de1

Please sign in to comment.