-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
754 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import json | ||
from typing import TYPE_CHECKING, Callable, List, Optional, Dict, Any | ||
|
||
from labelbox.orm.model import Entity | ||
|
||
if TYPE_CHECKING: | ||
from labelbox import User | ||
|
||
def lru_cache() -> Callable[..., Callable[..., Dict[str, Any]]]: | ||
pass | ||
else: | ||
from functools import lru_cache | ||
|
||
|
||
class CreateBatchesTask: | ||
|
||
def __init__(self, client, project_id: str, batch_ids: List[str], | ||
task_ids: List[str]): | ||
self.client = client | ||
self.project_id = project_id | ||
self.batches = batch_ids | ||
self.tasks = [ | ||
Entity.Task.get_task(self.client, task_id) for task_id in task_ids | ||
] | ||
|
||
def wait_till_done(self, timeout_seconds: int = 300) -> None: | ||
""" | ||
Waits for the task to complete. | ||
Args: | ||
timeout_seconds: the number of seconds to wait before timing out | ||
Returns: None | ||
""" | ||
|
||
for task in self.tasks: | ||
task.wait_till_done(timeout_seconds) | ||
|
||
def errors(self) -> Optional[Dict[str, Any]]: | ||
""" | ||
Returns the errors from the task, if any. | ||
Returns: a dictionary of errors, keyed by task id | ||
""" | ||
|
||
errors = {} | ||
for task in self.tasks: | ||
if task.status == "FAILED": | ||
errors[task.uid] = json.loads(task.result_url) | ||
|
||
if len(errors) == 0: | ||
return None | ||
|
||
return errors | ||
|
||
@lru_cache() | ||
def result(self): | ||
""" | ||
Returns the batches created by the task. | ||
Returns: the list of batches created by the task | ||
""" | ||
|
||
return [ | ||
self.client.get_batch(self.project_id, batch_id) | ||
for batch_id in self.batches | ||
] |
Oops, something went wrong.