Annotations : Create, Get, Update, Delete
Label your data
Annotations (also known as labels) describe your inputs. When you add inputs to your app, we will create an input level annotation for each input. This input level annotation contains any data you provided in POST /inputs
call. Models in your default workflow can also write annotations.
Once your input is successfully indexed, you can add additional annotations, such as concepts and bounding boxes.
Add Annotations
You can label your inputs by calling the POST /annotations
endpoint. For example, you can add concept(s) to an image, draw a bounding box, or label concept(s) in a video frame.
When you add an annotation, the app's default workflow will be run by default. This means that any newly added annotations will be immediately available for AI based search and training.
You can add from 1 up to 128 annotations in a single API call.
Each annotation should contain at most one region. If it is a video, each annotation should contain 1 frame. If there are multiple regions in a frame you want to label, you can add multiple annotations for each region and each annotation will be contained within the same frame but in a different region.
The initialization code used in the following examples is outlined in detail on the client installation page.
Annotate Images With Concepts
Below is an example of how to annotate a concept present anywhere in an image.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
#################################################################################################
# In this section, we set the user authentication, app ID, and how we want to annotate the image.
# Change these strings to run your own example.
#################################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the image you want to annotate
INPUT_ID = "53d0362a9dfa4e03b2293375e2d0db73"
CONCEPT_ID_1 = "tree"
CONCEPT_ID_2 = "water"
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
post_annotations_response = stub.PostAnnotations(
service_pb2.PostAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
annotations=[
resources_pb2.Annotation(
input_id=INPUT_ID,
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_1, value=1.), # 1 means true, this concept is present
resources_pb2.Concept(id=CONCEPT_ID_2, value=0.) # 0 means false, this concept is not present
]
)
)
]
),
metadata=metadata
)
if post_annotations_response.status.code != status_code_pb2.SUCCESS:
print(post_annotations_response.status)
raise Exception("Post annotations failed, status: " + post_annotations_response.status.description)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to
// annotate the image. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the image you want to annotate
const INPUT_ID = "c99f1b557d1d43d1916b46f8ce4a0487";
const CONCEPT_ID_1 = "tree";
const CONCEPT_ID_2 = "water";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"annotations": [
{
"input_id": INPUT_ID,
// 1 means true, this concept is present
// 0 means false, this concept is not present
"data": {
"concepts": [
{
"id": CONCEPT_ID_1,
"value": 1
},
{
"id": CONCEPT_ID_2,
"value": 0
}
]
}
}
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/annotations", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to
// annotate the image. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the image you want to annotate
const INPUT_ID = "c99f1b557d1d43d1916b46f8ce4a0487";
const CONCEPT_ID_1 = "tree";
const CONCEPT_ID_2 = "water";
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
annotations: [
{
input_id: INPUT_ID,
// 1 means true, this concept is present
// 0 means false, this concept is not present
data: {
concepts: [
{ id: CONCEPT_ID_1, value: 1 },
{ id: CONCEPT_ID_2, value: 0 }
]
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post annotations failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
//////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to
// annotate the image. Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the image you want to annotate
static final String INPUT_ID = "c99f1b557d1d43d1916b46f8ce4a0487";
static final String CONCEPT_ID_1 = "tree";
static final String CONCEPT_ID_2 = "water";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiAnnotationResponse postAnnotationsResponse = stub.postAnnotations(
PostAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addAnnotations(
Annotation.newBuilder()
.setInputId(INPUT_ID)
.setData(
Data.newBuilder().addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_1)
.setValue(1f) // 1 means true, this concept is present
.build()
).addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_2)
.setValue(0f) // 0 means false, this concept is not present
.build()
)
).build()
).build()
);
if (postAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post annotations failed, status: " + postAnnotationsResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to
// annotate the image. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the image you want to annotate
$INPUT_ID = "53d0362a9dfa4e03b2293375e2d0db73";
$CONCEPT_ID_1 = "tree";
$CONCEPT_ID_2 = "water";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostAnnotationsRequest;
use Clarifai\Api\Annotation;
use Clarifai\Api\Concept;
use Clarifai\Api\Data;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PostAnnotations(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostAnnotationsRequest([
"user_app_id" => $userDataObject,
"annotations" => [
new Annotation([
"input_id" => $INPUT_ID,
"data" => new Data([
"concepts" => [
new Concept(["id" => $CONCEPT_ID_1, "value" => 1.]),
new Concept(["id" => $CONCEPT_ID_2, "value" => 0.])
]
])
])
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
?>
# Value of 1 means true, this concept is present
# Value of 0 means false, this concept is not present
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"annotations": [
{
"input_id": "YOUR_INPUT_ID_HERE",
"data": {
"concepts": [
{
"id": "tree",
"value": 1
},
{
"id": "water",
"value": 0
}
]
}
}
]
}'
Annotate Images With Multiple Concepts
Below is an example of how to annotate an image with multiple concepts in a single API call. You can provide the concepts in a list and iterate through it.
- Python
- JavaScript (REST)
- NodeJS
#################################################################################################
# In this section, we set the user authentication, app ID, and how we want to annotate the image.
# Change these strings to run your own example.
#################################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the image you want to annotate with multiple concepts
INPUT_ID = "53d0362a9dfa4e03b2293375e2d0db73"
CONCEPT_IDS_LIST = ['one', 'two', 'three', 'four', 'five', 'six']
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
post_annotations_response = stub.PostAnnotations(
service_pb2.PostAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
annotations=[
resources_pb2.Annotation(
input_id=INPUT_ID,
data=resources_pb2.Data(
concepts=[
# We use Python list comprehension to iterate through the list of concepts
resources_pb2.Concept(id=str(i), value=1.) for i in CONCEPT_IDS_LIST
]
)
)
]
),
metadata=metadata
)
if post_annotations_response.status.code != status_code_pb2.SUCCESS:
print(post_annotations_response.status)
raise Exception("Post annotations failed, status: " + post_annotations_response.status.description)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to
// annotate the image. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the image you want to annotate with multiple concepts
const INPUT_ID = "c99f1b557d1d43d1916b46f8ce4a0487";
const CONCEPT_IDS_LIST = ['one', 'two', 'three', 'four', 'five', 'six'];
// We use a map function to iterate through the list of concepts
const myFunction = () => {
return CONCEPT_IDS_LIST.map((concept)=>({"id":concept,"value":1}));
}
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"annotations": [
{
"input_id": INPUT_ID,
// 1 means true, this concept is present
// 0 means false, this concept is not present
"data": {
"concepts": myFunction()
}
}
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/annotations", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to
// annotate the image. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the image you want to annotate with multiple concepts
const INPUT_ID = "c99f1b557d1d43d1916b46f8ce4a0487";
const CONCEPT_IDS_LIST = ['one', 'two', 'three', 'four', 'five', 'six'];
// We use a map function to iterate through the list of concepts
const myFunction = () => {
return CONCEPT_IDS_LIST.map((concept)=>({"id":concept,"value":1}));
}
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
annotations: [
{
input_id: INPUT_ID,
// 1 means true, this concept is present
// 0 means false, this concept is not present
data: {
concepts: myFunction()
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post annotations failed, status: " + response.status.description);
}
}
);
Annotate New Bounding Boxes in an Image
Below is an example of how to label a new rectangular bounding box for a region.
These are the bounding box coordinates you need to provide:
- top_row—The top left of the bounding box normalized to the data dimension to be within [0-1.0];
- left_col—The left column of the bounding box normalized to the data dimension to be within [0-1.0];
- bottom_row—The bottom row of the bounding box normalized to the data dimension to be within [0-1.0];
- right_col—The right col of the bounding box normalized to the data dimension to be within [0-1.0].
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
########################################################################################
# In this section, we set the user authentication, app ID, and how we want to annotate
# new bounding boxes. Change these strings to run your own example.
#########################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the new bounding boxes you want to annotate
INPUT_ID = "53d0362a9dfa4e03b2293375e2d0db73"
CONCEPT_ID_1 = "tree"
CONCEPT_ID_2 = "water"
CONCEPT_ID_3 = "bike"
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
post_annotations_response = stub.PostAnnotations(
service_pb2.PostAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
annotations=[
resources_pb2.Annotation(
input_id=INPUT_ID,
data=resources_pb2.Data(
regions=[
resources_pb2.Region(
region_info=resources_pb2.RegionInfo(
bounding_box=resources_pb2.BoundingBox( # draw a bounding box
top_row=0,
left_col=0,
bottom_row=0.5,
right_col=0.5
)
),
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_1, value=1.), # 1 means true, this concept is present.
resources_pb2.Concept(id=CONCEPT_ID_2, value=0.) # 0 means false, this concept is not present.
]
)
)
]
)
),
resources_pb2.Annotation(
input_id=INPUT_ID,
data=resources_pb2.Data(
regions=[
resources_pb2.Region(
region_info=resources_pb2.RegionInfo(
bounding_box=resources_pb2.BoundingBox( # draw another bounding box
top_row=0.6,
left_col=0.6,
bottom_row=0.8,
right_col=0.8
)
),
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_3, value=1.), # 1 means true, this concept is present.
]
)
)
]
)
)
]
),
metadata=metadata
)
if post_annotations_response.status.code != status_code_pb2.SUCCESS:
print(post_annotations_response.status)
raise Exception("Post annotations failed, status: " + post_annotations_response.status.description)
<!--index.html file-->
<script>
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// new bounding boxes. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the new bounding boxes you want to annotate
const INPUT_ID = "a8748df4938447e4844b2f505c8eaaef";
const CONCEPT_ID_1 = "tree";
const CONCEPT_ID_2 = "water";
const CONCEPT_ID_3 = "bike";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"annotations": [
{
"input_id": INPUT_ID,
"data": {
"regions": [
{
"region_info": {
"bounding_box": {
"top_row": 0,
"left_col": 0,
"bottom_row": 0.5,
"right_col": 0.5
}
},
"data": {
// 1 means true, this concept is present
// 0 means false, this concept is not present
"concepts": [
{
"id": CONCEPT_ID_1,
"value": 1
},
{
"id": CONCEPT_ID_2,
"value": 0
}
]
}
}
]
}
}, {
"input_id": INPUT_ID,
"data": {
"regions": [
{
"region_info": {
"bounding_box": {
"top_row": 0.6,
"left_col": 0.6,
"bottom_row": 0.8,
"right_col": 0.8
}
},
"data": {
"concepts": [
{
"id": CONCEPT_ID_3,
"value": 1
}
]
}
}
]
}
}
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/annotations", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// new bounding boxes. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the new bounding boxes you want to annotate
const INPUT_ID = "c9cbb1c90cf24bc98bfd2e529e744ca9";
const CONCEPT_ID_1 = "tree";
const CONCEPT_ID_2 = "water";
const CONCEPT_ID_3 = "bike";
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
annotations: [
{ // label a region in this image
input_id: INPUT_ID,
data: {
regions: [
{
region_info: {
bounding_box: { // draw a bounding box
top_row: 0,
left_col: 0,
bottom_row: 0.5,
right_col: 0.5
}
},
// 1 means true, this concept is present
// 0 means false, this concept is not present
data: {
concepts: [
{ id: CONCEPT_ID_1, value: 1 },
{ id: CONCEPT_ID_2, value: 0 }
]
},
}
]
}
}, { // label another region in this image
input_id: INPUT_ID,
data: {
regions: [
{
region_info: {
bounding_box: { // draw another bounding box
top_row: 0.6,
left_col: 0.6,
bottom_row: 0.8,
right_col: 0.8
}
},
// 1 means true, this concept is present
// 0 means false, this concept is not present
data: {
concepts: [
{ id: CONCEPT_ID_3, value: 1 },
]
},
}
]
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post annotations failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// new bounding boxes. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the new bounding boxes you want to annotate
static final String INPUT_ID = "53d0362a9dfa4e03b2293375e2d0db73";
static final String CONCEPT_ID_1 = "tree";
static final String CONCEPT_ID_2 = "water";
static final String CONCEPT_ID_3 = "bike";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiAnnotationResponse postAnnotationsResponse = stub.postAnnotations(
PostAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addAnnotations(
Annotation.newBuilder() // label a region in this image
.setInputId(INPUT_ID)
.setData(
Data.newBuilder().addRegions(
Region.newBuilder()
.setRegionInfo(
RegionInfo.newBuilder()
.setBoundingBox( // draw a bounding box
BoundingBox.newBuilder()
.setTopRow(0f)
.setLeftCol(0f)
.setBottomRow(0.5f)
.setRightCol(0.5f)
.build()
)
.build()
)
.setData(
Data.newBuilder()
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_1)
.setValue(1f) // 1 means true, this concept is present
.build()
)
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_2)
.setValue(0f) // 0 means false, this concept is not present
.build()
)
).build()
).build()
)
.build()
).addAnnotations( // label another region in this image
Annotation.newBuilder()
.setInputId(INPUT_ID)
.setData(
Data.newBuilder().addRegions(
Region.newBuilder()
.setRegionInfo(
RegionInfo.newBuilder()
.setBoundingBox( // draw another bounding box
BoundingBox.newBuilder()
.setTopRow(0.6f)
.setLeftCol(0.6f)
.setBottomRow(0.8f)
.setRightCol(0.8f)
.build()
)
.build()
)
.setData(
Data.newBuilder()
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_3)
.setValue(1f) // 1 means true, this concept is present
.build()
)
).build()
).build()
).build()
).build()
);
if (postAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post annotations failed, status: " + postAnnotationsResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// new bounding boxes. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the new bounding boxes you want to annotate
$INPUT_ID = "a8748df4938447e4844b2f505c8eaaef";
$CONCEPT_ID_1 = "tree";
$CONCEPT_ID_2 = "water";
$CONCEPT_ID_3 = "bike";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostAnnotationsRequest;
use Clarifai\Api\Annotation;
use Clarifai\Api\BoundingBox;
use Clarifai\Api\Concept;
use Clarifai\Api\Data;
use Clarifai\Api\Region;
use Clarifai\Api\RegionInfo;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PostAnnotations(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostAnnotationsRequest([
"user_app_id" => $userDataObject,
"annotations" => [
new Annotation([
"input_id" => $INPUT_ID,
"data" => new Data([
"regions" => [
new Region([
"region_info" => new RegionInfo([
"bounding_box" => new BoundingBox([ // draw a bounding box
"top_row" => 0,
"left_col" => 0,
"bottom_row" => 0.5,
"right_col" => 0.5
])
]),
"data" => new Data([
"concepts" => [
new Concept([ "id" => $CONCEPT_ID_1, "value" => 1. ]), // 1 means true, this concept is present
new Concept([ "id" => $CONCEPT_ID_2, "value" => 0. ]), // 0 means false, this concept is not present
]
])
])
]
])
]),
new Annotation([
"input_id" => $INPUT_ID,
"data" => new Data([
"regions" => [
new Region([
"region_info" => new RegionInfo([
"bounding_box" => new BoundingBox([ // draw another bounding box
"top_row" => 0.6,
"left_col" => 0.6,
"bottom_row" => 0.8,
"right_col" => 0.8
])
]),
"data" => new Data([
"concepts" => [
new Concept([ "id" => $CONCEPT_ID_3, "value" => 1. ]), // 1 means true, this concept is present
]
])
])
]
])
])
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
?>
# Draw two bounding boxes in the same region
# Value of 1 means true, this concept is present
# Value of 0 means false, this concept is not present
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"annotations": [
{
"input_id": "YOUR_INPUT_ID_HERE",
"data": {
"regions": [
{
"region_info": {
"bounding_box": {
"top_row": 0,
"left_col": 0,
"bottom_row": 0.5,
"right_col": 0.5
}
},
"data": {
"concepts": [
{
"id": "tree",
"value": 1
},
{
"id": "water",
"value": 0
}
]
}
}
]
}
}, {
"input_id": "YOUR_INPUT_ID_HERE",
"data": {
"regions": [
{
"region_info": {
"bounding_box": {
"top_row": 0.6,
"left_col": 0.6,
"bottom_row": 0.8,
"right_col": 0.8
}
},
"data": {
"concepts": [
{
"id": "bike",
"value": 1
}
]
}
}
]
}
}
]
}'
Annotate Polygons in an Image
Below is an example of how to provide annotations within any polygon-shaped region of an image.
These are the list of points that connect together to form a polygon:
- row—The row location of the point. This has a [0.0-1.0] range with 0.0 being top row and 1.0 being the bottom row;
- col—The column location of the point. This has a [0.0-1.0] range with 0.0 being left col and 1.0 being the right col;
- z—Depth, if applicable, of the point.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
#########################################################################################
# In this section, we set the user authentication, app ID, and how we want to annotate
# a polygon. Change these strings to run your own example.
#########################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the polygon you want to annotate
INPUT_ID = "ca8666e974ac4c2c8dfbd7df1e7cbc44"
CONCEPT_ID_1 = "tree"
CONCEPT_ID_2 = "water"
CONCEPT_ID_3 = "bike"
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.grpc.api.status import status_code_pb2
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
post_annotations_response = stub.PostAnnotations(
service_pb2.PostAnnotationsRequest(
# The userDataObject is created in the overview and is required when using a PAT
user_app_id=userDataObject,
annotations=[
resources_pb2.Annotation(
input_id=INPUT_ID,
data=resources_pb2.Data(
regions=[
resources_pb2.Region(
region_info=resources_pb2.RegionInfo(
polygon=resources_pb2.Polygon( # draw a polygon
points=[
resources_pb2.Point(row=0.30), # row location of the point, with a [0.0-1.0] range
resources_pb2.Point(col=0.50), # column location of the point, with a [0.0-1.0] range
resources_pb2.Point(z=0.50) # depth, if applicable, of the point
]
)
),
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_1, value=1), # 1 means true, this concept is present
resources_pb2.Concept(id=CONCEPT_ID_2, value=0) # 0 means false, this concept is not present
]
)
)
]
)
),
resources_pb2.Annotation(
input_id=INPUT_ID,
data=resources_pb2.Data(
regions=[
resources_pb2.Region(
region_info=resources_pb2.RegionInfo(
polygon=resources_pb2.Polygon( # draw another polygon
points=[
resources_pb2.Point(row=0.60),
resources_pb2.Point(col=0.80),
resources_pb2.Point(z=0.50)
]
)
),
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_3, value=1), # 1 means true, this concept is present
]
)
)
]
)
)
]
),
metadata=metadata
)
if post_annotations_response.status.code != status_code_pb2.SUCCESS:
print(post_annotations_response.status)
raise Exception("Post annotations failed, status: " + post_annotations_response.status.description)
<!--index.html file-->
<script>
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// a polygon. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the polygon you want to annotate
const INPUT_ID = "a8748df4938447e4844b2f505c8eaaef";
const CONCEPT_ID_1 = "tree";
const CONCEPT_ID_2 = "water";
const CONCEPT_ID_3 = "bike";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"annotations": [
{
"input_id": INPUT_ID,
"data": {
"regions": [
{
"region_info": {
"polygon": {
"points": [
{
"row": 0.30
},
{
"col": 0.50
},
{
"z": 0.50
}
]
}
},
"data": {
// 1 means true, this concept is present
// 0 means false, this concept is not present
"concepts": [
{
"id": CONCEPT_ID_1,
"value": 1
},
{
"id": CONCEPT_ID_2,
"value": 0
}
]
}
}
]
}
}, {
"input_id": INPUT_ID,
"data": {
"regions": [
{
"region_info": {
"polygon": {
"points": [
{
"row": 0.60
},
{
"col": 0.80
},
{
"z": 0.50
}
]
}
},
"data": {
"concepts": [
{
"id": CONCEPT_ID_3,
"value": 1
}
]
}
}
]
}
}
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/annotations", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// a polygon. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the polygon you want to annotate
const INPUT_ID = "c9cbb1c90cf24bc98bfd2e529e744ca9";
const CONCEPT_ID_1 = "tree";
const CONCEPT_ID_2 = "water";
const CONCEPT_ID_3 = "bike";
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
annotations: [
{ // label a region in this image
input_id: INPUT_ID,
data: {
regions: [
{
region_info: {
polygon: { // draw a polygon
points: [
{
row: 0.30 // row location of the point, with a [0.0-1.0] range
},
{
col: 0.50 // column location of the point, with a [0.0-1.0] range
},
{
z: 0.50 // depth, if applicable, of the point
}
]
}
},
// 1 means true, this concept is present
// 0 means false, this concept is not present
data: {
concepts: [
{ id: CONCEPT_ID_1, value: 1 },
{ id: CONCEPT_ID_2, value: 0 }
]
},
}
]
}
}, { // label another region in this image
input_id: INPUT_ID,
data: {
regions: [
{
region_info: {
polygon: { // draw another polygon
points: [
{
row: 0.60
},
{
col: 0.80
},
{
z: 0.50
}
]
}
},
// 1 means true, this concept is present
// 0 means false, this concept is not present
data: {
concepts: [
{ id: CONCEPT_ID_3, value: 1 },
]
},
}
]
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post annotations failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// a polygon. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the polygon you want to annotate
static final String INPUT_ID = "c9cbb1c90cf24bc98bfd2e529e744ca9";
static final String CONCEPT_ID_1 = "tree";
static final String CONCEPT_ID_2 = "water";
static final String CONCEPT_ID_3 = "bike";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiAnnotationResponse postAnnotationsResponse = stub.postAnnotations(
PostAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addAnnotations(
Annotation.newBuilder() // label a region in this image
.setInputId(INPUT_ID)
.setData(
Data.newBuilder().addRegions(
Region.newBuilder()
.setRegionInfo(
RegionInfo.newBuilder()
.setPolygon( // draw a polygon
Polygon.newBuilder()
.addPoints(Point.newBuilder().setRow(0.3f)) // row location of the point, with a [0.0-1.0] range
.addPoints(Point.newBuilder().setCol(0.5f)) // column location of the point, with a [0.0-1.0] range
.addPoints(Point.newBuilder().setZ(0.5f)) // depth, if applicable, of the point
.build()
)
.build()
)
.setData(
Data.newBuilder()
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_1)
.setValue(1f) // 1 means true, this concept is present
.build()
)
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_2)
.setValue(0f) // 0 means false, this concept is not present
.build()
)
).build()
).build()
)
.build()
)
.addAnnotations( // label another region in this image
Annotation.newBuilder()
.setInputId(INPUT_ID)
.setData(
Data.newBuilder().addRegions(
Region.newBuilder()
.setRegionInfo(
RegionInfo.newBuilder()
.setPolygon( // draw another polygon
Polygon.newBuilder()
.addPoints(Point.newBuilder().setRow(0.6f))
.addPoints(Point.newBuilder().setCol(0.8f))
.addPoints(Point.newBuilder().setZ(0.5f))
.build()
)
.build()
)
.setData(
Data.newBuilder()
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_3)
.setValue(1f) // 1 means true, this concept is present
.build()
)
).build()
).build()
).build()
).build()
);
if (postAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post annotations failed, status: " + postAnnotationsResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// a polygon. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the polygon you want to annotate
$INPUT_ID = "a8748df4938447e4844b2f505c8eaaef";
$CONCEPT_ID_1 = "tree";
$CONCEPT_ID_2 = "water";
$CONCEPT_ID_3 = "bike";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostAnnotationsRequest;
use Clarifai\Api\Annotation;
use Clarifai\Api\Concept;
use Clarifai\Api\Data;
use Clarifai\Api\Point;
use Clarifai\Api\Polygon;
use Clarifai\Api\Region;
use Clarifai\Api\RegionInfo;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PostAnnotations(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostAnnotationsRequest([
"user_app_id" => $userDataObject,
"annotations" => [
new Annotation([
"input_id" => $INPUT_ID,
"data" => new Data([
"regions" => [
new Region([
"region_info" => new RegionInfo([
"polygon" => new Polygon([ // draw a polygon
"points" => [
new Point(["row" => 0.30]), // row location of the point, with a [0.0-1.0] range
new Point(["col" => 0.50]), // column location of the point, with a [0.0-1.0] range
new Point(["z" => 0.50]) // depth, if applicable, of the point
]
])
]),
"data" => new Data([
"concepts" => [
new Concept([ "id" => $CONCEPT_ID_1, "value" => 1. ]), // 1 means true, this concept is present
new Concept([ "id" => $CONCEPT_ID_2, "value" => 0. ]), // 0 means false, this concept is not present
]
])
])
]
])
]),
new Annotation([
"input_id" => $INPUT_ID,
"data" => new Data([
"regions" => [
new Region([
"region_info" => new RegionInfo([
"polygon" => new Polygon([ // draw another polygon
"points" => [
new Point(["row" => 0.60]),
new Point(["col" => 0.80]),
new Point(["z" => 0.50])
]
])
]),
"data" => new Data([
"concepts" => [
new Concept([ "id" => $CONCEPT_ID_3, "value" => 1. ]), // 1 means true, this concept is present
]
])
])
]
])
])
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
?>
# Value of 1 means true, this concept is present
# Value of 0 means false, this concept is not present
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"annotations": [
{
"input_id": "YOUR_INPUT_ID_HERE",
"data": {
"regions": [
{
"region_info": {
"polygon": {
"points": [
{
"row": 0.30
},
{
"col": 0.50
},
{
"z": 0.50
}
]
}
},
"data": {
"concepts": [
{
"id": "YOUR_CONCEPT_ID_1",
"value": 1
},
{
"id": "YOUR_CONCEPT_ID_2",
"value": 0
}
]
}
}
]
}
}, {
"input_id": "YOUR_INPUT_ID_HERE",
"data": {
"regions": [
{
"region_info": {
"polygon": {
"points": [
{
"row": 0.60
},
{
"col": 0.80
},
{
"z": 0.50
}
]
}
},
"data": {
"concepts": [
{
"id": "YOUR_CONCEPT_ID_3",
"value": 1
}
]
}
}
]
}
}
]
}'
Annotate Existing Regions in an Image
When you add an input, detection models (such as Face Detection
or General Detection
) will detect regions in your image where there appear to be relevant objects. You can get the IDs of these detected regions by listing model's annotations.
Your labels should be contained within Region.data
. Each annotation can only have 1 region. If you want to label multiple regions, it is possible to label multiple annotations in a single API call.
Below is an example of how to annotate existing regions in an image.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
########################################################################################
# In this section, we set the user authentication, app ID, and how we want to annotate
# existing regions in an image. Change these strings to run your own example.
#########################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the existing regions you want to annotate
INPUT_ID = "53d0362a9dfa4e03b2293375e2d0db73"
CONCEPT_ID_1 = "tree"
CONCEPT_ID_2 = "water"
CONCEPT_ID_3 = "bike"
REGION_ID_1 = "361d6a9253be9152968012660258a4bf"
REGION_ID_2 = "dcfa961b753f3b197d0bf7b242718ab1"
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
post_annotations_response = stub.PostAnnotations(
service_pb2.PostAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
annotations=[
resources_pb2.Annotation( # label a region in this image
input_id=INPUT_ID,
data=resources_pb2.Data(
regions=[
resources_pb2.Region(
id=REGION_ID_1, # this should be a region id returned from list annotations call
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_1, value=1.), # 1 means true, this concept is present.
resources_pb2.Concept(id=CONCEPT_ID_2, value=0.) # 0 means false, this concept is not present.
]
)
)
]
)
),
resources_pb2.Annotation( # label another region in this image
input_id=INPUT_ID,
data=resources_pb2.Data(
regions=[
resources_pb2.Region(
id=REGION_ID_2 , # this should be a region id returned from list annotations call
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_3, value=1.), # 1 means true, this concept is present.
]
)
)
]
)
),
]
),
metadata=metadata
)
if post_annotations_response.status.code != status_code_pb2.SUCCESS:
print(post_annotations_response.status)
raise Exception("Post annotations failed, status: " + post_annotations_response.status.description)
<!--index.html file-->
<script>
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// existing regions in an image. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the existing regions you want to annotate
const INPUT_ID = "c9cbb1c90cf24bc98bfd2e529e744ca9";
const CONCEPT_ID_1 = "tree";
const CONCEPT_ID_2 = "water";
const CONCEPT_ID_3 = "bike";
const REGION_ID_1 = "361d6a9253be9152968012660258a4bf";
const REGION_ID_2 = "dcfa961b753f3b197d0bf7b242718ab1";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"annotations": [
{
"input_id": INPUT_ID,
"data": {
"regions": [
{
"id": REGION_ID_1,
"data": {
"concepts": [
{
"id": CONCEPT_ID_1,
"value": 1
},
{
"id": CONCEPT_ID_2,
"value": 0
}
]
}
}
]
}
}, {
"input_id": INPUT_ID,
"data": {
"regions": [
{
"id": REGION_ID_2,
"data": {
"concepts": [
{
"id": CONCEPT_ID_3,
"value": 1
}
]
}
}
]
}
}
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/annotations", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// existing regions in an image. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the existing regions you want to annotate
const INPUT_ID = "c9cbb1c90cf24bc98bfd2e529e744ca9";
const CONCEPT_ID_1 = "tree";
const CONCEPT_ID_2 = "water";
const CONCEPT_ID_3 = "bike";
const REGION_ID_1 = "361d6a9253be9152968012660258a4bf";
const REGION_ID_2 = "dcfa961b753f3b197d0bf7b242718ab1";
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
annotations: [
{ // label a region in this image
input_id: INPUT_ID,
data: {
regions: [
{
id: REGION_ID_1, // this should be a region id returned from list annotations call
// 1 means true, this concept is present.
// 0 means false, this concept is not present.
data: {
concepts: [
{ id: CONCEPT_ID_1, value: 1 },
{ id: CONCEPT_ID_2, value: 0 }
]
},
}
]
}
}, { // label another region in this image
input_id: INPUT_ID,
data: {
regions: [
{
id: REGION_ID_2, // this should be a region id returned from list annotations call
// 1 means true, this concept is present.
// 0 means false, this concept is not present.
data: {
concepts: [
{ id: CONCEPT_ID_3, value: 1 },
]
},
}
]
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post annotations failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// existing regions in an image. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the existing regions you want to annotate
static final String INPUT_ID = "c9cbb1c90cf24bc98bfd2e529e744ca9";
static final String CONCEPT_ID_1 = "tree";
static final String CONCEPT_ID_2 = "water";
static final String CONCEPT_ID_3 = "bike";
static final String REGION_ID_1 = "361d6a9253be9152968012660258a4bf";
static final String REGION_ID_2 = "dcfa961b753f3b197d0bf7b242718ab1";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiAnnotationResponse postAnnotationsResponse = stub.postAnnotations(
PostAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addAnnotations(
Annotation.newBuilder() // label a region in this image
.setInputId(INPUT_ID)
.setData(
Data.newBuilder().addRegions(
Region.newBuilder()
.setId(REGION_ID_1) // this should be a region id returned from list annotations call
.setData(
Data.newBuilder().addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_1)
.setValue(1f) // 1 means true, this concept is present
.build()
).addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_2)
.setValue(0f) // 0 means false, this concept is not present
.build()
)
).build()
).build()
)
.build()
).addAnnotations(
Annotation.newBuilder() // label another region in the same image
.setInputId(INPUT_ID)
.setData(
Data.newBuilder().addRegions(
Region.newBuilder()
.setId(REGION_ID_2) // this should be a region id returned from list annotations call
.setData(
Data.newBuilder().addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_3)
.setValue(1f) // 1 means true, this concept is present
.build()
)
).build()
).build()
).build()
).build()
);
if (postAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post annotations failed, status: " + postAnnotationsResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// existing regions in an image. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the existing regions you want to annotate
$INPUT_ID = "c9cbb1c90cf24bc98bfd2e529e744ca9";
$CONCEPT_ID_1 = "tree";
$CONCEPT_ID_2 = "water";
$CONCEPT_ID_3 = "bike";
$REGION_ID_1 = "361d6a9253be9152968012660258a4bf";
$REGION_ID_2 = "dcfa961b753f3b197d0bf7b242718ab1";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostAnnotationsRequest;
use Clarifai\Api\Annotation;
use Clarifai\Api\Concept;
use Clarifai\Api\Data;
use Clarifai\Api\Region;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PostAnnotations(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostAnnotationsRequest([
"user_app_id" => $userDataObject,
"annotations" => [
new Annotation([ // label a region in this image
"input_id" => $INPUT_ID,
"data" => new Data([
"regions" => [
new Region([
"id" => $REGION_ID_1, // this should be a region id returned from list annotations call
"data" => new Data([
"concepts" => [
new Concept([ "id" => $CONCEPT_ID_1, "value" => 1. ]), // 1 means true, this concept is present
new Concept([ "id" => $CONCEPT_ID_2, "value" => 0. ]), // 0 means false, this concept is not present
]
])
])
]
])
]),
new Annotation([ // label another region in this image
"input_id" => $INPUT_ID,
"data" => new Data([
"regions" => [
new Region([
"id" => $REGION_ID_2, // this should be a region id returned from list annotations call
"data" => new Data([
"concepts" => [
new Concept([ "id" => $CONCEPT_ID_3, "value" => 1. ]), // 1 means true, this concept is present
]
])
])
]
])
])
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
?>
# Value of 1 means true, this concept is present
# Value of 0 means false, this concept is not present
# Region ID should be the region ID returned from a list annotations call
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"annotations": [
{
"input_id": "YOUR_INPUT_ID_HERE",
"data": {
"regions": [
{
"id": "REGION_ID_1",
"data": {
"concepts": [
{
"id": "tree",
"value": 1
},
{
"id": "water",
"value": 0
}
]
}
}
]
}
}, {
"input_id": "YOUR_INPUT_ID_HERE",
"data": {
"regions": [
{
"id": "REGION_ID_2",
"data": {
"concepts": [
{
"id": "bike",
"value": 1
}
]
}
}
]
}
}
]
}'
Annotate Images With Mask
Below is an example of how to add a mask to an Image using a single API call. In this example, we provide an image mask as a base64
string.
Click here to learn more about image mask annotations.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
#########################################################################################
# In this section, we set the user authentication, app ID, and how we want to create an
# image mask. Change these strings to run your own example.
#########################################################################################
# Your user and app ID
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the new bounding boxes you want to annotate
INPUT_ID = "INPUT_ID_FROM_UI"
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.grpc.api.status import status_code_pb2
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
post_annotations_response = stub.PostAnnotations(
service_pb2.PostAnnotationsRequest(
# The userDataObject is created in the overview and is required when using a PAT
user_app_id=userDataObject,
annotations=[
resources_pb2.Annotation(
input_id=INPUT_ID,
data=resources_pb2.Data(
regions=[
resources_pb2.Region(
region_info=resources_pb2.RegionInfo(
mask=resources_pb2.Mask(
image=resources_pb2.Image(
base64=b"iVBORw0KGgoAAAANSUhEUgAAA6YAAAJLCAAAAADRRNTfAAAK8ElEQVR4nOzd227cVrpG0a0Nv/8ru9FWx4gtlcRi8TB/cozLIBdC5I9zLaoi////AXFmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnk/zv4CuJyfZ38Bb2d/AZtTU8i73oOHVU5P4G6u8EdcTSHvCo8annbddn5t6h93NYW8qY8XnnPXfD4y7M+9mkLesKcKi+nnIjMGMOOrZDHrXCG/AodeyMs/R1hKR18U3oKaQl74CcJSOrqh5CLUFPKSzw4WE9J9xHahppAXe2rwDCndWWYdagp5mecFz9DRozQG0vgqeIaNHiuwEYdeyAs8KXiGlJ7h7JmoKeT5Pb2TSOlNqSnknX3oZjEpPdO5Q1FTyFPTA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c9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIe8/AQAA//+1OJOq3RUbswAAAABJRU5ErkJggg=="
),
)
),
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id="CONCEPT_ID_FROM_UI", value=1), # 1 means true, this concept is present
]
)
)
]
)
)
]
),
metadata=metadata
)
if post_annotations_response.status.code != status_code_pb2.SUCCESS:
print(post_annotations_response.status)
raise Exception("Post annotations failed, status: " + post_annotations_response.status.description)
<!--index.html file-->
<script>
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// an image mask. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the input you want to annotate
const INPUT_ID = 'INPUT_ID_FROM_UI';
const CONCEPT_ID = 'CONCEPT_ID_FROM_UI';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"annotations": [
{
"input_id": INPUT_ID,
"data": {
"regions": [
{
"region_info": {
"mask": {
"image": {
"base64":"iVBORw0KGgoAAAANSUhEUgAAA6YAAAJLCAAAAADRRNTfAAAK8ElEQVR4nOzd227cVrpG0a0Nv/8ru9FWx4gtlcRi8TB/cozLIBdC5I9zLaoi////AXFmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnk/zv4CuJyfZ38Bb2d/AZtTU8i73oOHVU5P4G6u8EdcTSHvCo8annbddn5t6h93NYW8qY8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8k57pirrCRR0KDWFvMLzVVh3VfgW85rg99BqNxH8zrKWQy/k9Z+54rpQ/1vJWmoKeTMfwQr7y8xvHs9TU8i7zgP52oW9zveJFdQU8m7xlE6H9hbfAV6jppDnWf7YlhH23xngyhx6Ic9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIe8/AQAA//+1OJOq3RUbswAAAABJRU5ErkJggg=="
}
}
},
"data": {
"concepts": [
{
"id": CONCEPT_ID,
"value": 1 // 1 means true, this concept is present
}
]
}
}
]
}
}
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT,
'Content-Type': 'application/json'
},
body: raw
};
fetch("https://api.clarifai.com/v2/annotations", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// an image mask. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the input you want to annotate
const INPUT_ID = 'INPUT_ID_FROM_UI';
const CONCEPT_ID = 'CONCEPT_ID_FROM_UI';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostAnnotations(
{
user_app_id: {
user_id: USER_ID,
app_id: APP_ID
},
annotations: [
{
input_id: INPUT_ID,
data: {
regions: [
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qTlP6LmkKemlKkpX9QU8hTU3Kk9G9qCnlqSouUfsJMCbHRzzn0Qp6aUiGlD6kp5Kkp59PRb6gp5KkpJ5PS76kp5Kkpp9HRpdQU8tSUE+joc8yUY1noCg69kKemHEVHV1NTyFNTdiair1NTyFNTdqCg21JTyFNTNqSi+1BTyFNTNqGje/rvf92fZ38RTGag+3Pohby/H4XKymI6ehQ1hbwvHojCyqdE9HBqCnkLn4zKio6eR00hb93zUVxvRELPp6aQt8WjUluvSERDtv5mmOxw1lnk0At5uz08ZXUWFS1TU8jb/SGqqmkiOoKaQt6hT1NlDdHRQdQU8k57pirrCRR0KDWFvMLzVVh3VfgW85rg99BqNxH8zrKWQy/k9Z+54rpQ/1vJWmoKeTMfwQr7y8xvHs9TU8i7zgP52oW9zveJFdQU8m7xlE6H9hbfAV6jppDnWf7YlhH23xngyhx6Ic9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIe8/AQAA//+1OJOq3RUbswAAAABJRU5ErkJggg=="
}
}
},
data: {
concepts: [
{
id: CONCEPT_ID,
value: 1 // 1 means true, this concept is present
}
]
}
}
]
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post annotations failed, status: " + response.status.description);
}
console.log("Post annotations succeeded");
}
);
package com.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.StatusCode;
import com.google.protobuf.ByteString;
public class annotate_mask {
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to
////////////////////////////////////////////////////////////////////////////////////////// annotate
// an image mask. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the portal under
// Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the input you want to annotate
static final String INPUT_ID = "INPUT_ID_FROM_UI";
static final String CONCEPT_ID = "CONCEPT_ID_FROM_UI";
static final String myString = "iVBORw0KGgoAAAANSUhEUgAAA6YAAAJLCAAAAADRRNTfAAAK8ElEQVR4nOzd227cVrpG0a0Nv/8ru9FWx4gtlcRi8TB/cozLIBdC5I9zLaoi////AXFmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnk/zv4CuJyfZ38Bb2d/AZtTU8i73oOHVU5P4G6u8EdcTSHvCo8annbddn5t6h93NYW8qY8XnnPXfD4y7M+9mkLesKcKi+nnIjMGMOOrZDHrXCG/AodeyMs/R1hKR18U3oKaQl74CcJSOrqh5CLUFPKSzw4WE9J9xHahppAXe2rwDCndWWYdagp5mecFz9DRozQG0vgqeIaNHiuwEYdeyAs8KXiGlJ7h7JmoKeT5Pb2TSOlNqSnknX3oZjEpPdO5Q1FTyFPTAXQ04cStqCnkqWmdlIacNRczTbPRnFMW49ALeWoapqVNx49GTSHPhwWrpJTf1BTy3E2TpDTu4N2oKeSpaY+UjnDkdNQU8swU8hx6Y5x4BzlsPWoKeWpaIqXjHDMgNYU8HxbMkFIeUVPIczdtkNK5DtiQmkKemgZI6XR7z0hNIc+b3rNJKd9y6D2VjV7Grkty6IU8h17Yws89g6qmkKem53ExZSE1hTxves+ipRe015zUFPLU9BRSelm7LEpNIU9Njyel17fxrsz0YDZ6F1tOy6EX8tT0SFJ6RxtsTE0hz4cFYV+/z1Drs6qmkOduuo0/b52f/ld1MeXd86NTU8hT01c9iOTbon+L+3pmemoKed70vmRZJKWU1zj0rvfd+t4W/Vvc1+L1OfRCnkPvSo67HEdNIU9N15BSDqWmkKemcJbFvylfTSFPTZ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PIM1PIM1PIM1PI8wMZRrjxT2PUFCYwU8gzU8gzU8gzU8gzU8jzAxn67v3TGDWFCcwU8swU8txNibv9xVRNYQIzhTwzhTx3U8pcTH9RU8gzU8hz6CXLifcfagp5akqTlP6LmkKemlKkpX9QU8hTU3Kk9G9qCnlqSouUfsJMCbHRzzn0Qp6aUiGlD6kp5Kkp59PRb6gp5KkpJ5PS76kp5Kkpp9HRpdQU8tSUE+joc8yUY1noCg69kKemHEVHV1NTyFNTdiair1NTyFNTdqCg21JTyFNTNqSi+1BTyFNTNqGje/rvf92fZ38RTGag+3Pohby/H4XKymI6ehQ1hbwvHojCyqdE9HBqCnkLn4zKio6eR00hb93zUVxvRELPp6aQt8WjUluvSERDtv5mmOxw1lnk0At5uz08ZXUWFS1TU8jb/SGqqmkiOoKaQt6hT1NlDdHRQdQU8k57pirrCRR0KDWFvMLzVVh3VfgW85rg99BqNxH8zrKWQy/k9Z+54rpQ/1vJWmoKeTMfwQr7y8xvHs9TU8i7zgP52oW9zveJFdQU8m7xlE6H9hbfAV6jppDnWf7YlhH23xngyhx6Ic9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIe8/AQAA//+1OJOq3RUbswAAAABJRU5ErkJggg==";
static final ByteString byteString = ByteString.copyFrom(myString.getBytes());
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiAnnotationResponse postAnnotationsResponse = stub.postAnnotations(
PostAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addAnnotations(
Annotation.newBuilder()
.setInputId(INPUT_ID)
.setData(
Data.newBuilder().addRegions(
Region.newBuilder()
.setRegionInfo(
RegionInfo.newBuilder()
.setMask( // draw a mask
Mask.newBuilder()
.setImage(
Image.newBuilder()
.setBase64(
byteString)
.build())
.build())
.build())
.setData(
Data.newBuilder()
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID)
.setValue(1f) // 1 means
// true,
// this
// concept
// is
// present
.build()))
.build())
.build())
.build())
.build());
if (postAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post annotations failed, status: " + postAnnotationsResponse.getStatus());
}
System.out.println("Post annotations succeeded");
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
require 'vendor/autoload.php';
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// an image mask. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the input you want to annotate
$INPUT_ID = "INPUT_ID_FROM_UI";
$CONCEPT_ID = "CONCEPT_ID_FROM_UI";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostAnnotationsRequest;
use Clarifai\Api\Annotation;
use Clarifai\Api\Concept;
use Clarifai\Api\Image;
use Clarifai\Api\Data;
use Clarifai\Api\Mask;
use Clarifai\Api\Region;
use Clarifai\Api\RegionInfo;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Create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9RU8gzU8hz6CXLifcfagp5akqTlP6LmkKemlKkpX9QU8hTU3Kk9G9qCnlqSouUfsJMCbHRzzn0Qp6aUiGlD6kp5Kkp59PRb6gp5KkpJ5PS76kp5Kkpp9HRpdQU8tSUE+joc8yUY1noCg69kKemHEVHV1NTyFNTdiair1NTyFNTdqCg21JTyFNTNqSi+1BTyFNTNqGje/rvf92fZ38RTGag+3Pohby/H4XKymI6ehQ1hbwvHojCyqdE9HBqCnkLn4zKio6eR00hb93zUVxvRELPp6aQt8WjUluvSERDtv5mmOxw1lnk0At5uz08ZXUWFS1TU8jb/SGqqmkiOoKaQt6hT1NlDdHRQdQU8k57pirrCRR0KDWFvMLzVVh3VfgW85rg99BqNxH8zrKWQy/k9Z+54rpQ/1vJWmoKeTMfwQr7y8xvHs9TU8i7zgP52oW9zveJFdQU8m7xlE6H9hbfAV6jppDnWf7YlhH23xngyhx6Ic9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIe8/AQAA//+1OJOq3RUbswAAAABJRU5ErkJggg=="
])
]);
// Define the annotation with the mask
$annotation = new Annotation([
"input_id" => $INPUT_ID,
"data" => new Data([
"regions" => [
new Region([
"region_info" => new RegionInfo([
"mask" => $mask
]),
"data" => new Data([
"concepts" => [
new Concept([
"id" => $CONCEPT_ID,
"value" => 1.0 // 1 means true, this concept is present
])
]
])
])
]
])
]);
// Let's make a RPC call to the Clarifai platform
[$response, $status] = $client->PostAnnotations(
new PostAnnotationsRequest([
"user_app_id" => $userDataObject,
"annotations" => [$annotation]
]),
$metadata
)->wait();
// Check the status of the response
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
echo "Post annotations succeeded";
?>
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"annotations": [
{
"input_id": "INPUT_ID_FROM_UI",
"data": {
"regions": [
{
"region_info": {
"mask": {
"image": {
"base64": "iVBORw0KGgoAAAANSUhEUgAAA6YAAAJLCAAAAADRRNTfAAAK8ElEQVR4nOzd227cVrpG0a0Nv/8ru9FWx4gtlcRi8TB/cozLIBdC5I9zLaoi////AXFmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnk/zv4CuJyfZ38Bb2d/AZtTU8i73oOHVU5P4G6u8EdcTSHvCo8annbddn5t6h93NYW8qY8XnnPXfD4y7M+9mkLesKcKi+nnIjMGMOOrZDHrXCG/AodeyMs/R1hKR18U3oKaQl74CcJSOrqh5CLUFPKSzw4WE9J9xHahppAXe2rwDCndWWYdagp5mecFz9DRozQG0vgqeIaNHiuwEYdeyAs8KXiGlJ7h7JmoKeT5Pb2TSOlNqSnknX3oZjEpPdO5Q1FTyFPTAXQ04cStqCnkqWmdlIacNRczTbPRnFMW49ALeWoapqVNx49GTSHPhwWrpJTf1BTy3E2TpDTu4N2oKeSpaY+UjnDkdNQU8swU8hx6Y5x4BzlsPWoKeWpaIqXjHDMgNYU8HxbMkFIeUVPIczdtkNK5DtiQmkKemgZI6XR7z0hNIc+b3rNJKd9y6D2VjV7Grkty6IU8h17Yws89g6qmkKem53ExZSE1hTxves+ipRe015zUFPLU9BRSelm7LEpNIU9Njyel17fxrsz0YDZ6F1tOy6EX8tT0SFJ6RxtsTE0hz4cFYV+/z1Drs6qmkOduuo0/b52f/ld1MeXd86NTU8hT01c9iOTbon+L+3pmemoKed70vmRZJKWU1zj0rvfd+t4W/Vvc1+L1OfRCnkPvSo67HEdNIU9N15BSDqW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hTxvepnirq951RQmMFPIM1PIM1PIM1PIM1PI8wMZRrjxT2PUFCYwU8gzU8gzU8gzU8gzU8jzAxn67v3TGDWFCcwU8swU8txNibv9xVRNYQIzhTwzhTx3U8pcTH9RU8gzU8hz6CXLifcfagp5akqTlP6LmkKemlKkpX9QU8hTU3Kk9G9qCnlqSouUfsJMCbHRzzn0Qp6aUiGlD6kp5Kkp59PRb6gp5KkpJ5PS76kp5Kkpp9HRpdQU8tSUE+joc8yUY1noCg69kKemHEVHV1NTyFNTdiair1NTyFNTdqCg21JTyFNTNqSi+1BTyFNTNqGje/rvf92fZ38RTGag+3Pohby/H4XKymI6ehQ1hbwvHojCyqdE9HBqCnkLn4zKio6eR00hb93zUVxvRELPp6aQt8WjUluvSERDtv5mmOxw1lnk0At5uz08ZXUWFS1TU8jb/SGqqmkiOoKaQt6hT1NlDdHRQdQU8k57pirrCRR0KDWFvMLzVVh3VfgW85rg99BqNxH8zrKWQy/k9Z+54rpQ/1vJWmoKeTMfwQr7y8xvHs9TU8i7zgP52oW9zveJFdQU8m7xlE6H9hbfAV6jppDnWf7YlhH23xngyhx6Ic9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIe8/AQAA//+1OJOq3RUbswAAAABJRU5ErkJggg==" }
}
},
"data": {
"concepts": [
{
"id": "CONCEPT_ID_FROM_UI",
"value": 1
}
]
}
}
]
}
}
]
}'
Annotate Images With Different user_id
and status
Each annotation is tied to a user or a model in your workflow. By default, when a user posts an annotation, this user is the owner of the annotation.
Sometimes, however, you might want to post an annotation as another user; for example, when assigning an image to another user. In such a case, you can create an annotation with another user_id
(and status PENDING
).
Only the app owner can post an annotation with other user's user_id
; collaborators cannot.
Below is an example of how to annotate images with different user_id
and status
.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
#########################################################################
# In this section, we set the user authentication, app ID, input ID,
# and another user ID. Change these strings to run your own example.
#########################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to post your own annotations
INPUT_ID = 'e838fac8da9d40c89f2291a6496593da'
ANOTHER_USER_ID = 'ANOTHER_USER_ID_HERE'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2, status_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID) # The userDataObject is created in the overview and is required when using a PAT
post_annotations_response = stub.PostAnnotations(
service_pb2.PostAnnotationsRequest(
user_app_id=userDataObject,
annotations=[
resources_pb2.Annotation(
input_id=INPUT_ID,
user_id=ANOTHER_USER_ID, # If empty, it is the user who posts this annotation
status=status_pb2.Status(
code=status_code_pb2.ANNOTATION_PENDING # annotation pending status. By default success.
),
)
]
),
metadata=metadata
)
if post_annotations_response.status.code != status_code_pb2.SUCCESS:
print(post_annotations_response.status)
raise Exception("Post annotations failed, status: " + post_annotations_response.status.description)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID,
// and another user ID. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to post your own annotations
const INPUT_ID = 'c9cbb1c90cf24bc98bfd2e529e744ca9';
const ANOTHER_USER_ID = 'ANOTHER_USER_ID_HERE';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"annotations": [
{
"input_id": INPUT_ID,
"user_id": ANOTHER_USER_ID,
"status": {
"code": "ANNOTATION_PENDING"
}
}
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/annotations", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID,
// and another user ID. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to post your own annotations
const INPUT_ID = 'c9cbb1c90cf24bc98bfd2e529e744ca9';
const ANOTHER_USER_ID = 'ANOTHER_USER_ID_HERE';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
annotations: [
{
input_id: INPUT_ID,
user_id: ANOTHER_USER_ID, // If empty, it is the user who posts this annotation
status: {
code: 24151 // annotation pending status. By default success.
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post annotations failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.Status;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
//////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID,
// and another user ID. Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to post your own annotations
static final String INPUT_ID = "c9cbb1c90cf24bc98bfd2e529e744ca9";
static final String ANOTHER_USER_ID = "ANOTHER_USER_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiAnnotationResponse postAnnotationsResponse = stub.postAnnotations(
PostAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addAnnotations(
Annotation.newBuilder()
.setInputId(INPUT_ID)
.setUserId(ANOTHER_USER_ID) // If empty, it is the user who posts this annotation
.setStatus(
Status.newBuilder()
.setCodeValue(StatusCode.ANNOTATION_PENDING_VALUE) // annotation pending status. By default, it's ANNOTATION_SUCCESS_VALUE
.build()
)
.build()
).build()
);
if (postAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post annotations failed, status: " + postAnnotationsResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID,
// and another user ID. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these to post your own annotations
$INPUT_ID = "c9cbb1c90cf24bc98bfd2e529e744ca9";
$ANOTHER_USER_ID = "ANOTHER_USER_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostAnnotationsRequest;
use Clarifai\Api\Annotation;
use Clarifai\Api\Status\Status;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PostAnnotations(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostAnnotationsRequest([
"user_app_id" => $userDataObject,
"annotations" => [
new Annotation([
"input_id" => $INPUT_ID,
"user_id" => $ANOTHER_USER_ID, // If empty, it is the user who posts this annotation
"status" => new Status([
"code" => StatusCode::ANNOTATION_PENDING // Annotation pending status. By default success
])
])
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
?>
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"annotations": [
{
"input_id": "YOUR_INPUT_ID_HERE",
"user_id": "ANOTHER_USER_ID_HERE",
"status": {
"code": "ANNOTATION_PENDING"
}
}
]
}'
List Annotations
You can get a list of annotations within your app with a GET call. Annotations will be returned from oldest to newest.
These requests are paginated. By default each page will return 20 annotations.
List All User Created Annotations in Your App
Below is an example of how to list all your user labelled annotations.
This will not show annotations by models in your workflow. To include model created annotations, you need to set list_all_annotations
to True
.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
##################################################################
# In this section, we set the user authentication and app ID.
# Change these strings to run your own example.
##################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
list_annotations_response = stub.ListAnnotations(
service_pb2.ListAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
per_page=10
),
metadata=metadata
)
if list_annotations_response.status.code != status_code_pb2.SUCCESS:
print(list_annotations_response.status)
raise Exception("List annotations failed, status: " + list_annotations_response.status.description)
for annotation_object in list_annotations_response.annotations:
print(annotation_object)
<!--index.html file-->
<script>
/////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const requestOptions = {
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
}
};
fetch(`https://api.clarifai.com/v2/users/${USER_ID}/apps/${APP_ID}/annotations?page=1&per_page=10`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
/////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.ListAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
page: 1,
per_page: 10
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("List annotations failed, status: " + response.status.description);
}
for (const annotation of response.annotations) {
console.log(JSON.stringify(annotation, null, 2));
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
///////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiAnnotationResponse listAnnotationsResponse = stub.listAnnotations(
ListAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setPerPage(10)
.setPage(1) // Pages start at 1
.build()
);
if (listAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("List annotations failed, status: " + listAnnotationsResponse.getStatus());
}
for (Annotation annotation: listAnnotationsResponse.getAnnotationsList()) {
System.out.println(annotation);
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
/////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\ListAnnotationsRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->ListAnnotations(
// The request object carries the request along with the request status and other metadata related to the request itself
new ListAnnotationsRequest([
"user_app_id" => $userDataObject,
"per_page" => 10
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
foreach ($response->getAnnotations() as $annotation_object) {
echo $annotation_object->SerializeToJSONString() . "</br>";
}
?>
curl -X GET "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations?page=1&per_page=10" \
-H "Authorization: Key YOUR_PAT_HERE"
List All Annotations in Your App
Below is an example of how to list all annotations, including those created by models.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
##################################################################
# In this section, we set the user authentication and app ID.
# Change these strings to run your own example.
##################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
list_annotations_response = stub.ListAnnotations(
service_pb2.ListAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
per_page=10,
list_all_annotations=True
),
metadata=metadata
)
if list_annotations_response.status.code != status_code_pb2.SUCCESS:
print(list_annotations_response.status)
raise Exception("List annotations failed, status: " + list_annotations_response.status.description)
for annotation_object in list_annotations_response.annotations:
print(annotation_object)
<!--index.html file-->
<script>
/////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const requestOptions = {
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
}
};
fetch(`https://api.clarifai.com/v2/users/${USER_ID}/apps/${APP_ID}/annotations?page=1&per_page=10&list_all_annotations=true`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
/////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.ListAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
list_all_annotations: true,
page: 1,
per_page: 10
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("List annotations failed, status: " + response.status.description);
}
for (const annotation of response.annotations) {
console.log(JSON.stringify(annotation, null, 2));
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.*;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
///////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiAnnotationResponse listAnnotationsResponse = stub.listAnnotations(
ListAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setPerPage(10)
.setListAllAnnotations(true)
.setPage(1) // Pages start at 1
.build()
);
if (listAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("List annotations failed, status: " + listAnnotationsResponse.getStatus());
}
for (Annotation annotation: listAnnotationsResponse.getAnnotationsList()) {
System.out.println(annotation);
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
/////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\ListAnnotationsRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->ListAnnotations(
// The request object carries the request along with the request status and other metadata related to the request itself
new ListAnnotationsRequest([
"user_app_id" => $userDataObject,
"per_page" => 10,
"list_all_annotations" => true
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
foreach ($response->getAnnotations() as $annotation_object) {
echo $annotation_object->SerializeToJSONString() . "</br>";
}
?>
curl -X GET "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations?page=1&per_page=10&list_all_annotations=true" \
-H "Authorization: Key YOUR_PAT_HERE"
List User Created Annotations by Input IDs
Below is an example of how to list all user created annotations for certain input (one or several) by providing a list of input IDs.
This will not show annotations by models in your workflow. To include model created annotations, you need to set list_all_annotations
to True
.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
#########################################################################
# In this section, we set the user authentication, app ID, and input IDs
# Change these strings to run your own example.
#########################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to list your own annotations
INPUT_ID_1 = '53d0362a9dfa4e03b2293375e2d0db73'
INPUT_ID_2 = '00f6d742124147ac8ca7788f73736fb9'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
list_annotations_response = stub.ListAnnotations(
service_pb2.ListAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
input_ids=[INPUT_ID_1, INPUT_ID_2],
per_page=10
),
metadata=metadata
)
if list_annotations_response.status.code != status_code_pb2.SUCCESS:
print(list_annotations_response.status)
raise Exception("List annotations failed, status: " + list_annotations_response.status.description)
for annotation_object in list_annotations_response.annotations:
print(annotation_object)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and input IDs.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change this to list your own annotations
const INPUT_ID = 'c9cbb1c90cf24bc98bfd2e529e744ca9';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const requestOptions = {
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
}
};
fetch(`https://api.clarifai.com/v2/users/${USER_ID}/apps/${APP_ID}/annotations?page=1&per_page=10&input_ids=${INPUT_ID}`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and input IDs.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to list your own annotations
const INPUT_ID_1 = 'c9cbb1c90cf24bc98bfd2e529e744ca9';
const INPUT_ID_2 = 'a8748df4938447e4844b2f505c8eaaef';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.ListAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
input_ids: [INPUT_ID_1, INPUT_ID_2],
page: 1,
per_page: 10
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("List annotations failed, status: " + response.status.description);
}
for (const annotation of response.annotations) {
console.log(JSON.stringify(annotation, null, 2));
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.*;
public class ClarifaiExample {
/////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and input IDs.
// Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to list your own annotations
static final String INPUT_ID_1 = "c9cbb1c90cf24bc98bfd2e529e744ca9";
static final String INPUT_ID_2 = "a8748df4938447e4844b2f505c8eaaef";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiAnnotationResponse listAnnotationsResponse = stub.listAnnotations(
ListAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addInputIds(INPUT_ID_1)
.addInputIds(INPUT_ID_2)
.setPerPage(10)
.setPage(1) // Pages start at 1
.build()
);
if (listAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("List annotations failed, status: " + listAnnotationsResponse.getStatus());
}
for (Annotation annotation: listAnnotationsResponse.getAnnotationsList()) {
System.out.println(annotation);
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and input IDs.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these to list your own annotations
$INPUT_ID_1 = "c9cbb1c90cf24bc98bfd2e529e744ca9";
$INPUT_ID_2 = "a8748df4938447e4844b2f505c8eaaef";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\ListAnnotationsRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->ListAnnotations(
// The request object carries the request along with the request status and other metadata related to the request itself
new ListAnnotationsRequest([
"user_app_id" => $userDataObject,
"input_ids" => [$INPUT_ID_1, $INPUT_ID_2],
"per_page" => 10
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
foreach ($response->getAnnotations() as $annotation_object) {
echo $annotation_object->SerializeToJSONString() . "</br>";
}
?>
curl -X GET "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations?page=1&per_page=10&input_ids=YOUR_INPUT_ID_HERE" \
-H "Authorization: Key YOUR_PAT_HERE"
List Annotations by Input IDs and Annotation IDs
You can list annotations by input IDs and their corresponding annotation IDs. Number of input IDs and annotation IDs should be the same. Since we are finding annotation by IDs, this will match any user or model created annotations.
Below is an example of how to do that.
-
When listing annotations, both input IDs and annotation IDs are optional. If you do not provide any input ID or annotation ID, we will return all annotations based on the creation time of each input.
-
You can also list annotations by providing input IDs only.
-
However, if you want to list annotations by providing annotation IDs, then input IDs are also required so that we know the inputs that correspond to the annotation IDs provided in the request. In this case, the number of input IDs should be equal to the number of annotation IDs.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
##########################################################################
# In this section, we set the user authentication, app ID, input IDs, and
# annotation IDs. Change these strings to run your own example.
##########################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to list your own annotations
INPUT_ID_1 = '53d0362a9dfa4e03b2293375e2d0db73'
INPUT_ID_2 = '00f6d742124147ac8ca7788f73736fb9'
ANNOTATION_ID_1 = '300b8e39a65e4f33ae4e15e86eaf4a3b'
ANNOTATION_ID_2 = 'fcd19d4ad96440e7b1fbda7279c19e44'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
list_annotations_response = stub.ListAnnotations(
service_pb2.ListAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
input_ids=[INPUT_ID_1, INPUT_ID_2],
ids=[ANNOTATION_ID_1, ANNOTATION_ID_2],
per_page=10
),
metadata=metadata
)
if list_annotations_response.status.code != status_code_pb2.SUCCESS:
print(list_annotations_response.status)
raise Exception("List annotations failed, status: " + list_annotations_response.status.description)
for annotation_object in list_annotations_response.annotations:
print(annotation_object)
<!--index.html file-->
<script>
///////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input IDs, and
// annotation IDs. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to list your own annotations
const INPUT_ID_1 = 'c9cbb1c90cf24bc98bfd2e529e744ca9';
const INPUT_ID_2 = '1be923b967f148dbb4e588cf4a723da1';
const ANNOTATION_ID_1 = '55ccf4250ba34592ac48fd2b839652fe';
const ANNOTATION_ID_2 = '5a6dafa3864a4d768a4c32e514dd8da1';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const requestOptions = {
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
}
};
fetch(`https://api.clarifai.com/v2/users/${USER_ID}/apps/${APP_ID}/annotations?page=1&per_page=10&input_ids=${INPUT_ID_1}&input_ids=${INPUT_ID_2}&ids=${ANNOTATION_ID_1}&ids=${ANNOTATION_ID_2}`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
///////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input IDs, and
// annotation IDs. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to list your own annotations
const INPUT_ID_1 = 'c9cbb1c90cf24bc98bfd2e529e744ca9';
const INPUT_ID_2 = '1be923b967f148dbb4e588cf4a723da1';
const ANNOTATION_ID_1 = '55ccf4250ba34592ac48fd2b839652fe';
const ANNOTATION_ID_2 = '5a6dafa3864a4d768a4c32e514dd8da1';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.ListAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
input_ids: [INPUT_ID_1, INPUT_ID_2],
ids: [ANNOTATION_ID_1, ANNOTATION_ID_2],
page: 1,
per_page: 10
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("List annotations failed, status: " + response.status.description);
}
for (const annotation of response.annotations) {
console.log(JSON.stringify(annotation, null, 2));
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.*;
public class ClarifaiExample {
/////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input IDs, and
// annotation IDs. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to list your own annotations
static final String INPUT_ID_1 = "c9cbb1c90cf24bc98bfd2e529e744ca9";
static final String INPUT_ID_2 = "1be923b967f148dbb4e588cf4a723da1";
static final String ANNOTATION_ID_1 = "55ccf4250ba34592ac48fd2b839652fe";
static final String ANNOTATION_ID_2 = "5a6dafa3864a4d768a4c32e514dd8da1";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiAnnotationResponse listAnnotationsResponse = stub.listAnnotations(
ListAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setPerPage(10)
.addInputIds(INPUT_ID_1)
.addInputIds(INPUT_ID_2)
.addIds(ANNOTATION_ID_1)
.addIds(ANNOTATION_ID_2)
.build()
);
if (listAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("List annotations failed, status: " + listAnnotationsResponse.getStatus());
}
for (Annotation annotation: listAnnotationsResponse.getAnnotationsList()) {
System.out.println(annotation);
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
///////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input IDs, and
// annotation IDs. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these to list your own annotations
$INPUT_ID_1 = 'c9cbb1c90cf24bc98bfd2e529e744ca9';
$INPUT_ID_2 = '1be923b967f148dbb4e588cf4a723da1';
$ANNOTATION_ID_1 = '55ccf4250ba34592ac48fd2b839652fe';
$ANNOTATION_ID_2 = '5a6dafa3864a4d768a4c32e514dd8da1';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\ListAnnotationsRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->ListAnnotations(
// The request object carries the request along with the request status and other metadata related to the request itself
new ListAnnotationsRequest([
"user_app_id" => $userDataObject,
"input_ids" => [$INPUT_ID_1, $INPUT_ID_2],
"ids" => [$ANNOTATION_ID_1, $ANNOTATION_ID_2],
"per_page" => 10
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
foreach ($response->getAnnotations() as $annotation_object) {
echo $annotation_object->SerializeToJSONString() . "</br>";
}
?>
curl -X GET "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations?page=1&per_page=10&input_ids=YOUR_INPUT_ID_1_HERE&input_ids=YOUR_INPUT_ID_2_HERE&ids=YOUR_ANNOTATION_ID_1_HERE&ids=YOUR_ANNOTATION_ID_2_HERE" \
-H "Authorization: Key YOUR_PAT_HERE"
List Annotations by User IDs
An annotation is created by either a user or a model. You can list annotations created by specific user(s) by providing their user IDs.
Below is an example of how to do that.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
#########################################################################
# In this section, we set the user authentication, app ID, and user IDs.
# Change these strings to run your own example.
#########################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Insert the user IDs
USER_ID_1 = 'USER_ID_1_HERE'
USER_ID_2 = 'USER_ID_2_HERE'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
list_annotations_response = stub.ListAnnotations(
service_pb2.ListAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
user_ids=[USER_ID_1, USER_ID_2],
per_page=10
),
metadata=metadata
)
if list_annotations_response.status.code != status_code_pb2.SUCCESS:
print(list_annotations_response.status)
raise Exception("List annotations failed, status: " + list_annotations_response.status.description)
for annotation_object in list_annotations_response.annotations:
print(annotation_object)
<!--index.html file-->
<script>
///////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and user IDs.
// Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Insert the user IDs
const USER_ID_1 = 'USER_ID_1_HERE';
const USER_ID_2 = 'USER_ID_2_HERE';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const requestOptions = {
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
}
};
fetch(`https://api.clarifai.com/v2/users/${USER_ID}/apps/${APP_ID}/annotations?page=1&per_page=10&user_ids=${USER_ID_1}&user_ids=${USER_ID_2}`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
///////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and user IDs.
// Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Insert the user IDs
const USER_ID_1 = 'USER_ID_1_HERE';
const USER_ID_2 = 'USER_ID_2_HERE';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.ListAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
user_ids: [USER_ID_1, USER_ID_2],
page: 1,
per_page: 10
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("List annotations failed, status: " + response.status.description);
}
for (const annotation of response.annotations) {
console.log(JSON.stringify(annotation, null, 2));
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
//////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and user IDs.
// Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Insert the user IDs
static final String USER_ID_1 = "USER_ID_1_HERE";
static final String USER_ID_2 = "USER_ID_2_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiAnnotationResponse listAnnotationsResponse = stub.listAnnotations(
ListAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addUserIds(USER_ID_1)
.addUserIds(USER_ID_2)
.setPerPage(10)
.build()
);
if (listAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("List annotations failed, status: " + listAnnotationsResponse.getStatus());
}
for (Annotation annotation: listAnnotationsResponse.getAnnotationsList()) {
System.out.println(annotation);
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
///////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and user IDs.
// Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Insert the user IDs
$USER_ID_1 = "USER_ID_1_HERE";
$USER_ID_2 = "USER_ID_2_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\ListAnnotationsRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->ListAnnotations(
// The request object carries the request along with the request status and other metadata related to the request itself
new ListAnnotationsRequest([
"user_app_id" => $userDataObject,
"user_ids" => [$USER_ID_1, $USER_ID_2],
"per_page" => 10
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
foreach ($response->getAnnotations() as $annotation_object) {
echo $annotation_object->SerializeToJSONString() . "</br>";
}
?>
curl -X GET "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations?page=1&per_page=10&user_ids=USER_ID_1_HERE&user_ids=USER_ID_2_HERE" \
-H "Authorization: Key YOUR_PAT_HERE"
List Annotations by Model Version IDs
An annotation is created by either a user or a model. For example, if your workflow has a detection model, when you add an input, the model will detect objects in your input. You can see these detected objects by listing the annotations created in the detection model.
You can also label these regions by using Post annotation
with the region ID returned from this call.
Below is an example of how to list annotations by model version IDs.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
##################################################################################
# In this section, we set the user authentication, app ID, and model version IDs.
# Change these strings to run your own example.
##################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Insert the model version IDs
MODEL_VERSION_ID_1 = 'MODEL_VERSION_ID_1_HERE'
MODEL_VERSION_ID_2 = 'MODEL_VERSION_ID_2_HERE'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
list_annotations_response = stub.ListAnnotations(
service_pb2.ListAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
model_version_ids=[MODEL_VERSION_ID_1, MODEL_VERSION_ID_2],
per_page=10
),
metadata=metadata
)
if list_annotations_response.status.code != status_code_pb2.SUCCESS:
print(list_annotations_response.status)
raise Exception("List annotations failed, status: " + list_annotations_response.status.description)
for annotation_object in list_annotations_response.annotations:
print(annotation_object)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and model version IDs.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Insert the model version IDs
const MODEL_VERSION_ID_1 = 'MODEL_VERSION_ID_1_HERE';
const MODEL_VERSION_ID_2 = 'MODEL_VERSION_ID_2_HERE';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const requestOptions = {
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
}
};
fetch(`https://api.clarifai.com/v2/users/${USER_ID}/apps/${APP_ID}/annotations?page=1&per_page=10&model_version_ids=${MODEL_VERSION_ID_1}&model_version_ids=${MODEL_VERSION_ID_2}`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and model version IDs.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Insert the model version IDs
const MODEL_VERSION_ID_1 = 'MODEL_VERSION_ID_1_HERE';
const MODEL_VERSION_ID_2 = 'MODEL_VERSION_ID_2_HERE';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.ListAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
model_version_ids: [MODEL_VERSION_ID_1, MODEL_VERSION_ID_2],
page: 1,
per_page: 10
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("List annotations failed, status: " + response.status.description);
}
for (const annotation of response.annotations) {
console.log(JSON.stringify(annotation, null, 2));
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
/////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and model version IDs.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Insert the model version IDs
static final String MODEL_VERSION_ID_1 = "MODEL_VERSION_ID_1_HERE";
static final String MODEL_VERSION_ID_2 = "MODEL_VERSION_ID_2_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiAnnotationResponse listAnnotationsResponse = stub.listAnnotations(
ListAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addModelVersionIds(MODEL_VERSION_ID_1)
.addModelVersionIds(MODEL_VERSION_ID_2)
.setPerPage(10)
.build()
);
if (listAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("List annotations failed, status: " + listAnnotationsResponse.getStatus());
}
for (Annotation annotation: listAnnotationsResponse.getAnnotationsList()) {
System.out.println(annotation);
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and model version IDs.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Insert the model version IDs
$MODEL_VERSION_ID_1 = "MODEL_VERSION_ID_1_HERE";
$MODEL_VERSION_ID_2 = "MODEL_VERSION_ID_2_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\ListAnnotationsRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->ListAnnotations(
// The request object carries the request along with the request status and other metadata related to the request itself
new ListAnnotationsRequest([
"user_app_id" => $userDataObject,
"model_version_ids" => [$MODEL_VERSION_ID_1, $MODEL_VERSION_ID_2],
"per_page" => 10
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
foreach ($response->getAnnotations() as $annotation_object) {
echo $annotation_object->SerializeToJSONString() . "</br>";
}
?>
curl -X GET "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations?page=1&per_page=10&model_version_ids=MODEL_VERSION_ID_1_HERE&model_version_ids=MODEL_VERSION_ID_2_HERE" \
-H "Authorization: Key YOUR_PAT_HERE"
Update Annotations
Changing annotation data is possible by PATCHing existing annotations. The application owner can change any user-created annotations. Collaborators are not allowed to change annotations made by other collaborators.
Generally speaking, you should send PATCH when you want to change the data you have posted; for example, changing the concept from positive to negative or adjusting the bounding box coordinates.
If you want to add more tags, you can always POST new annotations. There is no limit on how many annotations an input can have.
Update supports overwrite
, merge
, and remove
actions. You can update from 1 up to 128 annotations in a single API call.
Update Annotation With Concepts
Below is an example of how to update an annotation of an image with a new concept, or change a concept value from true to false (or vice versa).
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
####################################################################################
# In this section, we set the user authentication, app ID, input ID, annotation ID,
# and concept ID. Change these strings to run your own example.
####################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the annotation you want to update
INPUT_ID = '53d0362a9dfa4e03b2293375e2d0db73'
ANNOTATION_ID = '300b8e39a65e4f33ae4e15e86eaf4a3b'
CONCEPT_ID = 'apple'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
patch_annotations_response = stub.PatchAnnotations(
service_pb2.PatchAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
action="merge", # Supported actions: overwrite, merge, remove.
annotations=[
resources_pb2.Annotation(
input_id=INPUT_ID,
id=ANNOTATION_ID,
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID, value=1.) # 1 means true, this concept is present.
]
)
)
]
),
metadata=metadata
)
if patch_annotations_response.status.code != status_code_pb2.SUCCESS:
print(patch_annotations_response.status)
raise Exception("Patch annotations failed, status: " + patch_annotations_response.status.description)
<!--index.html file-->
<script>
//////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID, annotation ID,
// and concept ID. Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the annotation you want to update
const INPUT_ID = 'c9cbb1c90cf24bc98bfd2e529e744ca9';
const ANNOTATION_ID = '08d3b9b81432477fb5522d3fb1d1a6f4';
const CONCEPT_ID = 'apple';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"annotations": [
{
"input_id": INPUT_ID,
"id": ANNOTATION_ID,
"data": {
"concepts": [
{
"id": CONCEPT_ID,
"value": 1
}
]
}
}
],
"action": "merge"
});
const requestOptions = {
method: 'PATCH',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/annotations", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
//////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID, annotation ID,
// and concept ID. Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the annotation you want to update
const INPUT_ID = 'c9cbb1c90cf24bc98bfd2e529e744ca9';
const ANNOTATION_ID = '08d3b9b81432477fb5522d3fb1d1a6f4';
const CONCEPT_ID = 'apple';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PatchAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
action: "merge", // Supported actions: overwrite, merge, remove.
annotations: [
{
input_id: INPUT_ID,
id: ANNOTATION_ID,
// 1 means true, this concept is present.
// 0 means false, this concept is not present.
data: {
concepts: [
{ id: CONCEPT_ID, value: 1 }
]
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Patch annotations failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID, annotation ID,
// and concept ID. Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the annotation you want to update
static final String INPUT_ID = "c9cbb1c90cf24bc98bfd2e529e744ca9";
static final String ANNOTATION_ID = "08d3b9b81432477fb5522d3fb1d1a6f4";
static final String CONCEPT_ID = "apple";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiAnnotationResponse patchAnnotationsResponse = stub.patchAnnotations(
PatchAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setAction("merge") // Supported actions: overwrite, merge, remove
.addAnnotations(
Annotation.newBuilder()
.setInputId(INPUT_ID)
.setId(ANNOTATION_ID)
.setData(
Data.newBuilder().addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID)
.setValue(1f) // 1 means true, this concept is present
.build()
)
)
.build()
).build()
);
if (patchAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Patch annotations failed, status: " + patchAnnotationsResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
//////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID, annotation ID,
// and concept ID. Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the annotation you want to update
$INPUT_ID = "c9cbb1c90cf24bc98bfd2e529e744ca9";
$ANNOTATION_ID = "08d3b9b81432477fb5522d3fb1d1a6f4";
$CONCEPT_ID = "apple";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PatchAnnotationsRequest;
use Clarifai\Api\Annotation;
use Clarifai\Api\Concept;
use Clarifai\Api\Data;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PatchAnnotations(
// The request object carries the request along with the request status and other metadata related to the request itself
new PatchAnnotationsRequest([
"user_app_id" => $userDataObject,
"action" => "merge", // Supported actions: overwrite, merge, remove
"annotations" => [
new Annotation([
"input_id" => $INPUT_ID,
"id" => $ANNOTATION_ID,
"data" => new Data([
"concepts" => [
new Concept(["id" => $CONCEPT_ID, "value" => 1.]) // 1 means true, this concept is present
]
])
])
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
?>
# Value of 1 means true, this concept is present
# Value of 0 means false, this concept is not present
curl -X PATCH "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"annotations": [
{
"input_id": "YOUR_INPUT_ID_HERE",
"id": "YOUR_ANNOTATION_ID_HERE",
"data": {
"concepts": [
{
"id": "apple",
"value": 1
}
]
}
}
],
"action":"merge"
}'
Update Annotation With Concepts in a Region
When you update region data, you must nest this new data within region.data
. Set the region_id
to the current region_id
if you do not want to change or remove this region.
Below is an example of how to update annotation with concepts in a region.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
####################################################################################
# In this section, we set the user authentication, app ID, input ID, annotation ID,
# concept ID, and region ID. Change these strings to run your own example.
####################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the annotation you want to update
INPUT_ID = '53d0362a9dfa4e03b2293375e2d0db73'
ANNOTATION_ID = '300b8e39a65e4f33ae4e15e86eaf4a3b'
CONCEPT_ID = 'tree'
REGION_ID = '361d6a9253be9152968012660258a4bf'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
patch_annotations_response = stub.PatchAnnotations(
service_pb2.PatchAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
action="merge", # Supported actions: overwrite, merge, remove.
annotations=[
resources_pb2.Annotation(
input_id=INPUT_ID,
id=ANNOTATION_ID,
data=resources_pb2.Data(
regions=[
resources_pb2.Region(
id=REGION_ID, # this should be the region id of this annotation before patch
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID, value=1.), # 1 means true, this concept is present.
]
)
)
]
)
)
]
),
metadata=metadata
)
if patch_annotations_response.status.code != status_code_pb2.SUCCESS:
print(patch_annotations_response.status)
raise Exception("Patch annotations failed, status: " + patch_annotations_response.status.description)
<!--index.html file-->
<script>
//////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID, annotation ID,
// concept ID, and region ID. Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the annotation you want to update
const INPUT_ID = 'c9cbb1c90cf24bc98bfd2e529e744ca9';
const ANNOTATION_ID = '08d3b9b81432477fb5522d3fb1d1a6f4';
const CONCEPT_ID = 'tree';
const REGION_ID = '361d6a9253be9152968012660258a4bf';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"annotations": [
{
"input_id": INPUT_ID,
"id": ANNOTATION_ID,
"data": {
"regions": [
{
"id": REGION_ID,
"data": {
"concepts": [
{
"id": CONCEPT_ID,
"value": 1
}
]
}
}
]
}
}
],
"action": "merge"
});
const requestOptions = {
method: 'PATCH',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/annotations", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
//////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID, annotation ID,
// concept ID, and region ID. Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the annotation you want to update
const INPUT_ID = 'c9cbb1c90cf24bc98bfd2e529e744ca9';
const ANNOTATION_ID = '08d3b9b81432477fb5522d3fb1d1a6f4';
const CONCEPT_ID = 'apple';
const REGION_ID = '361d6a9253be9152968012660258a4bf';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PatchAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
action: "merge", // Supported actions: overwrite, merge, remove.
annotations: [
{
input_id: INPUT_ID,
id: ANNOTATION_ID,
data: {
regions: [
{
id: REGION_ID, // this should be the region id of this annotation before patch
// 1 means true, this concept is present.
data: {
concepts: [
{ id: CONCEPT_ID, value: 1 },
]
},
}
]
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Patch annotations failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID, annotation ID,
// concept ID, and region ID. Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the annotation you want to update
static final String INPUT_ID = "c9cbb1c90cf24bc98bfd2e529e744ca9";
static final String ANNOTATION_ID = "08d3b9b81432477fb5522d3fb1d1a6f4";
static final String CONCEPT_ID = "apple";
static final String REGION_ID = "361d6a9253be9152968012660258a4bf";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiAnnotationResponse patchAnnotationsResponse = stub.patchAnnotations(
PatchAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setAction("merge") // Supported actions: overwrite, merge, remove
.addAnnotations(
Annotation.newBuilder()
.setInputId(INPUT_ID)
.setId(ANNOTATION_ID)
.setData(
Data.newBuilder().addRegions(
Region.newBuilder()
.setId(REGION_ID) // this should be the region id of this annotation
.setData(
Data.newBuilder().addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID)
.setValue(1f) // 1 means true, this concept is present
.build()
)
).build()
).build()
)
.build()
).build()
);
if (patchAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Patch annotations failed, status: " + patchAnnotationsResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
//////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID, annotation ID,
// concept ID, and region ID. Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the annotation you want to update
$INPUT_ID = "c9cbb1c90cf24bc98bfd2e529e744ca9";
$ANNOTATION_ID = "08d3b9b81432477fb5522d3fb1d1a6f4";
$CONCEPT_ID = "apple";
$REGION_ID = "361d6a9253be9152968012660258a4bf";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PatchAnnotationsRequest;
use Clarifai\Api\Annotation;
use Clarifai\Api\Concept;
use Clarifai\Api\Data;
use Clarifai\Api\Region;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PatchAnnotations(
// The request object carries the request along with the request status and other metadata related to the request itself
new PatchAnnotationsRequest([
"user_app_id" => $userDataObject,
"action" => "merge", // Supported actions: overwrite, merge, remove
"annotations" => [
new Annotation([
"input_id" => $INPUT_ID,
"id" => $ANNOTATION_ID,
"data" => new Data([
"regions" => [
new Region([
"id" => $REGION_ID, // this should be the region id of this annotation before patch
"data" => new Data([
"concepts" => [
new Concept([ "id" => $CONCEPT_ID, "value" => 1. ]), // 1 means true, this concept is present
]
])
])
]
])
]),
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
?>
# Value of 1 means true, this concept is present
# Region ID should be the region ID of this annotation before patch
curl -X PATCH "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"annotations": [
{
"input_id": "YOUR_INPUT_ID_HERE",
"id": "YOUR_ANNOTATION_ID_HERE",
"data": {
"regions": [
{
"id": "REGION_ID_HERE",
"data": {
"concepts": [
{
"id": "apple",
"value": 1
}
]
}
}
]
}
}
],
"action":"merge"
}'
Update Annotation Region Coordinates
You can update region bounding boxes coordinates. When changing the region, you should use overwrite
action. With overwrite
action, you need to provide the data you want to keep in this annotation.
Below is an example of how to do that.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
####################################################################################
# In this section, we set the user authentication, app ID, input ID, annotation ID,
# and concept ID. Change these strings to run your own example.
#####################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the annotation you want to update
INPUT_ID = '53d0362a9dfa4e03b2293375e2d0db73'
ANNOTATION_ID = '300b8e39a65e4f33ae4e15e86eaf4a3b'
CONCEPT_ID = 'bike'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
patch_annotations_response = stub.PatchAnnotations(
service_pb2.PatchAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
action="overwrite",
annotations=[
resources_pb2.Annotation(
input_id=INPUT_ID,
id=ANNOTATION_ID,
data=resources_pb2.Data(
regions=[
resources_pb2.Region(
region_info=resources_pb2.RegionInfo(
bounding_box=resources_pb2.BoundingBox( # move bounding box to new coordinates
top_row=0.5,
left_col=0.5,
bottom_row=0.8,
right_col=0.8
)
),
data=resources_pb2.Data( # need to provide tags you previously labeled since this is overwrite action
concepts=[
resources_pb2.Concept(id=CONCEPT_ID, value=1.), # 1 means true, this concept is present.
]
)
)
]
)
)
]
),
metadata=metadata
)
if patch_annotations_response.status.code != status_code_pb2.SUCCESS:
print(patch_annotations_response.status)
raise Exception("Patch annotations failed, status: " + patch_annotations_response.status.description)
<!--index.html file-->
<script>
//////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID, annotation ID,
// and concept ID. Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the annotation you want to update
const INPUT_ID = '3232a6fd32544c6a902c2cb0103034ff';
const ANNOTATION_ID = '3377446a88714ba78654f2cf811c2211';
const CONCEPT_ID = 'bike';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
action: "overwrite",
"annotations": [
{
"data": {
"regions": [{
"region_info": {
"bounding_box": {
"top_row": 0,
"left_col": 0,
"bottom_row": 1,
"right_col": 1
}
},
"data": {
"concepts": [{
"id": CONCEPT_ID,
"value": 1
}]
}
}]
},
"input_id": INPUT_ID,
"id": ANNOTATION_ID
}
]
});
const requestOptions = {
method: 'PATCH',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/annotations", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
//////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID, annotation ID,
// and concept ID. Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the annotation you want to update
const INPUT_ID = '3232a6fd32544c6a902c2cb0103034ff';
const ANNOTATION_ID = '3377446a88714ba78654f2cf811c2211';
const CONCEPT_ID = 'bike';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PatchAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
action: "overwrite",
annotations: [
{
input_id: INPUT_ID,
id: ANNOTATION_ID,
data: {
regions: [
{
region_info: {
bounding_box: { // move bounding box to a new coordiates
top_row: 0.5,
left_col: 0.5,
bottom_row: 0.8,
right_col: 0.8
}
},
// 1 means true, this concept is present.
// 0 means false, this concept is not present.
data: {
concepts: [
{ id: CONCEPT_ID, value: 1 },
]
},
}
]
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Patch annotations failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID, annotation ID,
// and concept ID. Change these strings to run your own example
//////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the annotation you want to update
static final String INPUT_ID = "3232a6fd32544c6a902c2cb0103034ff";
static final String ANNOTATION_ID = "3377446a88714ba78654f2cf811c2211";
static final String CONCEPT_ID = "bike";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiAnnotationResponse patchAnnotationsResponse = stub.patchAnnotations(
PatchAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setAction("overwrite")
.addAnnotations(
Annotation.newBuilder()
.setInputId(INPUT_ID)
.setId(ANNOTATION_ID)
.setData(
Data.newBuilder().addRegions(
Region.newBuilder()
.setRegionInfo(
RegionInfo.newBuilder()
.setBoundingBox( // move bounding box to a new coordinates
BoundingBox.newBuilder()
.setTopRow(0.5f)
.setLeftCol(0.5f)
.setBottomRow(0.8f)
.setRightCol(0.8f)
.build()
)
.build()
)
.setData(
Data.newBuilder()
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID)
.setValue(1f) // 1 means true, this concept is present
.build()
)
).build()
).build()
)
.build()
).build()
);
if (patchAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Patch annotations failed, status: " + patchAnnotationsResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
//////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID, annotation ID,
// and concept ID. Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the annotation you want to update
$INPUT_ID = "3232a6fd32544c6a902c2cb0103034ff";
$ANNOTATION_ID = "3377446a88714ba78654f2cf811c2211";
$CONCEPT_ID = "bike";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PatchAnnotationsRequest;
use Clarifai\Api\Annotation;
use Clarifai\Api\BoundingBox;
use Clarifai\Api\Concept;
use Clarifai\Api\Data;
use Clarifai\Api\Region;
use Clarifai\Api\RegionInfo;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PatchAnnotations(
// The request object carries the request along with the request status and other metadata related to the request itself
new PatchAnnotationsRequest([
"user_app_id" => $userDataObject,
"action" => "overwrite",
"annotations" => [
new Annotation([
"input_id" => $INPUT_ID,
"id" => $ANNOTATION_ID,
"data" => new Data([
"regions" => [
new Region([
"region_info" => new RegionInfo([
"bounding_box" => new BoundingBox([ // move bounding box to new coordinates
"top_row" => 0.5,
"left_col" => 0.5,
"bottom_row" => 0.8,
"right_col" => 0.8
])
]),
"data" => new Data([ // need to provide tags you previously labeled since this is overwrite action
"concepts" => [
new Concept([ "id" => $CONCEPT_ID, "value" => 1. ]), // 1 means true, this concept is present
]
])
])
]
])
]),
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
?>
curl -X PATCH "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"annotations": [
{
"data": {
"regions": [{
"region_info": {
"bounding_box": {
"top_row": 0,
"left_col": 0,
"bottom_row": 1,
"right_col": 1
}
},
"data": {
"concepts": [{
"id": "bike",
"value": 1
}]
}
}]
},
"input_id": "YOUR_INPUT_ID_HERE",
"id": "YOUR_ANNOTATION_ID_HERE"
}
],
"action":"overwrite"
}'
Update Annotation Status
Below is an example of how to update an annotation status.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
#############################################################################
# In this section, we set the user authentication, app ID, input ID, and
# annotation ID. Change these strings to run your own example.
#############################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the annotation status you want to update
INPUT_ID = 'c021c670357e4083b197abe80bda82b0'
ANNOTATION_ID = '8ac7fd96ce6f44b8a0f4806488b41b93'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2, status_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
patch_annotations_response = stub.PatchAnnotations(
service_pb2.PatchAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
action="merge", # Supported actions: overwrite, merge, remove.
annotations=[
resources_pb2.Annotation(
input_id=INPUT_ID,
id=ANNOTATION_ID,
status=status_pb2.Status(
code=status_code_pb2.ANNOTATION_SUCCESS
)
)
]
),
metadata=metadata
)
if patch_annotations_response.status.code != status_code_pb2.SUCCESS:
print(patch_annotations_response.status)
raise Exception("Patch annotations failed, status: " + patch_annotations_response.status.description)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID, and
// annotation ID. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the annotation status you want to update
const INPUT_ID = '3232a6fd32544c6a902c2cb0103034ff';
const ANNOTATION_ID = '3377446a88714ba78654f2cf811c2211';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"annotations": [
{
"input_id": INPUT_ID,
"id": ANNOTATION_ID,
"status": {
"code": "ANNOTATION_SUCCESS"
}
}
],
"action": "merge"
});
const requestOptions = {
method: 'PATCH',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/annotations", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID, and
// annotation ID. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the annotation status you want to update
const INPUT_ID = '3232a6fd32544c6a902c2cb0103034ff';
const ANNOTATION_ID = '3377446a88714ba78654f2cf811c2211';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PatchAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
action: "merge", // Supported actions: overwrite, merge, remove.
annotations: [
{
input_id: INPUT_ID,
id: ANNOTATION_ID,
status: {
code: 24150
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Patch annotations failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.Status;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
//////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID, and
// annotation ID. Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the annotation status you want to update
static final String INPUT_ID = "3232a6fd32544c6a902c2cb0103034ff";
static final String ANNOTATION_ID = "3377446a88714ba78654f2cf811c2211";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiAnnotationResponse patchAnnotationsResponse = stub.patchAnnotations(
PatchAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setAction("merge") // Supported actions: overwrite, merge, remove
.addAnnotations(
Annotation.newBuilder()
.setInputId(INPUT_ID)
.setId(ANNOTATION_ID)
.setStatus(
Status.newBuilder()
.setCodeValue(StatusCode.ANNOTATION_SUCCESS_VALUE)
.build()
)
.build()
).build()
);
if (patchAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("patch annotations failed, status: " + patchAnnotationsResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID, and
// annotation ID. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the annotation status you want to update
$INPUT_ID = "3232a6fd32544c6a902c2cb0103034ff";
$ANNOTATION_ID = "3377446a88714ba78654f2cf811c2211";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PatchAnnotationsRequest;
use Clarifai\Api\Annotation;
use Clarifai\Api\Status\Status;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PatchAnnotations(
// The request object carries the request along with the request status and other metadata related to the request itself
new PatchAnnotationsRequest([
"user_app_id" => $userDataObject,
"action" => "merge", // Supported actions: overwrite, merge, remove
"annotations" => [
new Annotation([
"input_id" => $INPUT_ID,
"id" => $ANNOTATION_ID,
"status" => new Status([
"code" => StatusCode::ANNOTATION_SUCCESS
])
])
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
?>
curl -X PATCH "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"annotations": [
{
"input_id": "YOUR_INPUT_ID_HERE",
"id": "YOUR_ANNOTATION_ID_HERE",
"status": {
"code": "ANNOTATION_SUCCESS"
}
}
],
"action":"merge"
}'
Delete Annotations
Delete Annotation by Input ID and Annotation ID
Below is an example of how to delete a single annotation by input ID and annotation ID.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
#####################################################################
# In this section, we set the user authentication, app ID, input ID,
# and annotation ID. Change these strings to run your own example.
#####################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the annotation you want to delete
INPUT_ID = '53d0362a9dfa4e03b2293375e2d0db73'
ANNOTATION_ID = '300b8e39a65e4f33ae4e15e86eaf4a3b'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
delete_annotation_response = stub.DeleteAnnotation(
service_pb2.DeleteAnnotationRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
input_id=INPUT_ID,
annotation_id=ANNOTATION_ID
),
metadata=metadata
)
if delete_annotation_response.status.code != status_code_pb2.SUCCESS:
print(delete_annotation_response.status)
raise Exception("Delete annotations failed, status: " + delete_annotation_response.status.description)
<!--index.html file-->
<script>
///////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID,
// and annotation ID. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the annotation you want to delete
const INPUT_ID = 'c99f1b557d1d43d1916b46f8ce4a0487';
const ANNOTATION_ID = '244b8a39e51944ffb43bde7f6d33f0a7';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const requestOptions = {
method: 'DELETE',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
}
};
fetch(`https://api.clarifai.com/v2/users/${USER_ID}/apps/${APP_ID}/inputs/${INPUT_ID}/annotations/${ANNOTATION_ID}`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
///////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID,
// and annotation ID. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the annotation you want to delete
const INPUT_ID = 'c99f1b557d1d43d1916b46f8ce4a0487';
const ANNOTATION_ID = 'b65d2a9106ba448382a0cee540f7c582';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.DeleteAnnotation(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
input_id: INPUT_ID,
annotation_id: ANNOTATION_ID
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Delete annotation failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.BaseResponse;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
/////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID,
// and annotation ID. Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the annotation you want to delete
static final String INPUT_ID = "c99f1b557d1d43d1916b46f8ce4a0487";
static final String ANNOTATION_ID = "b65d2a9106ba448382a0cee540f7c582";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
BaseResponse deleteAnnotationResponse = stub.deleteAnnotation(
DeleteAnnotationRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setInputId(INPUT_ID)
.setAnnotationId(ANNOTATION_ID)
.build()
);
if (deleteAnnotationResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Delete annotation failed, status: " + deleteAnnotationResponse.getStatus());
}
}
}
curl -X DELETE "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/inputs/YOUR_INPUT_ID_HERE/annotations/YOUR_ANNOTATION_ID_HERE" \
-H "Authorization: Key YOUR_PAT_HERE" \
Bulk Delete Annotations by Input IDs and Annotation IDs
You can delete multiple annotations in one API call. You need to provide a list of input IDs and a list of annotation IDs. The number of input IDs has to match the number of annotation IDs.
Below is an example of how to do that.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
#######################################################################
# In this section, we set the user authentication, app ID, input IDs,
# and annotation IDs. Change these strings to run your own example.
#######################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the annotations you want to bulk delete
INPUT_ID_1 = 'b76fe0adb0294906942f169bb1f6cacf'
INPUT_ID_2 = 'e838fac8da9d40c89f2291a6496593da'
ANNOTATION_ID_1 = '35c37cda9ad8460fae12b2b2b6a23f1d'
ANNOTATION_ID_2 = '63d69000ae3343d0b70b892ea3dcb01d'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
delete_annotations_response = stub.DeleteAnnotations(
service_pb2.DeleteAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
input_ids=[INPUT_ID_1, INPUT_ID_2],
ids=[ANNOTATION_ID_1, ANNOTATION_ID_2]
),
metadata=metadata
)
if delete_annotations_response.status.code != status_code_pb2.SUCCESS:
print(delete_annotations_response.status)
raise Exception("Delete annotations failed, status: " + delete_annotations_response.status.description)
<!--index.html file-->
<script>
///////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input IDs,
// and annotation IDs. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the annotations you want to bulk delete
const INPUT_ID_1 = 'c99f1b557d1d43d1916b46f8ce4a0487';
const INPUT_ID_2 = '7c5f489bcafe43fe8a71c68091cb64ce';
const ANNOTATION_ID_1 = '6793f476f6c24712b447316ae2fc12c1';
const ANNOTATION_ID_2 = 'd703cafff61b45bbb4d8c1d9575420b3';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"input_ids": [INPUT_ID_1, INPUT_ID_2],
"ids": [ANNOTATION_ID_1, ANNOTATION_ID_2]
});
const requestOptions = {
method: 'DELETE',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/annotations", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
///////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input IDs,
// and annotation IDs. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the annotations you want to bulk delete
const INPUT_ID_1 = 'c99f1b557d1d43d1916b46f8ce4a0487';
const INPUT_ID_2 = '7c5f489bcafe43fe8a71c68091cb64ce';
const ANNOTATION_ID_1 = '9bcbdbc381c34a6da64bb3d635e82833';
const ANNOTATION_ID_2 = 'e5f8310fbd824354b657050132311e64';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.DeleteAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
input_ids: [INPUT_ID_1, INPUT_ID_2],
annotation_ids: [ANNOTATION_ID_1, ANNOTATION_ID_2]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Delete annotations failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.BaseResponse;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
/////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input IDs,
// and annotation IDs. Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the annotations you want to bulk delete
static final String INPUT_ID_1 = "c99f1b557d1d43d1916b46f8ce4a0487";
static final String INPUT_ID_2 = "7c5f489bcafe43fe8a71c68091cb64ce";
static final String ANNOTATION_ID_1 = "9bcbdbc381c34a6da64bb3d635e82833";
static final String ANNOTATION_ID_2 = "e5f8310fbd824354b657050132311e64";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
BaseResponse deleteAnnotationsResponse = stub.deleteAnnotations(
DeleteAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addInputIds(INPUT_ID_1)
.addInputIds(INPUT_ID_2)
.addIds(ANNOTATION_ID_1)
.addIds(ANNOTATION_ID_2)
.build()
);
if (deleteAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Delete annotations failed, status: " + deleteAnnotationsResponse.getStatus());
}
}
}
curl -X DELETE "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-d '{
"input_ids":["YOUR_INPUT_ID_1_HERE","YOUR_INPUT_ID_2_HERE"],
"ids":["YOUR_ANNOTATION_ID_1_HERE", "YOUR_ANNOTATION_ID_2_HERE"]
}'
Bulk Delete All Annotations by Input IDs
To delete all annotations of a given input, you just need to set their input ID(s). This will delete all annotations for these input(s), EXCEPT the input level annotations, which only get deleted if you delete the inputs themselves.
Below is an example of how to do that.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
##########################################################################
# In this section, we set the user authentication, app ID, and input IDs.
# Change these strings to run your own example.
##########################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the annotations you want to bulk delete
INPUT_ID_1 = '53d0362a9dfa4e03b2293375e2d0db73'
INPUT_ID_2 = '00f6d742124147ac8ca7788f73736fb9'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
delete_annotations_response = stub.DeleteAnnotations(
service_pb2.DeleteAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
input_ids=[INPUT_ID_1, INPUT_ID_2]
),
metadata=metadata
)
if delete_annotations_response.status.code != status_code_pb2.SUCCESS:
print(delete_annotations_response.status)
raise Exception("Delete annotations failed, status: " + delete_annotations_response.status.description)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and input IDs.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the annotations you want to bulk delete
const INPUT_ID_1 = 'b5585a6869d34c04bbcaf631e7cd5816';
const INPUT_ID_2 = 'a8748df4938447e4844b2f505c8eaaef';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"input_ids": [INPUT_ID_1, INPUT_ID_2]
});
const requestOptions = {
method: 'DELETE',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/annotations", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and input IDs.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the annotations you want to bulk delete
const INPUT_ID_1 = 'b5585a6869d34c04bbcaf631e7cd5816';
const INPUT_ID_2 = 'a8748df4938447e4844b2f505c8eaaef';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.DeleteAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
input_ids: [INPUT_ID_1, INPUT_ID_2]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Delete annotations failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.BaseResponse;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and input IDs.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the annotations you want to bulk delete
static final String INPUT_ID_1 = "b5585a6869d34c04bbcaf631e7cd5816";
static final String INPUT_ID_2 = "a8748df4938447e4844b2f505c8eaaef";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
BaseResponse deleteAnnotationsResponse = stub.deleteAnnotations(
DeleteAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addInputIds(INPUT_ID_1)
.addInputIds(INPUT_ID_2)
.build()
);
if (deleteAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Delete annotations failed, status: " + deleteAnnotationsResponse.getStatus());
}
}
}
curl -X DELETE "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-d '{
"input_ids":["YOUR_INPUT_ID_1_HERE","YOUR_INPUT_ID_2_HERE"]
}'