Skip to content

Commit

Permalink
fix: LEAP-1332: Add task example for MIG config
Browse files Browse the repository at this point in the history
  • Loading branch information
triklozoid committed Nov 12, 2024
1 parent 4a6cefe commit 068b1df
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
23 changes: 12 additions & 11 deletions label_studio/core/label_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,25 +250,26 @@ def generate_sample_task_without_check(label_config, mode='upload', secure_mode=
# make examples pretty
examples = data_examples(mode=mode)

# iterate over xml tree and find values with '$'
# iterate over xml tree and find elements with 'value' or 'valueList' attributes
task = {}
parent = xml.findall('.//*[@value]') # take all tags with value attribute
# Include both 'value' and 'valueList' attributes in the search
parent = xml.findall('.//*[@value]') + xml.findall('.//*[@valueList]')
for p in parent:

# Make sure it is a real object tag, extract data placeholder key
value = p.get('value')
# Extract data placeholder key
value = p.get('value') or p.get('valueList')
if not value or not value.startswith('$'):
continue
value = value[1:]
is_value_list = 'valueList' in p.attrib # Check if the attribute is 'valueList'

# detect secured mode - objects served as URLs
value_type = p.get('valueType') or p.get('valuetype')
only_urls = secure_mode or value_type == 'url'

example_from_field_name = examples.get('$' + value)
if example_from_field_name:
# try to get example by variable name
task[value] = example_from_field_name
# Get example by variable name
task[value] = [example_from_field_name] if is_value_list else example_from_field_name

Check warning on line 272 in label_studio/core/label_config.py

View check run for this annotation

Codecov / codecov/patch

label_studio/core/label_config.py#L272

Added line #L272 was not covered by tests

elif value == 'video' and p.tag == 'HyperText':
task[value] = examples.get('$videoHack')
Expand All @@ -286,7 +287,6 @@ def generate_sample_task_without_check(label_config, mode='upload', secure_mode=
task[value] = []
for item in examples[p.tag]:
task[value].append({name_key: item['author'], text_key: item['text']})

elif p.tag == 'TimeSeries':
# TimeSeries special case - generate signals on-the-fly
time_column = p.get('timeColumn')
Expand Down Expand Up @@ -323,10 +323,11 @@ def generate_sample_task_without_check(label_config, mode='upload', secure_mode=
else:
task[value] = examples['Choices']
else:
# patch for valueType="url"
# Patch for valueType="url"
examples['Text'] = examples['TextUrl'] if only_urls else examples['TextRaw']
# not found by name, try get example by type
task[value] = examples.get(p.tag, 'Something')
# Not found by name, try to get example by type
example_value = examples.get(p.tag, 'Something')
task[value] = [example_value] if is_value_list else example_value

# support for Repeater tag
if '[' in value:
Expand Down
30 changes: 30 additions & 0 deletions label_studio/tests/sample_tasks.tavern.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,33 @@ stages:
dialogue: /samples/paragraphs.json?nameKey=speaker&textKey=phrase
status_code: 200

---
test_name: get_image_sample_task_with_value_list
strict: false
marks:
- usefixtures:
- django_live_url
stages:
- id: signup
type: ref
- name: stage
request:
data:
label_config: |
<View>
<Image name="image" valueList="$images"/>
<RectangleLabels name="labels" toName="image">
<Label value="Label1"/>
<Label value="Label2"/>
<Label value="Label3"/>
</RectangleLabels>
</View>
headers:
content-type: application/x-www-form-urlencoded
method: POST
url: '{django_live_url}/projects/upload-example'
response:
json:
images:
- "/static/samples/sample.jpg"
status_code: 200

0 comments on commit 068b1df

Please sign in to comment.