Skip to content

Commit

Permalink
fix: LEAP-1379: disable non-functional export types for MIG projects
Browse files Browse the repository at this point in the history
  • Loading branch information
jombooth committed Nov 14, 2024
1 parent d6b2cea commit 0fa5878
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def parse_config(config_string):
"""
if not config_string:
return {}

try:
xml_tree = etree.fromstring(config_string)
except etree.XMLSyntaxError as e:
Expand Down Expand Up @@ -82,14 +81,23 @@ def parse_config(config_string):
elif _is_input_tag(tag):
inputs[tag.attrib["name"]] = {
"type": tag.tag,
"value": tag.attrib["value"].lstrip("$"),
"valueType": tag.attrib.get("valueType"),
}
if 'value' in tag.attrib:
inputs[tag.attrib["name"]]["value"] = tag.attrib["value"]
elif 'valueList' in tag.attrib:
inputs[tag.attrib["name"]]["valueList"] = tag.attrib["valueList"]
else:
raise ValueError(
'Inspecting tag {tag_name}... found no "value" or "valueList" attributes.'.format(
tag_name=etree.tostring(tag, encoding="unicode").strip()[:50]
)
)
if tag.tag not in _LABEL_TAGS:
continue
parent_name = _get_parent_output_tag_name(tag, outputs)
if parent_name is not None:
actual_value = tag.attrib.get("alias") or tag.attrib.get("value")
actual_value = tag.attrib.get("alias") or tag.attrib.get("value") or tag.attrib.get("valueList")
if not actual_value:
logger.debug(
'Inspecting tag {tag_name}... found no "value" or "alias" attributes.'.format(
Expand Down Expand Up @@ -137,7 +145,7 @@ def _is_input_tag(tag):
"""
Check if tag is input
"""
return tag.attrib.get("name") and tag.attrib.get("value")
return tag.attrib.get("name") and (tag.attrib.get("value") or tag.attrib.get("valueList"))


def _is_output_tag(tag):
Expand Down
14 changes: 10 additions & 4 deletions src/label_studio_sdk/converter/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,16 @@ def _get_data_keys_and_output_tags(self, output_tags=None):
for name, info in self._schema.items():
if output_tags is not None and name not in output_tags:
continue
data_keys |= set(map(itemgetter("value"), info["inputs"]))
for input_tag in info["inputs"]:
for value_key_name in ["value", "valueList"]:
if value_key_name in input_tag:
data_keys.add(input_tag[value_key_name])
output_tag_names.append(name)

return list(data_keys), output_tag_names

def _get_supported_formats(self):
is_MIG = False
if len(self._data_keys) > 1:
return [
Format.JSON.name,
Expand All @@ -300,6 +304,8 @@ def _get_supported_formats(self):
for info in self._schema.values():
output_tag_types.add(info["type"])
for input_tag in info["inputs"]:
if input_tag.get("valueList"):
is_MIG = True
if input_tag["type"] == "Text" and input_tag.get("valueType") == "url":
logger.error('valueType="url" are not supported for text inputs')
continue
Expand All @@ -308,7 +314,7 @@ def _get_supported_formats(self):
all_formats = [f.name for f in Format]
if not ("Text" in input_tag_types and "Labels" in output_tag_types):
all_formats.remove(Format.CONLL2003.name)
if not (
if is_MIG or not (
"Image" in input_tag_types
and (
"RectangleLabels" in output_tag_types
Expand All @@ -317,7 +323,7 @@ def _get_supported_formats(self):
)
):
all_formats.remove(Format.VOC.name)
if not (
if is_MIG or not (
"Image" in input_tag_types
and (
"RectangleLabels" in output_tag_types
Expand Down Expand Up @@ -346,7 +352,7 @@ def _get_supported_formats(self):
and "TextArea" in output_tag_types
):
all_formats.remove(Format.ASR_MANIFEST.name)
if 'Video' in input_tag_types and 'TimelineLabels' in output_tag_types:
if is_MIG or ('Video' in input_tag_types and 'TimelineLabels' in output_tag_types):
all_formats.remove(Format.YOLO_OBB.name)

return all_formats
Expand Down

0 comments on commit 0fa5878

Please sign in to comment.