Skip to content

Commit f396ec6

Browse files
committed
small changes
1 parent e027133 commit f396ec6

File tree

4 files changed

+178
-39
lines changed

4 files changed

+178
-39
lines changed

README.md renamed to README.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ The following endpoints for tasks are available:
3030

3131
## Create Task
3232

33-
Check `this`\_\_ for further information.
33+
This method can be used for any Scale supported task type using the following format:
34+
`client.create_{{Task Type}}_task(...)` and passing the applicable values into the function definition. The applicable fields and further information for each task type can be found in scales API docs `here`\_\_ for further information.
3435

35-
\_\_ https://docs.scale.com/reference#general-image-annotation
36+
\_\_ hhttps://docs.scale.com/reference#general-image-annotation
3637

3738
.. code-block:: python
3839
39-
client.create_task(
40-
task_type = 'imageannotation',
40+
client.create_imageannotation_task(
4141
project = 'test_project',
4242
callback_url = "http://www.example.com/callback",
4343
instruction= "Draw a box around each baby cow and big cow.",
@@ -123,7 +123,7 @@ Check `this`\_\_ for further information.
123123
name = 'batch_name_01_07_2021'
124124
)
125125
126-
## Finalize Batch
126+
## Finalize Batceh
127127

128128
Check `this`\_\_ for further information.
129129

@@ -153,7 +153,7 @@ Check `this`\_\_ for further information.
153153
154154
client.get_batch( batch_name = "batch_name_01_07_2021" )
155155
156-
## List Batchs
156+
## List Batches
157157

158158
Check `this`\_\_ for further information.
159159

@@ -167,7 +167,7 @@ Retrieve a list of batches
167167
counter = 0
168168
all_batchs =[]
169169
while True:
170-
batches = client.batches(
170+
batches = client.list_batches(
171171
status = "completed"
172172
)
173173
for batch in batches:
@@ -207,6 +207,7 @@ Check `this`\_\_ for further information.
207207
208208
## List Projects
209209

210+
This function does not take any arguments. It will return information for every project.
210211
Check `this`\_\_ for further information.
211212

212213
\_\_ https://docs.scale.com/reference#batch-list

local_test.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import scaleapi
2+
3+
nofel_key = "live_ecf03a873847470e8ec59f20b09276b4"
4+
# stanford_key = 'live_c23b58e102b044bd9e854436a9c64a18'
5+
client = scaleapi.ScaleClient(nofel_key)
6+
attachment = 'https://p-ZmFjlye.t1.n0.cdn.getcloudapp.com/items/eDuwnDY4/f5fa720d-6c2c-4ef1-8aed-59e7f1021db6.jpeg?source=client&v=1700792a861cc7747f10f1c36e5ba057'
7+
8+
# task = client.create_task(
9+
# task_type= 'imageannotation',
10+
# callback_url= "http://www.example.com/callback",
11+
# attachment= attachment,
12+
# batch = 'batch_name_01_07_2021',
13+
# # attachment = "s3://scale-sales-uploads/TRI/2d_bbox_sample.mp4",
14+
# # attachment_type = 'video',
15+
# project = 'nofel_test_project',
16+
# )
17+
18+
# print(f'attachment: {attachment}')
19+
# print(f'frame_rate: {frame_rate}')
20+
21+
# data = client.update_project(
22+
# project_name='nofel_test_project',
23+
# instruction='update: Please label all the stuff',
24+
# geometries={'box':{'objects_to_annotate':['update_label']}}
25+
# )
26+
27+
# project = client.create_project(
28+
# project_name = 'nofel_test_project',
29+
# type = 'imageannotation',
30+
# params = {'instruction':'Please label the stuff'}
31+
# )
32+
33+
batch = client.get_projet(
34+
project_name = 'nofel_test_project',
35+
)
36+
37+
print(batch.param_dict['type'])
38+
39+
40+
# counter = 0
41+
# projects = client.projects()
42+
# for project in projects:
43+
# counter += 1
44+
# print('Downloading project %s | %s | %s' % (counter, project['name'], project['type']))

scaleapi/__init__.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,24 @@
55
from .projects import Project
66

77
TASK_TYPES = [
8+
'annotation',
9+
'audiotranscription',
810
'categorization',
11+
'comparison',
12+
'cuboidannotation',
13+
'datacollection',
914
'imageannotation',
15+
'lineannotation',
1016
'namedentityrecognition',
17+
'pointannotation',
18+
'polygonannotation',
1119
'segmentannotation',
20+
'transcription',
1221
'documenttranscription',
1322
'videoannotation',
23+
'videoboxannotation',
1424
'videoplaybackannotation',
15-
'namedentityrecognition',
16-
'textcollection',
17-
'documentmodel'
25+
'videocuboidannotation'
1826
]
1927
SCALE_ENDPOINT = 'https://api.scale.com/v1/'
2028
DEFAULT_LIMIT = 100
@@ -166,12 +174,12 @@ def get_batch(self, batch_name):
166174
batchdata = self._getrequest('batches/%s' % batch_name)
167175
return Batch(batchdata, self)
168176

169-
def batches(self, **kwargs):
177+
def list_batches(self, **kwargs):
170178
allowed_kwargs = {'start_time', 'end_time', 'status', 'project',
171179
'limit', 'offset', }
172180
for key in kwargs:
173181
if key not in allowed_kwargs:
174-
raise ScaleInvalidRequest('Illegal parameter %s for ScaleClient.tasks()'
182+
raise ScaleInvalidRequest('Illegal parameter %s for ScaleClient.list_batches()'
175183
% key, None)
176184
response = self._getrequest('batches', params=kwargs)
177185
docs = [Batch(doc, self) for doc in response['docs']]

tests/test_client.py

Lines changed: 113 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
raise Exception("Please set the environment variable SCALE_TEST_API_KEY to run tests.")
1414

1515
def make_a_task():
16-
return client.create_task(
17-
task_type = 'imageannotation',
16+
return client.create_imageannotation_task(
1817
callback_url = "http://www.example.com/callback",
1918
instruction = "Draw a box around each baby cow and big cow.",
2019
attachment_type = "image",
@@ -29,8 +28,7 @@ def make_a_task():
2928
)
3029

3130
def test_categorize_ok():
32-
task = client.create_task(
33-
task_type = 'categorization',
31+
task = client.create_categorization_task(
3432
callback_url='http://www.example.com/callback',
3533
instruction='Is this company public or private?',
3634
attachment_type='website',
@@ -39,14 +37,12 @@ def test_categorize_ok():
3937

4038
def test_categorize_fail():
4139
with pytest.raises(scaleapi.ScaleInvalidRequest):
42-
client.create_task(
43-
task_type = 'categorization',
40+
client.create_categorization_task(
4441
callback_url='http://www.example.com/callback',
4542
categories=['public', 'private'])
4643

4744
def test_transcription_ok():
48-
task = client.create_task(
49-
task_type = 'categorization',
45+
task = client.create_transcription_task(
5046
callback_url='http://www.example.com/callback',
5147
instruction='Transcribe the given fields. Then for each news item on the page, transcribe the information for the row.',
5248
attachment_type='website',
@@ -62,14 +58,12 @@ def test_transcription_ok():
6258

6359
def test_transcription_fail():
6460
with pytest.raises(scaleapi.ScaleInvalidRequest):
65-
client.create_task(
66-
task_type='transcription',
61+
client.create_transcription_task(
6762
callback_url='http://www.example.com/callback',
6863
attachment_type='website')
6964

7065
def test_imageannotation_ok():
71-
client.create_task(
72-
task_type = 'imageannotation',
66+
client.create_imageannotation_task(
7367
callback_url = "http://www.example.com/callback",
7468
instruction = "Draw a box around each baby cow and big cow.",
7569
attachment_type = "image",
@@ -82,29 +76,123 @@ def test_imageannotation_ok():
8276
}
8377
}
8478
)
85-
# min_width and min_height should be optional
86-
task2 = client.create_task(
87-
task_type = 'imageannotation',
79+
80+
def test_imageannotation_fail():
81+
with pytest.raises(scaleapi.ScaleInvalidRequest):
82+
client.create_imageannotation_task(
83+
callback_url='http://www.example.com/callback',
84+
instruction='Draw a box around each **baby cow** and **big cow**',
85+
attachment_type='image')
86+
87+
def test_documenttranscription_ok():
88+
client.create_documenttranscription_task(
89+
callback_url= 'http://www.example.com/callback',
90+
instruction= 'Please transcribe this receipt.',
91+
attachment= 'http://document.scale.com/receipt-20200519.jpg',
92+
features= [
93+
{
94+
'type': "block",
95+
'label': "barcode",
96+
}
97+
]
98+
)
99+
100+
def test_documenttranscription_fail():
101+
with pytest.raises(scaleapi.ScaleInvalidRequest):
102+
client.create_imageannotation_task(
103+
callback_url='http://www.example.com/callback',
104+
instruction='Please transcribe this receipt.',
105+
)
106+
107+
def test_annotation_ok():
108+
task = client.create_annotation_task(
88109
callback_url='http://www.example.com/callback',
89110
instruction='Draw a box around each **baby cow** and **big cow**',
90111
attachment_type='image',
91112
attachment='http://i.imgur.com/v4cBreD.jpg',
92-
geometries = {
93-
"box": {
94-
"objects_to_annotate": ["Baby Cow", "Big Cow"],
95-
"min_height": 10,
96-
"min_width": 10
97-
}
98-
})
113+
min_width='30',
114+
min_height='30',
115+
objects_to_annotate=['baby cow', 'big cow'],
116+
with_labels=True)
99117

100-
def test_imageannotation_fail():
118+
def test_annotation_fail():
101119
with pytest.raises(scaleapi.ScaleInvalidRequest):
102-
client.create_task(
103-
task_type = 'imageannotation',
120+
client.create_annotation_task(
104121
callback_url='http://www.example.com/callback',
105122
instruction='Draw a box around each **baby cow** and **big cow**',
106123
attachment_type='image')
107124

125+
def test_polygonannotation_ok():
126+
task = client.create_polygonannotation_task(
127+
callback_url='http://www.example.com/callback',
128+
instruction='Draw a tight shape around the big cow',
129+
attachment_type='image',
130+
attachment='http://i.imgur.com/v4cBreD.jpg',
131+
objects_to_annotate=['big cow'],
132+
with_labels=True)
133+
134+
def test_polygonannotation_fail():
135+
with pytest.raises(scaleapi.ScaleInvalidRequest):
136+
client.create_polygonannotation_task(
137+
callback_url='http://www.example.com/callback',
138+
instruction='Draw a tight shape around the big cow',
139+
attachment_type='image')
140+
141+
def test_lineannotation_ok():
142+
task = client.create_lineannotation_task(
143+
callback_url='http://www.example.com/callback',
144+
instruction='Draw a tight shape around the big cow',
145+
attachment_type='image',
146+
attachment='http://i.imgur.com/v4cBreD.jpg',
147+
objects_to_annotate=['big cow'],
148+
with_labels=True)
149+
150+
def test_lineannotation_fail():
151+
with pytest.raises(scaleapi.ScaleInvalidRequest):
152+
client.create_lineannotation_task(
153+
callback_url='http://www.example.com/callback',
154+
instruction='Draw a tight shape around the big cow',
155+
attachment_type='image')
156+
157+
def test_datacollection_ok():
158+
task = client.create_datacollection_task(
159+
callback_url='http://www.example.com/callback',
160+
instruction='Find the URL for the hiring page for the company with attached website.',
161+
attachment_type='website',
162+
attachment='http://www.google.com/',
163+
fields={ 'hiring_page': 'Hiring Page URL' })
164+
165+
def test_datacollection_fail():
166+
with pytest.raises(scaleapi.ScaleInvalidRequest):
167+
client.create_datacollection_task(
168+
callback_url='http://www.example.com/callback',
169+
attachment_type='website')
170+
171+
def test_audiotranscription_ok():
172+
task = client.create_audiotranscription_task(
173+
callback_url='http://www.example.com/callback',
174+
attachment_type='audio',
175+
attachment='https://storage.googleapis.com/deepmind-media/pixie/knowing-what-to-say/second-list/speaker-3.wav',
176+
verbatim=False,
177+
phrases=['avocado', 'stone']
178+
)
179+
180+
def test_audiotranscription_fail():
181+
with pytest.raises(scaleapi.ScaleInvalidRequest):
182+
client.create_audiotranscription_task(
183+
callback_url='http://www.example.com/callback',
184+
attachment_type='audio')
185+
186+
def test_namedentityrecognition_ok():
187+
return client.create_namedentityrecognition_task(
188+
callback_url='http://www.example.com/callback',
189+
instruction='Do the objects in these images have the same pattern?',
190+
text='Example text to label with NER tool',
191+
labels=[{
192+
'name': 'Label_A',
193+
'description': 'the first label',
194+
}])
195+
108196
def test_cancel():
109197
task = make_a_task()
110198
# raises a scaleexception, because test tasks complete instantly
@@ -169,5 +257,3 @@ def get_batch_status():
169257
def get_batch():
170258
batch = create_a_batch()
171259
client.get_batch(batch.name)
172-
173-
def

0 commit comments

Comments
 (0)