Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update: Examples from master to 0.0.34 #378

Closed
wants to merge 1 commit into from
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
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ If your data is hosted in Google Cloud Storage (GCS), you can write a Python scr
* Create a snapshot
* Check the snapshot status
* Download the snapshot
* [Export YOLO with images](https://github.com/HumanSignal/label-studio-sdk/blob/master/examples/export_yolo_with_images.py) - This script exports labeled data from a Label Studio project and converts it into the YOLO format, including downloading associated images.


## Machine Learning
Expand Down
4 changes: 3 additions & 1 deletion examples/active_learning/active_learning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Note:** This code utilizes functions from an older version of the Label Studio SDK (v0.0.34). While the newer versions v1.0 and above still support the functionalities of the old version (see `label_studio_sdk._legacy` for reference), we recommend using the latest Label Studio SDK v1.0 or higher.\n",
"\n",
"Active learning is a branch of machine learning that seeks to minimize the total amount of data required for labeling by strategically sampling data that provides insight into the problem you're trying to solve so that you can focus on labeling that data.\n",
"\n",
"Follow this example to write a Python script using the [Label Studio SDK](https://labelstud.io/sdk/index.html) that performs active learning with a text classification machine learning model. "
Expand Down Expand Up @@ -88,7 +90,7 @@
"metadata": {},
"outputs": [],
"source": [
"from label_studio_sdk.project import ProjectSampling\n",
"from label_studio_sdk._legacy.project import ProjectSampling\n",
"\n",
"project = ls.start_project(\n",
" title='AL Project Created from SDK - DEMO',\n",
Expand Down
11 changes: 9 additions & 2 deletions examples/active_learning/active_learning.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
"""
**Note:** This code utilizes functions from an older version of the Label Studio SDK (v0.0.34).
The newer versions v1.0 and above still support the functionalities of the old version, but you will need to specify
[`label_studio_sdk._legacy`](../../README.md) in your script.
"""

import random

from label_studio_sdk import Client
from label_studio_sdk.project import ProjectSampling
import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline

from label_studio_sdk import Client
from label_studio_sdk._legacy.project import ProjectSampling

LABEL_STUDIO_URL = "http://localhost:8080"
API_KEY = "91b3b61589784ed069b138eae3d5a5fe1e909f57"

Expand Down
12 changes: 9 additions & 3 deletions examples/adding_new_labels_to_project.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
"source": [
"This tutorial demonstrates how to add new labels to an ongoing project in real-time. The included example showcases the use of the `<Taxonomy>` tag, which can be applied to the entire document. However, this same principle can also be used for other cases, such as \n",
"- modifying labels for computer vision applications (bounding boxes, polygons, etc.), or segments in text and audio using nested `<Taxonomy>` tags. \n",
"- modify other tags that contain lists of labels, such as `<Choices>` and `<Labels>`."
"- modify other tags that contain lists of labels, such as `<Choices>` and `<Labels>`.\n",
"\n",
"**Note:** This code utilizes functions from an older version of the Label Studio SDK (v0.0.34).\n",
"The newer versions v1.0 and above still support the functionalities of the old version, but you will need to specify\n",
"[`label_studio_sdk._legacy`](../README.md) in your script."
]
},
{
Expand Down Expand Up @@ -222,7 +226,8 @@
"pycharm": {
"name": "#%% md\n"
}
}
},
"id": "641c8dd06b76348c"
},
{
"cell_type": "code",
Expand All @@ -237,7 +242,8 @@
"pycharm": {
"name": "#%%\n"
}
}
},
"id": "fa55edf2c553b707"
}
],
"metadata": {
Expand Down
55 changes: 23 additions & 32 deletions examples/annotate_data_from_gcs/annotate_data_from_gcs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Connect to your GCS bucket"
"## Get your GCS bucket ready"
]
},
{
Expand All @@ -30,33 +30,20 @@
"Connect to your GCS bucket and create a list of task references that Label Studio can use, based on the contents of your bucket. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install --upgrade google-api-python-client"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from google.cloud import storage as google_storage\n",
"\n",
"BUCKET_NAME = 'my-bucket' # specify your bucket name here\n",
"GOOGLE_APPLICATION_CREDENTIALS = 'my-service-account-credentials.json' # specify your GCS credentials\n",
"os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = GOOGLE_APPLICATION_CREDENTIALS\n",
"\n",
"google_client = google_storage.Client()\n",
"bucket = google_client.get_bucket(BUCKET_NAME)\n",
"tasks = []\n",
"for filename in bucket.list_blobs():\n",
" tasks.append({'image': f'gs://{BUCKET_NAME}/{filename}'})"
"BUCKET_NAME = 'your-bucket' # specify your bucket name here\n",
"PREFIX = 'bucket/subfolder' # specify your prefix here\n",
"# assuming you service account key is stored in GOOGLE_APPLICATION_CREDENTIALS\n",
"GOOGLE_APPLICATION_CREDENTIALS_FILE = os.getenv('GOOGLE_APPLICATION_CREDENTIALS') \n",
"with open(GOOGLE_APPLICATION_CREDENTIALS_FILE) as f:\n",
" credentials = f.read()"
]
},
{
Expand All @@ -79,12 +66,11 @@
"metadata": {},
"outputs": [],
"source": [
"from label_studio_sdk import Client\n",
"LABEL_STUDIO_URL = 'http://localhost:8000'\n",
"API_KEY = '91b3b61589784ed069b138eae3d5a5fe1e909f57'\n",
"from label_studio_sdk.client import LabelStudio\n",
"LABEL_STUDIO_URL = 'http://localhost:8080'\n",
"API_KEY = '27c982caa9e599c9d81b25b00663e7d4f82c9e3c'\n",
"\n",
"ls = Client(url=LABEL_STUDIO_URL, api_key=API_KEY)\n",
"ls.check_connection()"
"ls = LabelStudio(base_url=LABEL_STUDIO_URL, api_key=API_KEY)"
]
},
{
Expand All @@ -100,14 +86,14 @@
"metadata": {},
"outputs": [],
"source": [
"project = ls.start_project(\n",
" title='Image Annotation Project from SDK',\n",
"project = ls.projects.create(\n",
" title='Using Images from GCS',\n",
" label_config='''\n",
" <View>\n",
" <Image name=\"image\" value=\"$image\"/>\n",
" <RectangleLabels name=\"objects\" toName=\"image\">\n",
" <Choice value=\"Airplane\"/>\n",
" <Choice value=\"Car\"/>\n",
" <Label value=\"Airplane\"/>\n",
" <Label value=\"Car\"/>\n",
" </RectangleLabels>\n",
" </View>\n",
" '''\n",
Expand All @@ -134,9 +120,14 @@
"metadata": {},
"outputs": [],
"source": [
"project.connect_google_import_storage(\n",
"storage = ls.import_storage.gcs.create(\n",
" project=project.id,\n",
" bucket=BUCKET_NAME,\n",
" google_application_credentials=GOOGLE_APPLICATION_CREDENTIALS\n",
" prefix=PREFIX,\n",
" regex_filter='.*\\.jpg',\n",
" google_application_credentials=credentials,\n",
" use_blob_urls=True,\n",
" presign=True\n",
")"
]
},
Expand All @@ -160,7 +151,7 @@
"metadata": {},
"outputs": [],
"source": [
"project.import_tasks(tasks)"
"ls.import_storage.gcs.sync(id=storage.id)"
]
},
{
Expand Down
7 changes: 7 additions & 0 deletions examples/annotate_data_from_gcs/annotate_data_from_gcs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
"""
Note: This code utilizes functions from an older version of the Label Studio SDK (v0.0.34).
The newer versions v1.0 and above still support the functionalities of the old version, but you will need to specify
[`label_studio_sdk._legacy`](../../README.md) in your script.
"""

import os

from google.cloud import storage as google_storage

from label_studio_sdk import Client

BUCKET_NAME = "my-bucket" # specify your bucket name here
Expand Down
10 changes: 10 additions & 0 deletions examples/cloud_storages/cloud_storage_guide.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
},
"id": "b0600d1650011dc6"
},
{
"metadata": {},
"cell_type": "markdown",
"source": [
"**Note:** This code utilizes functions from an older version of the Label Studio SDK (v0.0.34).\n",
"The newer versions v1.0 and above still support the functionalities of the old version, but you will need to specify\n",
"[`label_studio_sdk._legacy`](../../README.md) in your script."
],
"id": "57cd42b243a4ea45"
},
{
"cell_type": "code",
"outputs": [],
Expand Down
7 changes: 7 additions & 0 deletions examples/export_snapshots.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
"""
**Note:** This code utilizes functions from an older version of the Label Studio SDK (v0.0.34).
The newer versions v1.0 and above still support the functionalities of the old version, but you will need to specify
[`label_studio_sdk._legacy`](../README.md) in your script.
"""

import os
import time

from label_studio_sdk import Client

LABEL_STUDIO_URL = os.getenv("LABEL_STUDIO_URL", default="http://localhost:8080")
Expand Down
6 changes: 5 additions & 1 deletion examples/export_with_filters.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
""" Export a snapshot with tasks filtered by ID range.

Note: at this moment it's not possible to export snapshots with filters,
**Note:** at this moment it's not possible to export snapshots with filters,
LS API doesn't support it yet. However, it's achievable by creating a view
with a filter and then exporting a snapshot using this view.
This approach is hidden behind the `project.export()` method.

**Note:** This code utilizes functions from an older version of the Label Studio SDK (v0.0.34).
The newer versions v1.0 and above still support the functionalities of the old version, but you will need to specify
[`label_studio_sdk._legacy`](../README.md) in your script.
"""

from label_studio_sdk import Client
Expand Down
Loading
Loading