Skip to content

Commit 35ef51b

Browse files
authored
Merge pull request #1 from nathanielherman/master
Add polygon and line annotation support to python client
2 parents 85578dc + 72d050b commit 35ef51b

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

scaleapi/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
'fields', 'choices'},
1515
'annotation': {'attachment', 'attachment_type', 'instruction',
1616
'objects_to_annotate', 'with_labels', 'examples'},
17+
'polygonannotation': {'attachment', 'attachment_type', 'instruction',
18+
'objects_to_annotate', 'with_labels', 'examples'},
19+
'lineannotation': {'attachment', 'attachment_type', 'instruction',
20+
'objects_to_annotate', 'with_labels', 'examples'},
1721
'datacollection': {'attachment', 'attachment_type', 'fields'},
1822
'audiotranscription': {'attachment', 'attachment_type', 'verbatim'}}
1923
SCALE_ENDPOINT = 'https://api.scaleapi.com/v1/'
@@ -146,6 +150,16 @@ def create_annotation_task(self, **kwargs):
146150
taskdata = self._postrequest('task/annotation', payload=kwargs)
147151
return Task(taskdata, self)
148152

153+
def create_polygonannotation_task(self, **kwargs):
154+
validate_payload('polygonannotation', kwargs)
155+
taskdata = self._postrequest('task/polygonannotation', payload=kwargs)
156+
return Task(taskdata, self)
157+
158+
def create_lineannotation_task(self, **kwargs):
159+
validate_payload('lineannotation', kwargs)
160+
taskdata = self._postrequest('task/lineannotation', payload=kwargs)
161+
return Task(taskdata, self)
162+
149163
def create_datacollection_task(self, **kwargs):
150164
validate_payload('datacollection', kwargs)
151165
taskdata = self._postrequest('task/datacollection', payload=kwargs)

tests/test_client.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,42 @@ def test_annotation_fail():
118118
attachment_type='image')
119119

120120

121+
def test_polygonannotation_ok():
122+
task = client.create_polygonannotation_task(
123+
callback_url='http://www.example.com/callback',
124+
instruction='Draw a tight shape around the big cow',
125+
attachment_type='image',
126+
attachment='http://i.imgur.com/v4cBreD.jpg',
127+
objects_to_annotate=['big cow'],
128+
with_labels=True)
129+
130+
131+
def test_polygonannotation_fail():
132+
with pytest.raises(scaleapi.ScaleInvalidRequest):
133+
client.create_polygonannotation_task(
134+
callback_url='http://www.example.com/callback',
135+
instruction='Draw a tight shape around the big cow',
136+
attachment_type='image')
137+
138+
139+
def test_lineannotation_ok():
140+
task = client.create_lineannotation_task(
141+
callback_url='http://www.example.com/callback',
142+
instruction='Draw a tight shape around the big cow',
143+
attachment_type='image',
144+
attachment='http://i.imgur.com/v4cBreD.jpg',
145+
objects_to_annotate=['big cow'],
146+
with_labels=True)
147+
148+
149+
def test_lineannotation_fail():
150+
with pytest.raises(scaleapi.ScaleInvalidRequest):
151+
client.create_lineannotation_task(
152+
callback_url='http://www.example.com/callback',
153+
instruction='Draw a tight shape around the big cow',
154+
attachment_type='image')
155+
156+
121157
def test_datacollection_ok():
122158
task = client.create_datacollection_task(
123159
callback_url='http://www.example.com/callback',

0 commit comments

Comments
 (0)