Skip to content
Open
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
25 changes: 16 additions & 9 deletions tutorials/assign_users_to_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import os
import sys
from label_studio_sdk.client import LabelStudio
from label_studio_sdk.core.api_error import ApiError


def main():
Expand Down Expand Up @@ -71,16 +72,22 @@ def main():
}
selected_items = {"all": True}

resp = ls.projects.assignments.bulk_assign(
id=project_id,
type=assignment_type, # 'AN' or 'RE'
users=[user.id], # list of user IDs
selected_items=selected_items, # apply to all tasks matching filters, or you can pass here specific task IDs
filters=filters, # Inner ID in (0, 100)
)
try:
resp = ls.projects.assignments.bulk_assign(
id=project_id,
type=assignment_type, # 'AN' or 'RE'
users=[user.id], # list of user IDs
selected_items=selected_items, # apply to all tasks matching filters, or you can pass here specific task IDs
filters=filters, # Inner ID in (0, 100)
)

# Simple summary
print(f"Bulk assignment done: {resp}")
# Simple summary
print(f"Bulk assignment done: {resp}")
except ApiError as e:
print(
"Assignments API not available on this instance (Enterprise only). "
"Skipping bulk assignment. Error: " + str(e)
)


if __name__ == "__main__":
Expand Down
62 changes: 32 additions & 30 deletions tutorials/connect_to_ml_backend.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,42 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "e9df445f9d4a746c",
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import os\n",
"\n",
"ls = LabelStudio(\n",
" base_url='http://localhost:8080',\n",
" api_key='27c982caa9e599c9d81b25b00663e7d4f82c9e3c'\n",
" base_url=os.getenv('LABEL_STUDIO_URL', 'http://localhost:8080'),\n",
" api_key=os.getenv('LABEL_STUDIO_API_KEY')\n",
")"
],
"metadata": {
"collapsed": false
},
"id": "e9df445f9d4a746c",
"execution_count": null
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "71598abdbca596e2",
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"project = ls.projects.create(\n",
" title='Live OCR',\n",
" description='A project to demonstrate live OCR with connected Tesseract model'\n",
")"
],
"metadata": {
"collapsed": false
},
"id": "71598abdbca596e2",
"execution_count": null
]
},
{
"cell_type": "markdown",
"id": "a04744cba5e2a576",
"metadata": {
"collapsed": false
},
"source": [
"# Create ML backend server\n",
"\n",
Expand All @@ -53,39 +59,35 @@
"```\n",
"\n",
"It will create a server with Tesseract OCR model listening on `http://localhost:9090`."
],
"metadata": {
"collapsed": false
},
"id": "a04744cba5e2a576"
]
},
{
"cell_type": "markdown",
"source": [
"# Connect ML backend server to the project"
],
"id": "45b8c6210f1df70d",
"metadata": {
"collapsed": false
},
"id": "45b8c6210f1df70d"
"source": [
"# Connect ML backend server to the project"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f9f90acea44fdf4e",
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"ls.ml.create(\n",
" title='Tesseract OCR',\n",
" description='A model to perform OCR using Tesseract',\n",
" url='http://localhost:9090',\n",
" url=os.getenv('ML_BACKEND_URL', 'http://localhost:9090'),\n",
" project=project.id,\n",
" is_interactive=True\n",
")"
],
"metadata": {
"collapsed": false
},
"id": "f9f90acea44fdf4e",
"execution_count": null
]
}
],
"metadata": {
Expand Down
88 changes: 46 additions & 42 deletions tutorials/evaluate_llm_response.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,49 @@
"cells": [
{
"cell_type": "markdown",
"source": [
"## Connect to Label Studio"
],
"id": "efa9779a955b3a2b",
"metadata": {
"collapsed": false
},
"id": "efa9779a955b3a2b"
"source": [
"## Connect to Label Studio"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "initial_id",
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import os\n",
"from label_studio_sdk.client import LabelStudio\n",
"\n",
"ls = LabelStudio(api_key='27c982caa9e599c9d81b25b00663e7d4f82c9e3c')"
],
"metadata": {
"collapsed": true
},
"id": "initial_id",
"execution_count": null
"ls = LabelStudio(\n",
" base_url=os.getenv('LABEL_STUDIO_URL', 'http://localhost:8080'),\n",
" api_key=os.getenv('LABEL_STUDIO_API_KEY')\n",
")"
]
},
{
"cell_type": "markdown",
"source": [
"## Create a project"
],
"id": "903cddbc351796d",
"metadata": {
"collapsed": false
},
"id": "903cddbc351796d"
"source": [
"## Create a project"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9e926fb9944f2953",
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"project = ls.projects.create(\n",
Expand Down Expand Up @@ -78,25 +87,25 @@
" </Taxonomy>\n",
" </View>'''\n",
")"
],
"metadata": {
"collapsed": false
},
"id": "9e926fb9944f2953",
"execution_count": null
]
},
{
"cell_type": "markdown",
"source": [
"## Get LLM response"
],
"id": "2bba0ad27241e262",
"metadata": {
"collapsed": false
},
"id": "2bba0ad27241e262"
"source": [
"## Get LLM response"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "45acb931ab897eb7",
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from openai import OpenAI\n",
Expand All @@ -106,7 +115,7 @@
" 'role': 'user'\n",
"}]\n",
"\n",
"llm = OpenAI()\n",
"llm = OpenAI() # uses OPENAI_API_KEY from environment\n",
"completion = llm.chat.completions.create(\n",
" messages=messages,\n",
" model='gpt-3.5-turbo',\n",
Expand All @@ -118,37 +127,32 @@
" 'content': response,\n",
" 'role': 'assistant'\n",
"}]"
],
"metadata": {
"collapsed": false
},
"id": "45acb931ab897eb7",
"execution_count": null
]
},
{
"cell_type": "markdown",
"source": [
"## Create an evaluation task"
],
"id": "24150be492eda586",
"metadata": {
"collapsed": false
},
"id": "24150be492eda586"
"source": [
"## Create an evaluation task"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e3b8ff41102036c7",
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"ls.tasks.create(\n",
" data={'chat': messages},\n",
" project=project.id\n",
")"
],
"metadata": {
"collapsed": false
},
"id": "e3b8ff41102036c7",
"execution_count": null
]
}
],
"metadata": {
Expand Down
9 changes: 6 additions & 3 deletions tutorials/fastapi_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
app = FastAPI()

# Initialize the async client with the API key and project ID from running Label Studio app
# Remember to set LABEL_STUDIO_API_KEY and LABEL_STUDIO_PROJECT_ID environment variables
# Remember to set LABEL_STUDIO_URL, LABEL_STUDIO_API_KEY and LABEL_STUDIO_PROJECT_ID environment variables
client = AsyncLabelStudio(
base_url="http://localhost:8080",
base_url=os.getenv("LABEL_STUDIO_URL", "http://localhost:8080"),
api_key=os.getenv("LABEL_STUDIO_API_KEY"),
)
project_id = int(os.getenv("LABEL_STUDIO_PROJECT_ID"))
project_id_env = os.getenv("LABEL_STUDIO_PROJECT_ID")
if not project_id_env:
raise RuntimeError("LABEL_STUDIO_PROJECT_ID env var is required")
project_id = int(project_id_env)


# Some dummy input data
Expand Down
Loading
Loading