Skip to content

Commit f1b70dc

Browse files
committed
Initial changes
1 parent 9de35c5 commit f1b70dc

File tree

15 files changed

+600
-109
lines changed

15 files changed

+600
-109
lines changed

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
minversion = 3.7
33
log_cli=true
44
python_files = test_*.py
5-
;addopts = -n auto --dist=loadscope
5+
addopts = -n auto --dist=loadscope

src/superannotate/lib/core/serviceproviders.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,17 @@ def upload_annotations(
372372
) -> ServiceResponse:
373373
raise NotImplementedError
374374

375+
def upload_big_annotation(
376+
self,
377+
team_id: int,
378+
project_id: int,
379+
folder_id: int,
380+
item_id: int,
381+
data: io.StringIO,
382+
chunk_size: int,
383+
) -> bool:
384+
raise NotImplementedError
385+
375386
def get_schema(
376387
self, team_id: int, project_type: int, version: str
377388
) -> ServiceResponse:

src/superannotate/lib/core/usecases/annotations.py

Lines changed: 203 additions & 67 deletions
Large diffs are not rendered by default.

src/superannotate/lib/infrastructure/services.py

Lines changed: 122 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ def __init__(
7878
@property
7979
def assets_provider_url(self):
8080
if self.api_url != constance.BACKEND_URL:
81-
return "https://sa-assets-provider.us-west-2.elasticbeanstalk.com/api/v1/"
82-
# return "https://assets-provider.devsuperannotate.com/api/v1/"
81+
# return "https://sa-assets-provider.us-west-2.elasticbeanstalk.com/api/v1.01/"
82+
return "https://assets-provider.devsuperannotate.com/api/v1.01/"
8383
return "https://assets-provider.superannotate.com/api/v1/"
8484

8585
@timed_lru_cache(seconds=360)
@@ -159,6 +159,7 @@ def _request(
159159
content_type=content_type,
160160
)
161161
if response.status_code > 299:
162+
print(url)
162163
self.logger.error(
163164
f"Got {response.status_code} response from backend: {response.text}"
164165
)
@@ -286,7 +287,9 @@ class SuperannotateBackendService(BaseBackendService):
286287
URL_DELETE_ANNOTATIONS = "annotations/remove"
287288
URL_DELETE_ANNOTATIONS_PROGRESS = "annotations/getRemoveStatus"
288289
URL_GET_LIMITS = "project/{}/limitationDetails"
289-
URL_GET_ANNOTATIONS = "annotations/stream"
290+
URL_GET_ANNOTATIONS = (
291+
"https://assets-provider.devsuperannotate.com/api/v1/annotations/stream"
292+
)
290293
URL_UPLOAD_PRIORITY_SCORES = "images/updateEntropy"
291294
URL_GET_INTEGRATIONS = "integrations"
292295
URL_ATTACH_INTEGRATIONS = "image/integration/create"
@@ -296,18 +299,21 @@ class SuperannotateBackendService(BaseBackendService):
296299
URL_CREATE_CUSTOM_SCHEMA = "/project/{project_id}/custom/metadata/schema"
297300
URL_GET_CUSTOM_SCHEMA = "/project/{project_id}/custom/metadata/schema"
298301
URL_UPLOAD_CUSTOM_VALUE = "/project/{project_id}/custom/metadata/item"
299-
URL_UPLOAD_ANNOTATIONS = (
300-
"https://sa-assets-provider.us-west-2.elasticbeanstalk.com/api/"
301-
"v1.01/items/annotations/upload"
302-
)
303-
URL_ANNOTATION_SCHEMAS = "https://sa-assets-provider.us-west-2.elasticbeanstalk.com/api/v1.01/items/annotations/schema"
302+
URL_UPLOAD_ANNOTATIONS = "items/annotations/upload"
303+
URL_ANNOTATION_SCHEMAS = "items/annotations/schema"
304+
URL_START_FILE_UPLOAD_PROCESS = "items/{item_id}/annotations/upload/multipart/start"
305+
URL_START_FILE_SEND_PART = "items/{item_id}/annotations/upload/multipart/part"
306+
URL_START_FILE_SEND_FINISH = "items/{item_id}/annotations/upload/multipart/finish"
307+
URL_START_FILE_SYNC = "items/{item_id}/annotations/sync"
308+
URL_START_FILE_SYNC_STATUS = "items/{item_id}/annotations/sync/status"
304309

305310
def upload_priority_scores(
306311
self, team_id: int, project_id: int, folder_id: int, priorities: list
307312
) -> dict:
308313
upload_priority_score_url = urljoin(
309314
self.api_url, self.URL_UPLOAD_PRIORITY_SCORES
310315
)
316+
311317
res = self._request(
312318
upload_priority_score_url,
313319
"post",
@@ -1156,7 +1162,7 @@ def get_annotations(
11561162

11571163
return loop.run_until_complete(
11581164
handler.get_data(
1159-
url=urljoin(self.assets_provider_url, self.URL_GET_ANNOTATIONS),
1165+
url=self.URL_GET_ANNOTATIONS,
11601166
data=items,
11611167
params=query_params,
11621168
chunk_size=self.DEFAULT_CHUNK_SIZE,
@@ -1195,7 +1201,7 @@ async def download_annotations(
11951201
)
11961202

11971203
return await handler.download_data(
1198-
url=urljoin(self.assets_provider_url, self.URL_GET_ANNOTATIONS),
1204+
url=self.URL_GET_ANNOTATIONS,
11991205
data=items,
12001206
params=query_params,
12011207
chunk_size=self.DEFAULT_CHUNK_SIZE,
@@ -1376,9 +1382,12 @@ def upload_annotations(
13761382
folder_id: int,
13771383
items_name_file_map: Dict[str, io.StringIO],
13781384
) -> UploadAnnotationsResponse:
1379-
url = f"{self.URL_UPLOAD_ANNOTATIONS}?{'&'.join(f'image_names[]={item_name}' for item_name in items_name_file_map.keys())}"
1385+
13801386
return self._request(
1381-
url,
1387+
urljoin(
1388+
self.assets_provider_url,
1389+
f"{self.URL_UPLOAD_ANNOTATIONS}?{'&'.join(f'image_names[]={item_name}' for item_name in items_name_file_map.keys())}",
1390+
),
13821391
"post",
13831392
params={
13841393
"team_id": team_id,
@@ -1392,12 +1401,111 @@ def upload_annotations(
13921401
content_type=UploadAnnotationsResponse,
13931402
)
13941403

1404+
def upload_big_annotation(
1405+
self,
1406+
team_id: int,
1407+
project_id: int,
1408+
folder_id: int,
1409+
item_id: int,
1410+
data: io.StringIO,
1411+
chunk_size: int,
1412+
) -> bool:
1413+
1414+
params = {
1415+
"team_id": team_id,
1416+
"project_id": project_id,
1417+
"folder_id": folder_id,
1418+
}
1419+
start_response = self._request(
1420+
urljoin(
1421+
self.assets_provider_url,
1422+
self.URL_START_FILE_UPLOAD_PROCESS.format(item_id=item_id),
1423+
),
1424+
"post",
1425+
params={
1426+
"team_id": team_id,
1427+
"project_id": project_id,
1428+
"folder_id": folder_id,
1429+
},
1430+
)
1431+
if not start_response.ok:
1432+
raise AppException("Can't start process.")
1433+
process_info = start_response.json()
1434+
params["path"] = process_info["path"]
1435+
headers = {"upload_id": process_info["upload_id"]}
1436+
chunk_id = 1
1437+
data_sent = False
1438+
while True:
1439+
chunk = data.read(chunk_size)
1440+
params["chunk_id"] = chunk_id
1441+
if chunk:
1442+
print("chunk len:", len(chunk))
1443+
data_sent = True
1444+
response = self._request(
1445+
urljoin(
1446+
self.assets_provider_url,
1447+
self.URL_START_FILE_SEND_PART.format(item_id=item_id),
1448+
),
1449+
"post",
1450+
params=params,
1451+
headers=headers,
1452+
data={"data_chunk": chunk},
1453+
)
1454+
if not response.ok:
1455+
raise AppException("Upload failed.")
1456+
chunk_id += 1
1457+
if not chunk and not data_sent:
1458+
return False
1459+
if len(chunk) < chunk_size:
1460+
break
1461+
del params["chunk_id"]
1462+
response = self._request(
1463+
urljoin(
1464+
self.assets_provider_url,
1465+
self.URL_START_FILE_SEND_FINISH.format(item_id=item_id),
1466+
),
1467+
"post",
1468+
headers=headers,
1469+
params=params,
1470+
)
1471+
if not response.ok:
1472+
raise AppException("Failed to finish upload.")
1473+
del params["path"]
1474+
response = self._request(
1475+
urljoin(
1476+
self.assets_provider_url,
1477+
self.URL_START_FILE_SYNC.format(item_id=item_id),
1478+
),
1479+
"post",
1480+
params=params,
1481+
)
1482+
if not response.ok:
1483+
raise AppException("Sync failed.")
1484+
while True:
1485+
response = self._request(
1486+
urljoin(
1487+
self.assets_provider_url,
1488+
self.URL_START_FILE_SYNC_STATUS.format(item_id=item_id),
1489+
),
1490+
"get",
1491+
params=params,
1492+
)
1493+
if response.ok:
1494+
data = response.json()
1495+
status = data.get("status")
1496+
print(status)
1497+
if status == "SUCCESS":
1498+
return True
1499+
elif status.startswith("FAILED"):
1500+
return False
1501+
else:
1502+
return False
1503+
13951504
def get_schema(
13961505
self, team_id: int, project_type: int, version: str
13971506
) -> ServiceResponse:
1398-
url = self.URL_ANNOTATION_SCHEMAS
13991507
return self._request(
1400-
url,
1508+
urljoin(self.assets_provider_url, self.URL_ANNOTATION_SCHEMAS),
14011509
"get",
14021510
params={
14031511
"team_id": team_id,

tests/data_set/sample_big_json_vector/aearth_mov_001.jpg.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

tests/data_set/sample_big_json_vector/aearth_mov_002.jpg.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

tests/data_set/sample_big_json_vector/aearth_mov_003.jpg.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

tests/data_set/sample_big_json_vector/aearth_mov_004.jpg.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

tests/data_set/sample_big_json_vector/aearth_mov_005.jpg.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"metadata":{"name":"aearth_mov_008.jpg","projectId":1290,"isPredicted":false,"status":"InProgress","pinned":false,"annotatorEmail":null,"qaEmail":null},"instances":[],"tags":[],"comments":[]}

0 commit comments

Comments
 (0)