Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ check-release: ## Check if everything is ready for release
@echo "3. Commit: git commit -m '[LABIMP-XXXX] Prepare release vX.X.X'"
@echo "4. Push and create PR to main (patch) or develop (minor)"

integration-test:
$(PYTHON) -m pytest -v labellerr_integration_tests.py

pre-commit-install:
pip install pre-commit
Expand Down
60 changes: 20 additions & 40 deletions driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from labellerr.client import LabellerrClient
from labellerr.core.datasets import LabellerrDataset, create_dataset
from labellerr.core.connectors import LabellerrS3Connection
from labellerr.core.connectors import LabellerrS3Connection, LabellerrConnection
from labellerr.core.files import LabellerrFile
from labellerr.core.projects import (
LabellerrProject,
Expand All @@ -25,26 +25,6 @@
)
from labellerr.core.autolabel import LabellerrAutoLabel

# Set logging level to DEBUG
logging.basicConfig(level=logging.DEBUG)

load_dotenv()

API_KEY = os.getenv("API_KEY")
API_SECRET = os.getenv("API_SECRET")
CLIENT_ID = os.getenv("CLIENT_ID")

if not all([API_KEY, API_SECRET, CLIENT_ID]):
raise ValueError(
"API_KEY, API_SECRET, and CLIENT_ID must be set in environment variables"
)

# Initialize client
client = LabellerrClient(
api_key=API_KEY,
api_secret=API_SECRET,
client_id=CLIENT_ID,
)

# if os.getenv("CREATE_DATASET", "").lower() == "true":
# from labellerr import schemas
Expand Down Expand Up @@ -160,25 +140,25 @@
# name="Amazon S3 Export Test",
# description="Amazon S3 Export Test",
# )))
project = LabellerrProject(client=client, project_id="")

export = project.create_export(
export_config=CreateExportParams(
export_name="Amazon S3 Export Test",
export_description="Amazon S3 Export Test",
export_format="json",
statuses=["review"],
connection_id=os.getenv("AWS_EXPORT_CONNECTION_ID"),
export_destination="s3",
export_folder_path="", # pattern - bucket_name/path/to/folder/ - the last slash is important
)
)
# project = LabellerrProject(client=client, project_id="")

print(f"Export created: {export.report_id}")
print(f"Current status: {export._status}")
# export = project.create_export(
# export_config=CreateExportParams(
# export_name="Amazon S3 Export Test",
# export_description="Amazon S3 Export Test",
# export_format="json",
# statuses=["review"],
# connection_id=os.getenv("AWS_EXPORT_CONNECTION_ID"),
# export_destination="s3",
# export_folder_path="", # pattern - bucket_name/path/to/folder/ - the last slash is important
# )
# )

# print(f"Export created: {export.report_id}")
# print(f"Current status: {export._status}")
# Uncomment to poll until completion:
final_status = export.status()
print(f"Final status: {final_status}")
# final_status = export.status()
# print(f"Final status: {final_status}")
# print(autolabel.train(training_request=TrainingRequest(model_id="yolov11", hyperparameters=Hyperparameters(epochs=10), slice_id='', min_samples_per_class=100, job_name="Yolo V11 Training")))

# dataset = LabellerrDataset(client=client, dataset_id="")
Expand All @@ -201,9 +181,9 @@
# print(file.file_data)

# project = LabellerrProject(client=client, project_id="")
# res = project.upload_preannotations(
# res = project.upload_preannotation(
# annotation_format="coco_json", annotation_file="horses_coco.json"
# )
# ).result()
# print(res)

# print(LabellerrProject.list_all_projects(client=client))
Expand Down
73 changes: 73 additions & 0 deletions drivers/connectors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import logging
import os
from dotenv import load_dotenv
from labellerr.client import LabellerrClient

# from labellerr.core.connectors import (
# LabellerrConnection,
# list_connections,
# delete_connection,
# create_connection,
# AWSConnectionParams,
# LabellerrGCSConnection,
# )
# from labellerr.core.schemas import (
# ConnectionType,
# ConnectorType,
# DatasetDataType,
# GCSConnectionTestParams,
# GCSConnectionParams,
# )

# Set logging level to DEBUG
logging.basicConfig(level=logging.DEBUG)

load_dotenv()

