Skip to content

Commit 1e3f213

Browse files
committed
Update __init__.py
1 parent a260d22 commit 1e3f213

File tree

2 files changed

+35
-47
lines changed

2 files changed

+35
-47
lines changed

src/superannotate/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import sys
33

4-
__version__ = "4.4.2dev5"
4+
__version__ = "4.4.2dev6"
55

66
sys.path.append(os.path.split(os.path.realpath(__file__))[0])
77

src/superannotate/lib/infrastructure/services.py

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import copy
23
import datetime
34
import io
45
import json
@@ -1373,52 +1374,39 @@ async def upload_annotations(
13731374
items_name_file_map: Dict[str, io.StringIO],
13741375
) -> UploadAnnotationsResponse:
13751376
url = urljoin(
1376-
self.assets_provider_url,
1377-
f"{self.URL_UPLOAD_ANNOTATIONS}?{'&'.join(f'image_names[]={item_name}' for item_name in items_name_file_map.keys())}",
1377+
"self.assets_provider_url",
1378+
f"{self.URL_UPLOAD_ANNOTATIONS}?{'&'.join(f'image_names[]={item_name}' for item_name in items_name_file_map.keys())}",
1379+
)
1380+
1381+
headers = copy.copy(self.default_headers)
1382+
del headers["Content-Type"]
1383+
async with aiohttp.ClientSession(
1384+
headers=headers,
1385+
connector=aiohttp.TCPConnector(ssl=self._verify_ssl),
1386+
) as session:
1387+
data = aiohttp.FormData()
1388+
1389+
for key, file in items_name_file_map.items():
1390+
file.seek(0)
1391+
data.add_field(key, bytes(file.read(), "ascii"), filename=key, content_type="application/json")
1392+
1393+
_response = await session.post(
1394+
url,
1395+
params={
1396+
"team_id": team_id,
1397+
"project_id": project_id,
1398+
"folder_id": folder_id,
1399+
"image_names": list(items_name_file_map.keys()),
1400+
},
1401+
data=data
13781402
)
1379-
return self._request(
1380-
url,
1381-
"post",
1382-
params={
1383-
"team_id": team_id,
1384-
"project_id": project_id,
1385-
"folder_id": folder_id,
1386-
"image_names": list(items_name_file_map.keys()),
1387-
},
1388-
files=[
1389-
(i[0], (*i, "application/json")) for i in items_name_file_map.items()
1390-
],
1391-
content_type=UploadAnnotationsResponse,
1392-
)
1393-
# async with aiohttp.ClientSession(
1394-
# headers=self.default_headers,
1395-
# connector=aiohttp.TCPConnector(ssl=self._verify_ssl),
1396-
# ) as session:
1397-
# data = aiohttp.FormData()
1398-
#
1399-
# for key, file in items_name_file_map.items():
1400-
# file.seek(0)
1401-
# data.add_field(key, bytes(file.read(), "ascii"), filename=key, content_type="application/json")
1402-
# # data.add_field(key, io.BytesIO(bytes("{}", "utf-8")), filename=key, content_type="application/json")
1403-
#
1404-
# _response = await session.post(
1405-
# # url,
1406-
# params={
1407-
# "team_id": team_id,
1408-
# "project_id": project_id,
1409-
# "folder_id": folder_id,
1410-
# "image_names": list(items_name_file_map.keys()),
1411-
# },
1412-
# data=data
1413-
# )
1414-
# from pydantic import parse_obj_as
1415-
# d = await _response.text()
1416-
# data_json = await _response.json()
1417-
# response = ServiceResponse()
1418-
# response.status = _response.status
1419-
# response._content = await _response.text()
1420-
# response.data = parse_obj_as(UploadAnnotationsResponse, data_json)
1421-
# return response
1403+
from pydantic import parse_obj_as
1404+
data_json = await _response.json()
1405+
response = ServiceResponse()
1406+
response.status = _response.status
1407+
response._content = await _response.text()
1408+
response.data = parse_obj_as(UploadAnnotationsResponse, data_json)
1409+
return response
14221410

14231411
async def upload_big_annotation(
14241412
self,
@@ -1515,7 +1503,7 @@ async def upload_big_annotation(
15151503
return True
15161504
elif status.startswith("FAILED"):
15171505
return False
1518-
time.sleep(1)
1506+
await asyncio.sleep(15)
15191507
else:
15201508
return False
15211509

0 commit comments

Comments
 (0)