Skip to content

Commit 9f6eeb9

Browse files
committed
fix upload
1 parent eca5261 commit 9f6eeb9

File tree

4 files changed

+50
-14
lines changed

4 files changed

+50
-14
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ def __init__(
120120
self._annotation_upload_data = None
121121
self._item_ids = []
122122
self._s3_bucket = None
123-
self._big_files_queue = asyncio.Queue()
124-
self._small_files_queue = asyncio.Queue()
123+
self._big_files_queue = None
124+
self._small_files_queue = None
125125
self._report = Report([], [], [], [])
126126

127127
@staticmethod
@@ -327,16 +327,14 @@ async def upload_small_annotations(self):
327327

328328
async def upload(_chunk):
329329
try:
330-
report = await self._upload_small_annotations(chunk)
330+
report = await self._upload_small_annotations(_chunk)
331331
self._report.failed_annotations.extend(report.failed_annotations)
332332
self._report.missing_classes.extend(report.missing_classes)
333333
self._report.missing_attr_groups.extend(report.missing_attr_groups)
334334
self._report.missing_attrs.extend(report.missing_attrs)
335-
except Exception:
336-
import traceback
337-
338-
traceback.print_exc()
339-
self._report.failed_annotations.extend([i.name for i in chunk])
335+
except Exception as e:
336+
self.reporter.log_debug(str(e))
337+
self._report.failed_annotations.extend([i.name for i in _chunk])
340338

341339
while True:
342340
item = await self._small_files_queue.get()
@@ -407,7 +405,10 @@ async def distribute_queues(self, items_to_upload: list):
407405
self._big_files_queue.put_nowait(t_item)
408406
else:
409407
self._small_files_queue.put_nowait(t_item)
410-
except (ValidationError, AppException):
408+
except Exception as e:
409+
self.reporter.log_debug(str(e))
410+
data[idx][1] = True
411+
self.reporter.update_progress()
411412
self._report.failed_annotations.append(item.name)
412413
finally:
413414
data[idx][1] = True
@@ -417,6 +418,8 @@ async def distribute_queues(self, items_to_upload: list):
417418

418419
async def run_workers(self, items_to_upload):
419420
try:
421+
self._big_files_queue = asyncio.Queue()
422+
self._small_files_queue = asyncio.Queue()
420423
await asyncio.gather(
421424
self.distribute_queues(items_to_upload),
422425
self.upload_small_annotations(),
@@ -449,7 +452,6 @@ def execute(self):
449452
items_to_upload.append(self.AnnotationToUpload(item.uuid, name, path))
450453
except KeyError:
451454
missing_annotations.append(name)
452-
453455
asyncio.run(self.run_workers(items_to_upload))
454456
self.reporter.finish_progress()
455457
self._log_report()
@@ -1228,8 +1230,6 @@ def iter_errors(self, instance, _schema=None):
12281230
validators.extend(jsonschema.validators.iteritems(_schema))
12291231

12301232
for k, v in validators:
1231-
if k == "createdBy":
1232-
print()
12331233
validator = self.VALIDATORS.get(k)
12341234
if validator is None:
12351235
continue

src/superannotate/lib/infrastructure/controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def get_default_reporter(
167167
log_info: bool = True,
168168
log_warning: bool = True,
169169
disable_progress_bar: bool = False,
170-
log_debug: bool = True,
170+
log_debug: bool = False,
171171
) -> Reporter:
172172
return Reporter(log_info, log_warning, disable_progress_bar, log_debug)
173173

src/superannotate/lib/infrastructure/services.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,8 @@ async def upload_annotations(
14021402
data=data,
14031403
)
14041404
if not _response.ok:
1405-
raise AppException(_response.json())
1405+
self.logger.debug(str(await _response.text()))
1406+
raise AppException("Can't upload annotations.")
14061407
data_json = await _response.json()
14071408
response = ServiceResponse()
14081409
response.status = _response.status
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import os
2+
3+
import tempfile
4+
from pathlib import Path
5+
import json
6+
import sys
7+
import logging
8+
logging.basicConfig(level=logging.DEBUG)
9+
10+
11+
LIB_PATH = Path(__file__).parent.parent.parent.parent / "src"
12+
print(LIB_PATH)
13+
sys.path.insert(0, str(LIB_PATH))
14+
sys.path.append(str( Path(__file__).parent.parent.parent.parent))
15+
from src.superannotate import SAClient
16+
17+
# # def test_():
18+
# os.environ.update(
19+
# {
20+
# "SA_VERSION_CHECK": "False",
21+
# "SA_URL": "https://api.devsuperannotate.com",
22+
# "SA_TOKEN": "b0677090e55b8fe5d7448e459a13b0aa3d0fdf8be71fb64c3f10cdde129703de1300ea0a613a7909t=8084"
23+
# }
24+
# )
25+
def test_():
26+
sa = SAClient()
27+
VECTOR_JSON = "example_image_1.jpg___objects.json"
28+
with tempfile.TemporaryDirectory() as tmpdir_name:
29+
with open(f"{tmpdir_name}/{VECTOR_JSON}", "w") as f:
30+
json.dump([{"metadata": {"name": "name"}, "instances": []}], f)
31+
print(sa.upload_annotations_from_folder_to_project("testo", f"{tmpdir_name}"))
32+
# sa.get_annotations("50k Large Data")
33+
34+
35+

0 commit comments

Comments
 (0)