API_KEY = os.getenv("API_KEY")
API_SECRET = os.getenv("API_SECRET")
CLIENT_ID = os.getenv("CLIENT_ID")

if not all([API_KEY, API_SECRET, CLIENT_ID]):
raise ValueError(
"API_KEY, API_SECRET, and CLIENT_ID must be set in environment variables"
)

# Initialize client
client = LabellerrClient(
api_key=API_KEY,
api_secret=API_SECRET,
client_id=CLIENT_ID,
)

# response = LabellerrGCSConnection.test_connection(client=client, params=GCSConnectionTestParams(
# svc_account_json='labellerr-dev.json',
# path="gs://aws-labellerr-public-datasets/coco2017",
# connection_type=ConnectionType._IMPORT,
# data_type=DatasetDataType.video,
# ))
# print(response)

# response = create_connection(client=client, connector_type=ConnectorType._GCS, params=GCSConnectionParams(
# svc_account_json='labellerr-dev.json',
# path="gs://aws-labellerr-public-datasets/coco2017",
# connection_type=ConnectionType._IMPORT,
# data_type=DatasetDataType.image, name="GCS Import Test", description="GCS Import Test"))
# print(response)
# connection = LabellerrConnection(client=client, connection_id='8c3dc4b4-e701-4d22-add3-28abc33e13ef')
# response = connection.test(path="gs://aws-labellerr-public-datasets/coco2017", connection_type=ConnectionType._IMPORT, data_type=DatasetDataType.image)
# print(response)
# connection = create_connection(client=client, connector_type=ConnectorType._S3, params=AWSConnectionParams(
# aws_access_key=os.getenv("AWS_KEY"),
# aws_secrets_key=os.getenv("AWS_SECRET"),
# s3_path="s3://amazon-s3-sync-test/labellerr-processed/videos/", # this path is not part of the connection but needed to test the connection on the desired path.
# # This can be dynamically changed while using the connection for creating datasets.
# connection_type=ConnectionType._IMPORT,
# name="Amazon S3 Import Test",
# description="Amazon S3 Import Test",
# ))
# print(f"Connection created: {connection.connection_id}")
# connection = LabellerrConnection(client=client, connection_id='2a30c044-57f7-42c7-8290-bab3bbac0ebc')
# print('connection type', connection.connection_type)

# print (connection.test(s3_path="s3://amazon-s3-sync-test/labellerr-processed/videos/datasets/", connection_type=ConnectionType._IMPORT))
61 changes: 61 additions & 0 deletions drivers/datasets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# from labellerr.core.datasets import (
# create_dataset_from_local,
# create_dataset_from_connection,
# )
import logging
import os
from dotenv import load_dotenv
from labellerr.client import LabellerrClient
from labellerr.core.schemas import DatasetConfig
from labellerr.core.datasets import LabellerrDataset

# from labellerr.core.connectors import (
# LabellerrConnection,
# list_connections,
# delete_connection,
# create_connection,
# AWSConnectionParams,
# LabellerrGCSConnection,
# )
# from labellerr.core.schemas import (
# ConnectionType,
# ConnectorType,
# DatasetDataType,
# GCSConnectionTestParams,
# GCSConnectionParams,
# )

# Set logging level to DEBUG
logging.basicConfig(level=logging.DEBUG)

load_dotenv()

API_KEY = os.getenv("API_KEY")
API_SECRET = os.getenv("API_SECRET")
CLIENT_ID = os.getenv("CLIENT_ID")

if not all([API_KEY, API_SECRET, CLIENT_ID]):
raise ValueError(
"API_KEY, API_SECRET, and CLIENT_ID must be set in environment variables"
)

# Initialize client
client = LabellerrClient(
api_key=API_KEY,
api_secret=API_SECRET,
client_id=CLIENT_ID,
)
dataset_config = DatasetConfig(
dataset_name="test_dataset_from_local SDK",
dataset_description="test dataset description",
data_type="image",
)
# dataset = create_dataset_from_local(
# client=client,
# dataset_config=dataset_config,
# folder_to_upload='images_single',
# )
dataset = LabellerrDataset(
client=client, dataset_id="455e3d45-55f9-436d-98c2-07a514b7894e"
)
print(dataset.files_count)
65 changes: 65 additions & 0 deletions drivers/projects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# from labellerr.core.projects import LabellerrProject
# from labellerr.core.annotation_templates import LabellerrAnnotationTemplate
import logging
import os
from dotenv import load_dotenv
from labellerr.client import LabellerrClient

