Skip to content

Commit 856f396

Browse files
niklubnikCopilot
authored
feat: DIA-2214: Utilities to support PDF use cases (#452)
Co-authored-by: nik <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 3e210f2 commit 856f396

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/label_studio_sdk/label_interface/interface.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
import json
99
import jsonschema
1010

11+
from functools import cached_property
1112
from typing import Dict, Optional, List, Tuple, Any, Callable, Union
1213
from pydantic import BaseModel
1314

15+
1416
# from typing import Dict, Optional, List, Tuple, Any
1517
from collections import defaultdict, OrderedDict
1618
from lxml import etree
@@ -517,6 +519,19 @@ def find_tags(
517519

518520
return lst
519521

522+
@cached_property
523+
def ner_tags(self):
524+
return self.find_tags('controls', lambda t: t.tag.lower() in ('labels', 'hypertextlabels'))
525+
526+
@cached_property
527+
def image_tags(self):
528+
return self.find_tags('objects', lambda t: t.tag.lower() == 'image')
529+
530+
@cached_property
531+
def pdf_tags(self):
532+
return self.find_tags('objects', lambda t: t.tag.lower() == 'pdf')
533+
534+
520535
def load_task(self, task):
521536
"""Loads a task and substitutes the value in each object tag
522537
with actual data from the task, returning a copy of the

src/label_studio_sdk/label_interface/object_tags.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,17 @@ def _generate_example(self, examples, only_urls=False):
189189

190190

191191
class ImageTag(ObjectTag):
192-
""" """
192+
"""Image tag"""
193193
tag: str = "Image"
194194

195195
def _generate_example(self, examples, only_urls=False):
196196
""" """
197197
return examples.get("Image")
198+
199+
@property
200+
def is_image_list(self):
201+
"""Check if the tag is an image list, i.e. it has a valueList attribute that accepts list of images"""
202+
return bool(self.attr.get("valueList")) if self.attr else False
198203

199204

200205
class TableTag(ObjectTag):

0 commit comments

Comments
 (0)