Skip to content

Commit

Permalink
use labelbox export_v2 instead of export
Browse files Browse the repository at this point in the history
  • Loading branch information
tyesayan committed Dec 11, 2024
1 parent dd3557b commit 519b357
Showing 1 changed file with 12 additions and 37 deletions.
49 changes: 12 additions & 37 deletions deeplake/integrations/labelbox/labelbox_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ def validate_project_creation_data_(proj, project_id, type):


def labelbox_get_project_json_with_id_(client, project_id, fail_on_error=False):
print("requesting project info from labelbox with id", project_id)
# Set the export params to include/exclude certain fields.
export_params = {
"attachments": False,
Expand All @@ -180,49 +179,25 @@ def labelbox_get_project_json_with_id_(client, project_id, fail_on_error=False):
"embeddings": False,
}

# Note: Filters follow AND logic, so typically using one filter is sufficient.
filters = {
"last_activity_at": ["2000-01-01 00:00:00", "2050-01-01 00:00:00"],
"label_created_at": ["2000-01-01 00:00:00", "2050-01-01 00:00:00"],
}

project = client.get_project(project_id)
export_task = project.export(params=export_params, filters=filters)

export_task = project.export_v2(params=export_params)

print(
"requesting project info from labelbox with id",
project_id,
"export task id",
export_task.uid,
)
export_task.wait_till_done()

# Provide results with JSON converter
# Returns streamed JSON output strings from export task results/errors, one by one

projects = []

# Callback used for JSON Converter
def json_stream_handler(output: lb.BufferedJsonConverterOutput):
projects.append(output.json)

def error_stream_handler(error):
if export_task.errors:
if fail_on_error:
raise Exception(f"Error during export: {error}")
print(f"Error during export: {error}")

try:
if export_task.has_errors():
export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(
stream_handler=error_stream_handler
)
except Exception as e:
if fail_on_error:
raise e
print(f"Error during export: {e}")

if export_task.has_result():
export_json = export_task.get_buffered_stream(
stream_type=lb.StreamType.RESULT
).start(stream_handler=json_stream_handler)
raise ValueError("Labelbox export task failed with errors")
print("Labelbox export task failed with errors:", export_task.errors)

print("project info is ready for project with id", project_id)

return projects
return export_task.result


def create_tensors_default_(ds):
Expand Down

0 comments on commit 519b357

Please sign in to comment.