Skip to content

Commit

Permalink
remove labelbox client arg from labelbox integration functions (#3031)
Browse files Browse the repository at this point in the history
* remove labelbox client arg from labelbox integration functions

* fix test labelbox failures
  • Loading branch information
tyesayan authored Feb 14, 2025
1 parent b208f60 commit 1339a2e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
23 changes: 13 additions & 10 deletions deeplake/integrations/labelbox/labelbox_.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

def converter_for_video_project_with_id(
project_id,
client,
deeplake_ds_loader,
lb_api_key,
group_mapping=None,
Expand All @@ -26,7 +25,6 @@ def converter_for_video_project_with_id(
Args:
project_id (str): The unique identifier for the Labelbox project to convert.
client (LabelboxClient): An authenticated Labelbox client instance for API access.
deeplake_ds_loader (callable): A function that creates/loads a Deeplake dataset given a name.
lb_api_key (str): Labelbox API key for authentication.
group_mapping (dict, optional): A dictionary mapping annotation kinds (labelbox_kind) to the desired tensor group name (tensor_name). This mapping determines whether annotations of the same kind should be grouped into the same tensor or kept separate.
Expand All @@ -45,10 +43,8 @@ def converter_for_video_project_with_id(
Exception: If project data validation fails.
Example:
>>> client = LabelboxClient(api_key='your_api_key')
>>> converter = converter_for_video_project_with_id(
... '<project_id>',
... client,
... lambda name: deeplake.load(name),
... 'your_api_key',
... group_mapping={"raster-segmentation": "mask"}
Expand All @@ -61,6 +57,9 @@ def converter_for_video_project_with_id(
- Supports Video ontology from labelbox.
- The function first validates the project data before setting up converters.
"""
import labelbox as lb # type: ignore

client = lb.Client(api_key=lb_api_key)
if project_json is None:
project_json = labelbox_get_project_json_with_id_(
client, project_id, fail_on_labelbox_project_export_error
Expand Down Expand Up @@ -181,7 +180,7 @@ def create_labelbox_annotation_project(
video_paths,
lb_dataset_name,
lb_project_name,
lb_client,
lb_api_key,
lb_ontology=None,
lb_batch_priority=5,
data_upload_strategy="fail",
Expand All @@ -194,14 +193,17 @@ def create_labelbox_annotation_project(
video_paths (List[str]): List of paths to video files to be processed can be either all local or all pre-signed remote.
lb_dataset_name (str): Name for Labelbox dataset.
lb_project_name (str): Name for Labelbox project.
lb_client (LabelboxClient): Authenticated Labelbox client instance
lb_api_key (str): Labelbox API key for authentication.
lb_ontology (Ontology, optional): Labelbox ontology to connect to project. Defaults to None
lb_batch_priority (int, optional): Priority for Labelbox batches. Defaults to 5
data_upload_strategy (str, optional): Strategy for uploading data to Labelbox. Can be 'fail', 'skip', or 'all'. Defaults to 'fail'
lb_batches_name (str, optional): Name for Labelbox batches. Defaults to None. If None, will use lb_dataset_name + '_batch-'
"""

import labelbox as lb # type: ignore

lb_client = lb.Client(api_key=lb_api_key)

video_paths = filter_video_paths_(video_paths, data_upload_strategy)

assets = video_paths
Expand Down Expand Up @@ -270,7 +272,6 @@ def create_labelbox_annotation_project(
def create_dataset_from_video_annotation_project_with_custom_data_filler(
deeplake_ds_path,
project_id,
lb_client,
lb_api_key,
data_filler,
deeplake_creds=None,
Expand All @@ -291,7 +292,6 @@ def create_dataset_from_video_annotation_project_with_custom_data_filler(
deeplake_ds_path (str): Path where the Deeplake dataset will be created/stored.
Can be local path or cloud path (e.g. 'hub://org/dataset')
project_id (str): Labelbox project ID to import data from
lb_client (LabelboxClient): Authenticated Labelbox client instance
lb_api_key (str): Labelbox API key for accessing video frames
data_filler (dict): Dictionary containing two functions:
- 'create_tensors': callable(ds) -> None
Expand All @@ -316,6 +316,11 @@ def create_dataset_from_video_annotation_project_with_custom_data_filler(
Notes:
- The function does not fetch the annotations from Labelbox, only the video frames. After creating the dataset, use the converter to apply annotations.
"""

import labelbox as lb # type: ignore

lb_client = lb.Client(api_key=lb_api_key)

wrapped_dataset = dataset_wrapper.create(
deeplake_ds_path,
token=deeplake_token,
Expand Down Expand Up @@ -376,7 +381,6 @@ def default_presigner(url):
def create_dataset_from_video_annotation_project(
deeplake_ds_path,
project_id,
lb_client,
lb_api_key,
deeplake_creds=None,
deeplake_org_id=None,
Expand All @@ -398,7 +402,6 @@ def create_dataset_from_video_annotation_project(
return create_dataset_from_video_annotation_project_with_custom_data_filler(
deeplake_ds_path,
project_id,
lb_client,
lb_api_key,
data_filler={
"create_tensors": create_tensors_default_,
Expand Down
4 changes: 0 additions & 4 deletions deeplake/integrations/tests/test_labelbox.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import labelbox as lb # type: ignore
import os
import numpy as np
import pytest
Expand Down Expand Up @@ -264,7 +263,6 @@ def test_connect_to_labelbox():
ds_path = "mem://labelbox_connect_test"

API_KEY = os.environ["LABELBOX_TOKEN"]
client = lb.Client(api_key=API_KEY)

project_id = "cm4hts5gf0109072nbpl390xc"

Expand All @@ -280,7 +278,6 @@ def url_presigner(url):
ds, project_json = create_dataset_from_video_annotation_project(
ds_path,
project_id,
client,
API_KEY,
url_presigner=url_presigner,
)
Expand All @@ -298,7 +295,6 @@ def ds_provider(p):

converter = converter_for_video_project_with_id(
project_id,
client,
ds_provider,
API_KEY,
group_mapping={"raster-segmentation": "mask"},
Expand Down

0 comments on commit 1339a2e

Please # to comment.