Skip to content

Commit e144220

Browse files
Add progress bar
1 parent 5141dd1 commit e144220

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

labelbox/schema/annotation_import.py

Lines changed: 14 additions & 7 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
78

89
import backoff
910
import ndjson
@@ -77,18 +78,24 @@ def statuses(self) -> List[Dict[str, Any]]:
7778
self.wait_until_done()
7879
return self._fetch_remote_ndjson(self.status_file_url)
7980

80-
def wait_until_done(self, sleep_time_seconds: int = 10) -> None:
81+
def wait_until_done(self, sleep_time_seconds: int = 10, show_progress: bool = True) -> None:
8182
"""Blocks import job until certain conditions are met.
8283
Blocks until the AnnotationImport.state changes either to
8384
`AnnotationImportState.FINISHED` or `AnnotationImportState.FAILED`,
8485
periodically refreshing object's state.
8586
Args:
86-
sleep_time_seconds (str): a time to block between subsequent API calls
87-
"""
88-
while self.state.value == AnnotationImportState.RUNNING.value:
89-
logger.info(f"Sleeping for {sleep_time_seconds} seconds...")
90-
time.sleep(sleep_time_seconds)
91-
self.__backoff_refresh()
87+
sleep_time_seconds (int): a time to block between subsequent API calls
88+
show_progress (bool): should show progress bar
89+
"""
90+
with tqdm(total=100) as pbar:
91+
while self.state.value == AnnotationImportState.RUNNING.value:
92+
logger.info(f"Sleeping for {sleep_time_seconds} seconds...")
93+
time.sleep(sleep_time_seconds)
94+
self.__backoff_refresh()
95+
if self.progress:
96+
pbar.update(self.progress)
97+
98+
pbar.update(100)
9299

93100
@backoff.on_exception(
94101
backoff.expo,

0 commit comments

Comments
 (0)