Skip to content

Commit 88b59f8

Browse files
author
Matt Sokoloff
committed
Merge branch 'tpeharda/DIAG-904-import-prediction-progress' of https://github.com/Labelbox/labelbox-python into develop
2 parents 9ee6dff + 8ecadd8 commit 88b59f8

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

labelbox/schema/annotation_import.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import time
66
from typing import Any, Dict, List, BinaryIO
7+
from tqdm import tqdm # type: ignore
78

89
import backoff
910
import ndjson
@@ -25,6 +26,7 @@ class AnnotationImport(DbObject):
2526
input_file_url = Field.String("input_file_url")
2627
error_file_url = Field.String("error_file_url")
2728
status_file_url = Field.String("status_file_url")
29+
progress = Field.String("progress")
2830

2931
created_by = Relationship.ToOne("User", False, "created_by")
3032

@@ -76,18 +78,28 @@ def statuses(self) -> List[Dict[str, Any]]:
7678
self.wait_until_done()
7779
return self._fetch_remote_ndjson(self.status_file_url)
7880

79-
def wait_until_done(self, sleep_time_seconds: int = 10) -> None:
81+
def wait_until_done(self,
82+
sleep_time_seconds: int = 10,
83+
show_progress: bool = False) -> None:
8084
"""Blocks import job until certain conditions are met.
8185
Blocks until the AnnotationImport.state changes either to
8286
`AnnotationImportState.FINISHED` or `AnnotationImportState.FAILED`,
8387
periodically refreshing object's state.
8488
Args:
85-
sleep_time_seconds (str): a time to block between subsequent API calls
89+
sleep_time_seconds (int): a time to block between subsequent API calls
90+
show_progress (bool): should show progress bar
8691
"""
92+
pbar = tqdm(total=100) if show_progress else None
8793
while self.state.value == AnnotationImportState.RUNNING.value:
8894
logger.info(f"Sleeping for {sleep_time_seconds} seconds...")
8995
time.sleep(sleep_time_seconds)
9096
self.__backoff_refresh()
97+
if self.progress and pbar:
98+
pbar.update(self.progress)
99+
100+
if pbar:
101+
pbar.update(100)
102+
pbar.close()
91103

92104
@backoff.on_exception(
93105
backoff.expo,

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@
2727
"requests>=2.22.0",
2828
"google-api-core>=1.22.1",
2929
"pydantic>=1.8,<2.0",
30+
"tqdm",
3031
],
3132
extras_require={
3233
'data': [
3334
"shapely", "geojson", "numpy", "rasterio", "PILLOW",
34-
"opencv-python", "typeguard", "tqdm", "imagesize"
35+
"opencv-python", "typeguard", "imagesize"
3536
],
3637
},
3738
classifiers=[

0 commit comments

Comments
 (0)