diff --git a/examples/CONTRIBUTING.md b/examples/CONTRIBUTING.md index b747cd104..81380167b 100644 --- a/examples/CONTRIBUTING.md +++ b/examples/CONTRIBUTING.md @@ -1,16 +1,16 @@ -# Contribution Guide +# Contribution guide Thank you for contributing to our notebook examples! To ensure that your contribution aligns with our guidelines, please carefully review the following guide. -## Table of Contents +## Table of contents -- [General Notebook Requirements](#general-notebook-requirements) -- [Branches and Tags](#branches-and-tags) -- [Github Workflows](#github-workflows) -- [General Prerequisites](#general-prerequisites) -- [Styling Tools](#styling-tools) +- [General notebook requirements](#general-notebook-requirements) +- [Branches and tags](#branches-and-tags) +- [Github workflows](#github-workflows) +- [General prerequisites](#general-prerequisites) +- [Styling tools](#styling-tools) -## General Notebook Requirements +## General notebook requirements Review our [template notebook](template.ipynbs) for general overview on how notebooks should be structure. The template notebook and this section just serves as a guide and exceptions can be made. Here are our general requirements: @@ -27,23 +27,23 @@ Review our [template notebook](template.ipynbs) for general overview on how note > [!IMPORTANT] > Please make sure to remove any API keys before pushing changes -## Branches and Tags +## Branches and tags - All development happens in feature branches ideally prefixed by contributor's initials. For example `fs/feature_name`. - Approved PRs are merged to the `develop` branch. - All releases align to a git tag. -## Github Workflows +## Github workflows - Github Branch Workflow - When you push to a branch that contains files inside the examples directory, it will automatically reformat your notebook to match our given style and provide appropriate headers. Once this workflow is completed it will commit back to your branch which then you can pull. - If your push contains new notebooks or modifies the names of notebooks the readme will be updated to reflect the change with updated links. -## General Prerequisites +## General prerequisites [Rye](https://rye-up.com/) may be installed before contributing to the repository as it is the tool used to style our example notebooks. This could be used to avoid the github styling workflow. This is also the packaging tool used for the main SDK. The pyproject used for the example notebooks is a virtual package and does not get published. -## Styling Tools +## Styling tools Rye is setup in this directory to use a customs script that will run the notebooks through our formatting tools and create readmes. diff --git a/examples/README.md b/examples/README.md index 478004fe3..fdf1907e7 100644 --- a/examples/README.md +++ b/examples/README.md @@ -75,11 +75,6 @@ - - Export V1 to V2 Migration Support - Open In Github - Open In Colab - Composite Mask Export Open In Github @@ -105,9 +100,9 @@ - Model Chat Evaluation Project - Open In Github - Open In Colab + Live Multimodal Chat Project + Open In Github + Open In Colab Project Setup diff --git a/examples/exports/export_v1_to_v2_migration_support.ipynb b/examples/exports/export_v1_to_v2_migration_support.ipynb deleted file mode 100644 index 2434c7369..000000000 --- a/examples/exports/export_v1_to_v2_migration_support.ipynb +++ /dev/null @@ -1,591 +0,0 @@ -{ - "nbformat": 4, - "nbformat_minor": 5, - "metadata": {}, - "cells": [ - { - "metadata": {}, - "source": [ - "", - " ", - "\n" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": [ - "# Export V1 to V2 migration " - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": [ - "**Export V1 will no longer be available in any version of the SDK starting on April 2024**. We recommend users to plan accordingly. \n", - "\n", - "This notebook is designed to help users identify alternative V2 export methods that can serve as replacements for V1 methods." - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": [ - "### Key changes included in export V2 methods ( ``export()`` and ``export_v2()``):\n", - "1. Added flexibility to only export the data that is needed. The new methods include parameters and filters to give you more granular control over your exports.\n", - "2. Added functionality to stream an **unlimited** number of data rows using ``export()`` (available on SDK >=3.56). Upgrading to `export()` is recommended as it is a more scalable solution.\n", - "\n", - "For complete details on how to use export V2 methods please see the [Export V2 methods](https://docs.labelbox.com/reference/label-export#export-v2-methods) documentation." - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": [ - "### Export V1 deprecated methods: \n", - "Project methods : \n", - "1. ```project.export_labels()```\n", - "2. ```project.label_generator()```\n", - "3. ```project.export_queued_data_rows()```\n", - "\n", - "Dataset methods: \n", - "1. ```dataset.export_data_rows()```\n", - "\n", - "Batch methods: \n", - "1. ```batch.export_data_rows()```\n", - "\n", - "Model methods :\n", - "1. ```model_run.export_labels()```\n", - "\n" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": [ - "# Imports" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": "%pip install -q \"labelbox[data]\"", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": "import labelbox as lb\nimport pprint\n\npp = pprint.PrettyPrinter(width=30, compact=True)", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": [ - "## API Key and Client\n", - "See the developer guide for [creating an API key](https://docs.labelbox.com/reference/create-api-key)." - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": "API_KEY = \"\"\nclient = lb.Client(api_key=API_KEY)\nclient.enable_experimental = (\n True ## This is required if using the export() streamable method\n)", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": [ - "# Exports V1 to V2 guidelines\n", - "The follow sections will demonstrate how to use the export V2 methods to fetch data from your projects, datasets, batches and model runs. " - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": [ - "## Export labels from a project\n" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": "PROJECT_ID = \"\"\nproject = client.get_project(PROJECT_ID)", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": [ - "##### Export V1 (deprecated) \n", - "1. ```project.export_labels()``` \n", - " - Parameters: \n", - " - ```download: bool = False```\n", - " - ```timeout_seconds: int = 1800```\n", - " - Output : (str | List[Dict[Any, Any]] | None)" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": [ - "For a comprehensive example of Export V1 ``project.export_labels()`` output, please refer to our documentation: [Export V1 sample export](https://docs.labelbox.com/reference/export-image-annotations#sample-project-export)" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": [ - "2. ```project.label_generator()```\n", - " - Parameters: \n", - " - ```timeout_seconds: int = 600```\n", - " - Output: LabelGenerator" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": "# Single entry from the output of project.label_generator() (deprecated)\n# Label objects will not be deprecated.\nsingle_output_from_generator = \"\"\"\n\nLabel(\n uid='clrf5csho2ihx07ilffgp2fzj',\n data=ImageData(\n im_bytes=None,\n file_path=None,\n url='https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg',\n arr=None\n ),\n annotations=[\n ObjectAnnotation(\n confidence=None,\n name='bounding_box',\n feature_schema_id='clrf5ck4a0b9b071paa9ncu15',\n extra={\n 'instanceURI': 'https://api.labelbox.com/masks/feature/clrf5csvi6ofm07lsf9pygwvi?token='\n 'color': '#ff0000',\n 'feature_id': 'clrf5csvi6ofm07lsf9pygwvi',\n 'value': 'bounding_box',\n 'page': None,\n 'unit': None\n },\n value=Rectangle(\n extra={},\n start=Point(extra={}, x=2096.0, y=1264.0),\n end=Point(extra={}, x=2240.0, y=1689.0)\n ),\n classifications=[]\n ),\n # Add more annotations as needed\n # ...\n ],\n extra={\n 'Created By': 'aovalle@labelbox.com',\n 'Project Name': 'Image Annotation Import Demo',\n 'Created At': '2024-01-15T16:35:59.000Z',\n 'Updated At': '2024-01-15T16:51:56.000Z',\n 'Seconds to Label': 66.0,\n 'Agreement': -1.0,\n 'Benchmark Agreement': -1.0,\n 'Benchmark ID': None,\n 'Dataset Name': 'image-demo-dataset',\n 'Reviews': [],\n 'View Label': 'https://editor.labelbox.com?project=clrf5ckex09m9070x1te223u5&label=clrf5csho2ihx07ilffgp2fzj',\n 'Has Open Issues': 0.0,\n 'Skipped': False,\n 'media_type': 'image',\n 'Data Split': None,\n 'Global Key': '2560px-Kitano_Street_Kobe01s5s41102.jpeg'\n }\n)\n\n\"\"\"", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": [ - "##### Export V2 \n", - "\n", - "For complete details on the supported filters abd parameters, including how they are used and what information is included, please see the [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters) documentation.\n", - "\n", - "1. ```project.export()``` : Starting from SDK version 3.56, a streamable method is available, this method allows you to stream unlimited number of data rows. However, if you are using an earlier version, you can still utilize the ```export_v2()``` function with identical parameters. It's important to note that the output task type differs, and streaming data methods are not included in `export_v2()`.\n", - "\n", - " - Parameters: \n", - " - ```\"label_details\": True```\n", - " - ```\"attachments\": True```\n", - " - ```\"data_row_details\": True```\n", - " - ```\"project_details\": True```\n", - " - ```\"label_details\": True```\n", - " - ```\"performance_details\": True```\n", - " - Output: \n", - " - ```ExportTask```\n", - " - `ExportTask.has_result()` return type: bool \n", - " - `ExportTask.has_errors()` return type: bool\n", - " - `ExportTask.get_stream()` return type: Stream[JsonConverterOutput]" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": "## Set the export parameters to only export labels\nexport_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"label_details\": True,\n \"performance_details\": True,\n}\n# You also have the option to include additional filtering to narrow down the list of labels\nfilters = {}\n\nexport_task = project.export(params=export_params, filters=filters)\nexport_task.wait_till_done()", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": "# Provide results with JSON converter\n# Returns streamed JSON output strings from export task results/errors, one by one\n\n\n# Callback used for JSON Converter\ndef json_stream_handler(output: lb.JsonConverterOutput):\n print(output.json_str)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)\n\nprint(\n \"file size: \",\n export_task.get_total_file_size(stream_type=lb.StreamType.RESULT),\n)\nprint(\n \"line count: \",\n export_task.get_total_lines(stream_type=lb.StreamType.RESULT),\n)", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": [ - "## Export queued (\"To Label\") data rows from a project" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": [ - "##### Export V1 (deprecated): \n", - "1. ``project.export_queued_data_rows()`` :\n", - " - Parameters: \n", - " - ``timeout_seconds: int = 120``\n", - " - ``include_metadata: bool = False``\n", - " - Output: List[Dict[str, str]]" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": "# Single entry from the output of project.export_queued_data_rows() (deprecated)\nsingle_output_example = \"\"\"\n[\n {'id': 'clpouak6nap2g0783ajd1d6pf',\n 'createdAt': '2023-12-03T02:04:34.062Z',\n 'updatedAt': '2023-12-03T02:05:33.797Z',\n 'externalId': None,\n 'globalKey': 'b57c9ab2-304f-4c17-ba5f-c536f39a6a46',\n 'metadataFields': [],\n 'customMetadata': [],\n 'rowData': 'https://storage.googleapis.com/labelbox-developer-testing-assets/image/data_files/santa.jpeg',\n 'mediaAttributes': {'assetType': 'image',\n 'contentLength': 305973,\n 'height': 1333,\n 'mimeType': 'image/jpeg',\n 'subType': 'jpeg',\n 'superType': 'image',\n 'width': 2000}}\n]\n\n\"\"\"", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": [ - "##### Export V2\n", - "For complete details on the supported filters and parameters, including how they are used and what information is included, please see the [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters) documentation.\n", - "\n", - "1. ```project.export()``` : Starting from SDK version 3.56, a streamable method is available, this method allows you to stream unlimited number of data rows. However, if you are using an earlier version, you can still utilize the ```export_v2()``` function with identical parameters. It's important to note that the output task type differs, and streaming data methods are not included in `export_v2()`.\n", - "\n", - " - Parameters (Minimum required parameters): \n", - " - ```\"data_row_details\": True```\n", - " - ```\"project_details\": True```\n", - " - Required filters: \n", - " - ``` \"workflow_status\": \"ToLabel\"```\n", - " - Output: \n", - " - ```ExportTask```\n", - " - `ExportTask.has_result()` return type: bool \n", - " - `ExportTask.has_errors()` return type: bool\n", - " - `ExportTask.get_stream()` return type: Stream[JsonConverterOutput]" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": "export_params = {\n \"attachments\": True, # Set to true if you want to export attachments\n \"metadata_fields\": True, # Set to true if you want to export metadata\n \"data_row_details\": True,\n \"project_details\": True,\n}\nfilters = {\n \"workflow_status\":\n \"ToLabel\" ## Using this filter will only export queued data rows\n}\n\n# An ExportTask is returned, this provides additional information about the status of your task, such as\n# any errors encountered and includes additional methods to stream your data\n\nexport_task = project.export(params=export_params, filters=filters)\nexport_task.wait_till_done()", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": "# Provide results with JSON converter\n# Returns streamed JSON output strings from export task results/errors, one by one\n\n\n# Callback used for JSON Converter\ndef json_stream_handler(output: lb.JsonConverterOutput):\n print(output.json_str)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)\n\nprint(\n \"file size: \",\n export_task.get_total_file_size(stream_type=lb.StreamType.RESULT),\n)\nprint(\n \"line count: \",\n export_task.get_total_lines(stream_type=lb.StreamType.RESULT),\n)", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": [ - "## Export data rows from a Dataset " - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": "DATASET_ID = \"\"\ndataset = client.get_dataset(DATASET_ID)", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": [ - "#### Export V1 (deprecated): \n", - "\n", - "1. ```dataset.export_data_rows()```\n", - " - Parameters: \n", - " - ``timeout_seconds=120``\n", - " - ``include_metadata: bool = True``\n", - " - Output: \n", - " - Data row object generator\n" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": "# Single entry from the output of dataset.export_data_rows() (deprecated)\n# Data row objects will not be deprecated.\n\nsingle_output_from_data_row_generator = \"\"\"\n\n\"\"\"", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": [ - "#### Export V2\n", - "For complete details on the supported filters and parameters, including how they are used and what information is included, please see the [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters) documentation.\n", - "\n", - "1. ```project.export()``` : Starting from SDK version 3.56, a streamable method is available, this method allows you to stream unlimited number of data rows. However, if you are using an earlier version, you can still utilize the ```export_v2()``` function with identical parameters. It's important to note that the output task type differs, and streaming data methods are not included in `export_v2()`.\n", - "\n", - " - Parameters (minimum required parameters): \n", - " - ``\"data_row_details\": True``\n", - " - Output: \n", - " - ```ExportTask```\n", - " - `ExportTask.has_result()` return type: bool \n", - " - `ExportTask.has_errors()` return type: bool\n", - " - `ExportTask.get_stream()` return type: Stream[JsonConverterOutput]" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": "export_params = {\n \"attachments\": True, # Set to true if you want to export attachments\n \"metadata_fields\": True, # Set to true if you want to export metadata\n \"data_row_details\": True,\n}\nfilters = {}\n\n# A task is returned, this provides additional information about the status of your task, such as\n# any errors encountered\nexport_task = dataset.export(params=export_params, filters=filters)\nexport_task.wait_till_done()", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": "# Provide results with JSON converter\n# Returns streamed JSON output strings from export task results/errors, one by one\n\n\n# Callback used for JSON Converter\ndef json_stream_handler(output: lb.JsonConverterOutput):\n print(output.json_str)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)\n\nprint(\n \"file size: \",\n export_task.get_total_file_size(stream_type=lb.StreamType.RESULT),\n)\nprint(\n \"line count: \",\n export_task.get_total_lines(stream_type=lb.StreamType.RESULT),\n)", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": [ - "## Export data rows from a batch" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": [ - "#### Export V1 (deprecated): \n", - "1. ```batch.export_data_rows()```\n", - " - Parameters: \n", - " - ``timeout_seconds=120``\n", - " - ``include_metadata: bool = True``\n", - " - Output: \n", - " - Data row object generator" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": "# Single output from batch.export_data_rows() method (deprecated)\n# Data row objects will not be deprecated\n\nsingle_output_from_data_row_generator = \"\"\"\n\n\"\"\"", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": [ - "#### Export V2\n", - "For complete details on the supported filters and parameters, including how they are used and what information is included, please see the [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters) documentation.\n", - "\n", - "1. ```project.export()``` : Starting from SDK version 3.56, a streamable method is available, this method allows you to stream unlimited number of data rows. However, if you are using an earlier version, you can still utilize the ```export_v2()``` function with identical parameters. It's important to note that the output task type differs, and streaming data methods are not included in `export_v2()`.\n", - "\n", - " - Required parameters: \n", - " - ```\"data_row_details\": True```,\n", - " - ```\"batch_ids\": [] ```\n", - " - Output: \n", - " - ```ExportTask```\n", - " - `ExportTask.has_result()` return type: bool \n", - " - `ExportTask.has_errors()` return type: bool\n", - " - `ExportTask.get_stream()` return type: Stream[JsonConverterOutput]" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": "# Find the batch ID by navigating to \"Batches\" --> \"Manage batches\" --> \"Copy Batch ID\"\nBATCH_ID = \"\"", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": "export_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"performance_details\": True,\n \"batch_ids\": [\n BATCH_ID\n ], # Include batch ids if you only want to export specific batches, otherwise,\n # you can export all the data without using this parameter\n}\nfilters = {}\n\n# A task is returned, this provides additional information about the status of your task, such as\n# any errors encountered\nexport_task = project.export(params=export_params, filters=filters)\nexport_task.wait_till_done()", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": "# Provide results with JSON converter\n# Returns streamed JSON output strings from export task results/errors, one by one\n\n\n# Callback used for JSON Converter\ndef json_stream_handler(output: lb.JsonConverterOutput):\n print(output.json_str)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)\n\nprint(\n \"file size: \",\n export_task.get_total_file_size(stream_type=lb.StreamType.RESULT),\n)\nprint(\n \"line count: \",\n export_task.get_total_lines(stream_type=lb.StreamType.RESULT),\n)", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": [ - "## Export data rows from a Model " - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": [ - "#### Export V1 (deprecated): \n", - "1. ```model_run.export_labels(downlaod=True)```\n", - " - Parameters: \n", - " - ```download: bool = False```\n", - " - ```timeout_seconds: int = 1800```\n", - " - Output : (str | List[Dict[Any, Any]] | None)" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": "# Single output from model_run.export_labels()\nsingle_output_example = \"\"\"\n[\n {'ID': '1c48a7a0-3016-48e0-b0e3-47430f974869',\n 'Data Split': 'training',\n 'DataRow ID': 'clpqdyf650xd40712pycshy6a',\n 'External ID': './resume/BANKING/99124477.pdf',\n 'Labeled Data': 'https://storage.labelbox.com/cl5bn8qvq1av907xtb3bp8q60%2F8c6afc38-42a4-b2e1-a2e3-1e3b0c2998fc-99124477.pdf?Expires=1706637969726&KeyName=labelbox-assets-key-3&Signature=2nVt3sJ21CbjGS9I64yFquUELRw',\n 'Media Attributes': {'assetType': 'pdf',\n 'contentLength': 42535,\n 'mimeType': 'application/pdf',\n 'pageCount': 3,\n 'subType': 'pdf',\n 'superType': 'application'},\n 'Label': {'objects': [{'featureId': 'b9f3b584-0f45-050a-88d4-39c2a169c8e1',\n 'schemaId': 'clq1ckwbd08jp07z91q9mch5j',\n 'title': 'Test',\n 'value': 'test',\n 'color': '#1CE6FF',\n 'data': {'location': [{'text-bbox': {'page': 1,\n 'top': 158.44,\n 'left': 58.765,\n 'height': 13.691,\n 'width': 78.261}}],\n 'unit': 'POINTS'}}],\n 'classifications': [],\n 'relationships': []}}\n ]\n \"\"\"", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": [ - "#### Export V2\n", - "For complete details on the supported filters and parameters, including how they are used and what information is included, please see the [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters) documentation.\n", - "\n", - "1. ```model_run.export()```: Starting from SDK version 3.56, a streamable method is available, this method allows you to stream unlimited number of data rows. However, if you are using an earlier version, you can still utilize the ```export_v2()``` function with identical parameters. It's important to note that the output task type differs, and streaming data methods are not included in `export_v2()`.\n", - "\n", - " - Required parameters: \n", - " - ```\"data_row_details\": True```\n", - " - ```\"project_details\": True```\n", - " - ```\"label_details\": True```\n", - " - Required filters: \n", - " - N/A -> Filters not supported\n", - " - Output: \n", - " - ```ExportTask```\n", - " - `ExportTask.has_result()` return type: bool \n", - " - `ExportTask.has_errors()` return type: bool\n", - " - `ExportTask.get_stream()` return type: Stream[JsonConverterOutput]" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": "MODEL_RUN_ID = \"\"\nmodel_run = client.get_model_run(MODEL_RUN_ID)", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": "export_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"performance_details\": True,\n}\n\nexport_task = model_run.export(params=export_params)\nexport_task.wait_till_done()", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": "# Provide results with JSON converter\n# Returns streamed JSON output strings from export task results/errors, one by one\n\n\n# Callback used for JSON Converter\ndef json_stream_handler(output: lb.JsonConverterOutput):\n print(output.json_str)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)\n\nprint(\n \"file size: \",\n export_task.get_total_file_size(stream_type=lb.StreamType.RESULT),\n)\nprint(\n \"line count: \",\n export_task.get_total_lines(stream_type=lb.StreamType.RESULT),\n)", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": [ - "## Export data rows from a video project\n", - "Video projects include additional fields. Please refer to the example below to extract specific fields from video exports.\n" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": [ - "##### Export V1 (deprecated) \n", - "1. ```project.export_labels()``` \n", - " - Parameters: \n", - " - ```download: bool = False```\n", - " - ```timeout_seconds: int = 1800```\n", - " - Output : (str | List[Dict[Any, Any]] | None)" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": [ - "For a comprehensive example of Export V1 ``project.export_labels()`` output, please refer to our documentation: [Export V1 sample export](https://docs.labelbox.com/reference/export-image-annotations#sample-project-export)" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": [ - "2. ```project.video_label_generator()```\n", - " - Parameters: \n", - " - ```timeout_seconds: int = 600```\n", - " - Output: LabelGenerator" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": [ - "##### Export V2\n", - "\n", - "For complete details on the supported filters and parameters, including how they are used and what information is included, please see the [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters) documentation.\n", - "\n", - "1. ```project.export()```: Starting from SDK version 3.56, a streamable method is available, this method allows you to stream unlimited number of data rows. However, if you are using an earlier version, you can still utilize the ```export_v2()``` function with identical parameters. It's important to note that the output task type differs, and streaming data methods are not included in `export_v2()`.\n", - "\n", - " - Required parameters: \n", - " - ```\"attachments\": True```\n", - " - ```\"data_row_details\": True```\n", - " - ```\"project_details\": True```\n", - " - ```\"label_details\": True```\n", - " - ```\"performance_details\": True```\n", - " - Output: \n", - " - ```ExportTask```\n", - " - `ExportTask.has_result()` return type: bool \n", - " - `ExportTask.has_errors()` return type: bool\n", - " - `ExportTask.get_stream()` return type: Stream[JsonConverterOutput]" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": "VIDEO_PROJECT_ID = \"\"\nproject = client.get_project(VIDEO_PROJECT_ID)", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": "export_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"performance_details\": True,\n \"label_details\": True,\n \"interpolated_frames\":\n True, # For additional information on interpolated frames please visit our documentation https://docs.labelbox.com/docs/video-annotations#video-editor-components\n}\nfilters = {}\n\n# A task is returned, this provides additional information about the status of your task, such as\n# any errors encountered\nexport_task = project.export(params=export_params, filters=filters)\nexport_task.wait_till_done()", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": [ - "Fetch frame specific objects and frame or global classifications" - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": "import json\nimport pprint as pp # Assuming pp is imported from pprint module\n\nframes_objects_class_list = []\nglobal_class_list = []\n\nstream = export_task.get_stream()\nfor output in stream:\n output_json = json.loads(output.json_str)\n for dr in output_json[\"projects\"][VIDEO_PROJECT_ID][\"labels\"]:\n frames_data = dr[\"annotations\"][\"frames\"]\n for k, v in frames_data.items():\n frames_objects_class_list.append({k: v})\n global_class_list.extend(dr[\"annotations\"][\"classifications\"])\n\n print(\"------- Frame specific classifications and objects -------\")\n pp.pprint(frames_objects_class_list)\n\n print(\"------ Global classifications -------\")\n pp.pprint(global_class_list)", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": [ - "Fetch key frame feature map " - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": "keyframe_map = []\n\nstream = export_task.get_stream()\nfor output in stream:\n output_json = json.loads(output.json_str)\n labels = output_json[\"projects\"][VIDEO_PROJECT_ID][\"labels\"]\n for label in labels:\n annotations = label[\"annotations\"][\"key_frame_feature_map\"]\n for key, value in annotations.items():\n keyframe_map.append({key: value})\n\nprint(\"----- Keyframe Feature Map -----\")\npp.pprint(keyframe_map)", - "cell_type": "code", - "outputs": [], - "execution_count": null - }, - { - "metadata": {}, - "source": [ - "Fetch segments " - ], - "cell_type": "markdown" - }, - { - "metadata": {}, - "source": "segments_map = []\nstream = export_task.get_stream()\nfor output in stream:\n output_json = json.loads(output.json_str)\n labels = output_json[\"projects\"][VIDEO_PROJECT_ID][\"labels\"]\n for label in labels:\n annotations = label[\"annotations\"][\"segments\"]\n for key, value in annotations.items():\n segments_map.append({key: value})\n\nprint(\"----- Segments Feature Map -----\")\npp.pprint(segments_map)", - "cell_type": "code", - "outputs": [], - "execution_count": null - } - ] -} \ No newline at end of file diff --git a/examples/project_configuration/model_chat_evaluation_project.ipynb b/examples/project_configuration/live_multimodal_chat_project.ipynb similarity index 80% rename from examples/project_configuration/model_chat_evaluation_project.ipynb rename to examples/project_configuration/live_multimodal_chat_project.ipynb index 26cd9e6de..0eab0c809 100644 --- a/examples/project_configuration/model_chat_evaluation_project.ipynb +++ b/examples/project_configuration/live_multimodal_chat_project.ipynb @@ -16,12 +16,12 @@ "metadata": {}, "source": [ "\n", - "\n", "\n", "\n", "\n", - "\n", "" ], @@ -30,14 +30,14 @@ { "metadata": {}, "source": [ - "# Model Chat Evaluation Project Setup\n", + "# Live Multimodal Chat project setup\n", "\n", - "This notebook will provide an example workflow of setting up a Model Chat Evaluation (MCE) Project with the Labelbox-Python SDK.\n", - "Model Chat Evaluation Projects are set up differently than other projects with its own unique method and modifications to existing methods:\n", + "This notebook will provide an example workflow of setting up a Live Multimodal Chat (LMC) Project with the Labelbox-Python SDK.\n", + "Live Multimodal Chat Projects are set up differently than other projects with its own unique method and modifications to existing methods:\n", "\n", - "- `client.create_model_evaluation_project`: The main method used to create a model chat evaluation project\n", + "- `client.create_model_evaluation_project`: The main method used to create a Live Multimodal Chat project\n", "\n", - "- `client.create_ontology`: Methods used to create Labelbox ontologies for MCE project this requires an `ontology_kind` parameter set to `lb.OntologyKind.ModelEvaluation`\n", + "- `client.create_ontology`: Methods used to create Labelbox ontologies for LMC project this requires an `ontology_kind` parameter set to `lb.OntologyKind.ModelEvaluation`\n", "\n", "- `client.create_ontology_from_feature_schemas`: Similar to `client.create_ontology` but from a list of `feature schema ids` designed to allow you to use existing features instead of creating new features. This also requires an `ontology_kind` set to `lb.OntologyKind.ModelEvaluation`." ], @@ -46,7 +46,7 @@ { "metadata": {}, "source": [ - "## Set Up" + "## Set up" ], "cell_type": "markdown" }, @@ -67,7 +67,7 @@ { "metadata": {}, "source": [ - "## API Key and Client\n", + "## API key and client\n", "Provide a valid API key below in order to properly connect to the Labelbox client. Please review [Create API key guide](https://docs.labelbox.com/reference/create-api-key) for more information." ], "cell_type": "markdown" @@ -82,16 +82,16 @@ { "metadata": {}, "source": [ - "## Example: Create Model Chat Evaluation Project\n", + "## Example: Create Live Multimodal Chat project\n", "\n", - "The steps to creating a Model Chat Evaluation Project through the Labelbox-Python SDK are similar to creating a regular project. However, they vary slightly, and we will showcase the different methods in this example workflow." + "The steps to creating a Live Multimodal Chat Project through the Labelbox-Python SDK are similar to creating a regular project. However, they vary slightly, and we will showcase the different methods in this example workflow." ], "cell_type": "markdown" }, { "metadata": {}, "source": [ - "### Create a Model Chat Evaluation Ontology\n", + "### Create a Live Multimodal Chat ontology\n", "\n", "You can create ontologies for Model Evaluation projects the same way as creating ontologies for other projects with the only requirement of passing in a `ontology_kind` parameter which needs set to `lb.OntologyKind.ModelEvaluation`. You can create ontologies with two methods: `client.create_ontology` and `client.create_ontology_from_feature_schemas`." ], @@ -102,13 +102,13 @@ "source": [ "#### Option A: `client.create_ontology`\n", "\n", - "Typically, you create ontologies and generate the associated features at the same time. Below is an example of creating an ontology for your model chat evaluation project using supported tools and classifications. For information on supported annotation types visit our [model chat evaluation](https://docs.labelbox.com/docs/model-chat-evaluation#supported-annotation-types) guide." + "Typically, you create ontologies and generate the associated features at the same time. Below is an example of creating an ontology for your Live Multimodal Chat project using supported tools and classifications. For information on supported annotation types visit our [Live Multimodal Chat](https://docs.labelbox.com/docs/live-multimodal-chat#supported-annotation-types) guide." ], "cell_type": "markdown" }, { "metadata": {}, - "source": "ontology_builder = lb.OntologyBuilder(\n tools=[\n lb.Tool(\n tool=lb.Tool.Type.MESSAGE_SINGLE_SELECTION,\n name=\"single select feature\",\n ),\n lb.Tool(\n tool=lb.Tool.Type.MESSAGE_MULTI_SELECTION,\n name=\"multi select feature\",\n ),\n lb.Tool(tool=lb.Tool.Type.MESSAGE_RANKING, name=\"ranking feature\"),\n ],\n classifications=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"checklist feature\",\n options=[\n lb.Option(value=\"option 1\", label=\"option 1\"),\n lb.Option(value=\"option 2\", label=\"option 2\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"radio_question\",\n options=[\n lb.Option(value=\"first_radio_answer\"),\n lb.Option(value=\"second_radio_answer\"),\n ],\n ),\n ],\n)\n\n# Create ontology\nontology = client.create_ontology(\n \"MCE ontology\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Conversational,\n ontology_kind=lb.OntologyKind.ModelEvaluation,\n)", + "source": "ontology_builder = lb.OntologyBuilder(\n tools=[\n lb.Tool(\n tool=lb.Tool.Type.MESSAGE_SINGLE_SELECTION,\n name=\"single select feature\",\n ),\n lb.Tool(\n tool=lb.Tool.Type.MESSAGE_MULTI_SELECTION,\n name=\"multi select feature\",\n ),\n lb.Tool(tool=lb.Tool.Type.MESSAGE_RANKING, name=\"ranking feature\"),\n ],\n classifications=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"checklist feature\",\n options=[\n lb.Option(value=\"option 1\", label=\"option 1\"),\n lb.Option(value=\"option 2\", label=\"option 2\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"radio_question\",\n options=[\n lb.Option(value=\"first_radio_answer\"),\n lb.Option(value=\"second_radio_answer\"),\n ],\n ),\n ],\n)\n\n# Create ontology\nontology = client.create_ontology(\n \"LMC ontology\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Conversational,\n ontology_kind=lb.OntologyKind.ModelEvaluation,\n)", "cell_type": "code", "outputs": [], "execution_count": null @@ -123,7 +123,7 @@ }, { "metadata": {}, - "source": "# ontology = client.create_ontology_from_feature_schemas(\n# \"MCE ontology\",\n# feature_schema_ids=[\"