# from labellerr.core.schemas.annotation_templates import CreateTemplateParams, AnnotationQuestion, QuestionType
# from labellerr.core.annotation_templates import create_template
# from labellerr.core.schemas.projects import CreateProjectParams, RotationConfig
# from labellerr.core.projects import create_project
# from labellerr.core.datasets import LabellerrDataset


# Set logging level to DEBUG
logging.basicConfig(level=logging.DEBUG)

load_dotenv()

API_KEY = os.getenv("API_KEY")
API_SECRET = os.getenv("API_SECRET")
CLIENT_ID = os.getenv("CLIENT_ID")

if not all([API_KEY, API_SECRET, CLIENT_ID]):
raise ValueError(
"API_KEY, API_SECRET, and CLIENT_ID must be set in environment variables"
)

# Initialize client
client = LabellerrClient(
api_key=API_KEY,
api_secret=API_SECRET,
client_id=CLIENT_ID,
)

# project = LabellerrProject(client=client, project_id="rafaela_youngest_pike_23125")
# res = project.upload_preannotation(annotation_format="coco_json", annotation_file="/Users/Ximi-Hoque/Downloads/export_to_annotate_05_15.json").result()
# print(res)

# annotation_template = LabellerrAnnotationTemplate(client=client, annotation_template_id="00016829-9051-46b1-96c6-3ec6763c342a")
# print(annotation_template.annotation_template_data)

# res = create_template(client, CreateTemplateParams(template_name="test_template_1", data_type="image",
# questions=[
# AnnotationQuestion(question_number=1,
# question="test_question",
# question_id="test_question_id",
# question_type=QuestionType.bounding_box,
# required=True,
# color="#FF4500",
# )]))
# print(res)

# project = create_project(client,
# CreateProjectParams(
# project_name="test_project_via_sdk",
# data_type="image",
# rotations=RotationConfig(annotation_rotation_count=1, review_rotation_count=1, client_review_rotation_count=1),
# use_ai=False),
# datasets=[LabellerrDataset(client=client, dataset_id="ca298293-7f5e-4bdd-801f-8863a5ba458b")],
# annotation_template=res
# )
# print (project.project_data)
# project = LabellerrProject(client=client, project_id="dinnie_confidential_lynx_20766")
# print(project.project_data)
64 changes: 64 additions & 0 deletions labellerr/core/annotation_templates/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from .base import LabellerrAnnotationTemplate
from ..schemas.annotation_templates import CreateTemplateParams, QuestionType, Option
from .. import constants
from ..client import LabellerrClient
import uuid

__all__ = [
"LabellerrAnnotationTemplate",
]

object_types = [
QuestionType.bounding_box,
QuestionType.polygon,
QuestionType.polyline,
QuestionType.dot,
]


def create_template(
client: LabellerrClient, params: CreateTemplateParams
) -> LabellerrAnnotationTemplate:
"""Create an annotation template"""

unique_id = str(uuid.uuid4())
for question in params.questions:
if question.question_type in object_types:
if not question.color:
raise ValueError(
"Color is required for bounding box, polygon, polyline, and dot questions"
)
question.options = [Option(option_name=question.color)]
else:
if question.question_type != QuestionType.input and not question.options:
raise ValueError(
"Options are required for radio, boolean, select, dropdown, stt, imc questions"
)

# Convert questions to the expected format
questions_data = []
for question in params.questions:
question_dict = question.model_dump()
# Convert enum to string value
question_dict["option_type"] = question.question_type.value
# Remove question_type as it's now option_type
question_dict.pop("question_type", None)
questions_data.append(question_dict)

payload = {"templateName": params.template_name, "questions": questions_data}
url = (
f"{constants.BASE_URL}/annotations/create_template?client_id={client.client_id}&data_type={params.data_type.value}"
f"&uuid={unique_id}"
)

response = client.make_request(
"POST",
url,
extra_headers={"content-type": "application/json"},
json=payload,
request_id=unique_id,
)
return LabellerrAnnotationTemplate(
client=client,
annotation_template_id=response.get("response", None).get("template_id"),
)
Loading
Loading