Programmatic Auto-Annotation Walkthrough
Use AI to help you build AI. Auto annotation uses your model predictions to label your training data
This tutorial demonstrates how auto-annotation workflows can be configured in the Clarifai API. With auto-annotation, you can use model predictions to label your inputs. Auto-annotation can help you prepare training data or assign other useful labels and metadata to your inputs.
Since models are doing most of the work of annotating your data, this enables you to speed-up and scale-up your annotation process while ensuring quality standards, typically reducing human effort of labeling data by orders of magnitude. And since this is built into our APIs, it seamlessly integrates with all the search, training, and prediction functionality of the Clarifai platform.
When a concept is predicted by a model, it is predicted with a confidence score of between 0 and 1. In this walkthrough, we will leverage that score in our workflow so that when your model predictions are confident (close to 1), you can have your data automatically labeled with that concept. When your predictions are less-than-confident, you can have your input sent to a human reviewer.
The initialization code used in the following examples is outlined in detail on the client installation page.
-
Click here to learn how to create an auto-annotation task via the API and automatically label the inputs in your dataset.
-
Click here to learn how to carry out auto-annotation via the UI.
Create Concepts
Let's start by creating the concepts we'll use in our model. We'll create the following concepts: people
, man
and adult
.
- gRPC Python
- gRPC NodeJS
- gRPC Java
- cURL
####################################################################################
# In this section, we set the user authentication, app ID, and the details of the
# concepts we want to create. 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 create your own concepts
CONCEPT_ID_1 = 'peopleID'
CONCEPT_NAME_1 = 'people'
CONCEPT_ID_2 = 'manID'
CONCEPT_NAME_2 = 'man'
CONCEPT_ID_3 = 'adultID'
CONCEPT_NAME_3 = 'adult'
##########################################################################
# 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) # The userDataObject is required when using a PAT
post_concepts_response = stub.PostConcepts(
service_pb2.PostConceptsRequest(
user_app_id=userDataObject,
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_1, name=CONCEPT_NAME_1),
resources_pb2.Concept(id=CONCEPT_ID_2, name=CONCEPT_NAME_2),
resources_pb2.Concept(id=CONCEPT_ID_3, name=CONCEPT_NAME_3),
]
),
metadata=metadata
)
if post_concepts_response.status.code != status_code_pb2.SUCCESS:
print(post_concepts_response.status)
raise Exception("Post concepts failed, status: " + post_concepts_response.status.description)
//index.js file
//////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the
// concepts we want to create. 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 create your own concepts
const CONCEPT_ID_1 = 'peopleID';
const CONCEPT_NAME_1 = 'people';
const CONCEPT_ID_2 = 'manID';
const CONCEPT_NAME_2 = 'man';
const CONCEPT_ID_3 = 'adultID';
const CONCEPT_NAME_3 = 'adult';
/////////////////////////////////////////////////////////////////////////////
// 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.PostConcepts(
{
user_app_id: {
user_id: USER_ID,
app_id: APP_ID
},
concepts: [
{
id: CONCEPT_ID_1,
name: CONCEPT_NAME_1
},
{
id: CONCEPT_ID_2,
name: CONCEPT_NAME_2
},
{
id: CONCEPT_ID_3,
name: CONCEPT_NAME_3
},
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post concepts failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
//////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the
// concepts we want to create. 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 create your own concepts
static final String CONCEPT_ID_1 = "peopleID";
static final String CONCEPT_NAME_1 = "people";
static final String CONCEPT_ID_2 = "manID";
static final String CONCEPT_NAME_2 = "man";
static final String CONCEPT_ID_3 = "adultID";
static final String CONCEPT_NAME_3 = "adult";
///////////////////////////////////////////////////////////////////////////////////
// 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));
MultiConceptResponse postConceptsResponse = stub.postConcepts(
PostConceptsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setAppId(APP_ID))
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_1)
.setName(CONCEPT_NAME_1)
)
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_2)
.setName(CONCEPT_NAME_2)
)
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_3)
.setName(CONCEPT_NAME_3)
)
.build()
);
if (postConceptsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post concepts failed, status: " + postConceptsResponse.getStatus());
}
}
}
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/concepts" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
--data-raw '{
"concepts": [
{
"id": "peopleID",
"name": "people"
},
{
"id": "manID",
"name": "man"
},
{
"id": "adultID",
"name": "adult"
}
]
}'
Link Concepts
Link the newly created concepts with concepts in the clarifai/main General model.
Run the code below three times; once for each concept you created previously. The concept IDs of the clarifai/main General models are as follows:
ai_l8TKp2h5
- the people concept;ai_dxSG2s86
- the man concept;ai_VPmHr5bm
- the adult concept.
Your model's concept IDs are the ones you created in the previous step: peopleID
, manID
, and adultID
.
- gRPC Python
- gRPC NodeJS
- gRPC Java
- cURL
####################################################################################
# In this section, we set the user authentication, app ID, and the details of the
# concepts we want to link. 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 link your own concepts
# Run this code three times; once for each concept you want to link
MODEL_CONCEPT_ID = 'YOUR_MODEL_CONCEPT_ID'
GENERAL_MODEL_CONCEPT_ID = 'GENERAL_MODEL_CONCEPT_ID'
##########################################################################
# 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) # The userDataObject is required when using a PAT
post_concept_relations_response = stub.PostConceptRelations(
service_pb2.PostConceptRelationsRequest(
user_app_id=userDataObject,
concept_id=MODEL_CONCEPT_ID,
concept_relations=[
resources_pb2.ConceptRelation(
object_concept=resources_pb2.Concept(id=GENERAL_MODEL_CONCEPT_ID, app_id="main"),
predicate="synonym"
)
]
),
metadata=metadata
)
if post_concept_relations_response.status.code != status_code_pb2.SUCCESS:
print(post_concept_relations_response.status)
raise Exception("Post concept relations failed, status: " + post_concept_relations_response.status.description)
//index.js file
//////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the
// concepts we want to link. 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 link your own concepts
// Run this code three times; once for each concept you want to link
const MODEL_CONCEPT_ID = 'YOUR_MODEL_CONCEPT_ID';
const GENERAL_MODEL_CONCEPT_ID = 'GENERAL_MODEL_CONCEPT_ID';
/////////////////////////////////////////////////////////////////////////////
// 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.PostConceptRelations(
{
user_app_id: {
user_id: USER_ID,
app_id: APP_ID
},
concept_id: MODEL_CONCEPT_ID,
concept_relations: [
{
object_concept: {
id: GENERAL_MODEL_CONCEPT_ID,
app_id: "main"
},
predicate: "synonym"
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post concept relations failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
//////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the
// concepts we want to link. 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 link your own concepts
// Run this code three times; once for each concept you want to link
static final String MODEL_CONCEPT_ID = "YOUR_MODEL_CONCEPT_ID";
static final String GENERAL_MODEL_CONCEPT_ID = "GENERAL_MODEL_CONCEPT_ID";
///////////////////////////////////////////////////////////////////////////////////
// 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));
MultiConceptRelationResponse postConceptRelationsResponse = stub.postConceptRelations(
PostConceptRelationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setConceptId(MODEL_CONCEPT_ID)
.addConceptRelations(
ConceptRelation.newBuilder()
.setObjectConcept(
Concept.newBuilder()
.setId(GENERAL_MODEL_CONCEPT_ID)
.setAppId("main")
)
.setPredicate("synonym").build())
.build()
);
if (postConceptRelationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post concept relations failed, status: " + postConceptRelationsResponse.getStatus());
}
}
}
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/concepts/YOUR_MODEL_CONCEPT_ID_HERE/relations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
--data-raw '{
"concept_relations": [
{
"object_concept": {
"id": "GENERAL_MODEL_CONCEPT_ID_HERE",
"app_id": "main"
},
"predicate": "synonym"
}
]
}'
Create a Concept Mapper Model
We're going to create a concept mapper model that translates the concepts from the General model to our new concepts. The model will map the concepts as synonyms. Hypernyms and hyponyms are supported as well.
We'll be setting the knowledge_graph_id
value to be empty.
If you want to define a subset of relationships in your app to be related to each other, you can provide the knowledge_graph_id
to each concept relation and then provide that knowledge_graph_id
as input to this model as well, which will only follow relationships in that subset of your app's knowledge graph.
- gRPC Python
- gRPC NodeJS
- gRPC Java
- cURL
###########################################################################################
# In this section, we set the user authentication, app ID, and the details of the concept
# mapper model we want to create. 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 create your own concept mapper model
SYNONYM_MODEL_ID = 'synonym-model-id'
MODEL_TYPE_ID = 'concept-synonym-mapper'
##########################################################################
# 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
from google.protobuf.struct_pb2 import Struct
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 required when using a PAT
params = Struct()
params.update({
"knowledge_graph_id": ""
})
post_models_response = stub.PostModels(
service_pb2.PostModelsRequest(
user_app_id=userDataObject,
models=[
resources_pb2.Model(
id=SYNONYM_MODEL_ID,
model_type_id=MODEL_TYPE_ID,
output_info=resources_pb2.OutputInfo(
params=params,
)
),
]
),
metadata=metadata
)
if post_models_response.status.code != status_code_pb2.SUCCESS:
print(post_models_response.status)
raise Exception("Post models failed, status: " + post_models_response.status.description)
print(post_models_response)
//index.js file
//////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the concept
// mapper model we want to create. 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 create your own concept mapper model
const SYNONYM_MODEL_ID = 'synonym-model-id';
const MODEL_TYPE_ID = 'concept-synonym-mapper';
/////////////////////////////////////////////////////////////////////////////
// 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);
const params = {
knowledge_graph_id: ""
}
stub.PostModels(
{
user_app_id: {
user_id: USER_ID,
app_id: APP_ID
},
models: [
{
id: SYNONYM_MODEL_ID,
model_type_id: MODEL_TYPE_ID,
output_info: {
params: params,
}
},
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post models failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
public class ClarifaiExample {
//////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the concept
// mapper model we want to create. 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 create your own concept mapper model
static final String SYNONYM_MODEL_ID = "synonym-model-id";
static final String MODEL_TYPE_ID = "concept-synonym-mapper";
///////////////////////////////////////////////////////////////////////////////////
// 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));
Struct.Builder params = Struct.newBuilder()
.putFields("knowledge_graph_id", Value.newBuilder().setStringValue("").build());
SingleModelResponse postModelsResponse = stub.postModels(
PostModelsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addModels(
Model.newBuilder()
.setId(SYNONYM_MODEL_ID)
.setModelTypeId(MODEL_TYPE_ID)
.setOutputInfo(
OutputInfo.newBuilder()
.setParams(params)
)
)
.build()
);
if (postModelsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post models failed, status: " + postModelsResponse.getStatus());
}
}
}
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/models" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
--data-raw '{
"model": {
"id": "synonym-model-id",
"model_type_id": "concept-synonym-mapper",
"output_info": {
"params": {
"knowledge_graph_id": ""
}
}
}
}'
Create a "Greater Than" Concept Thresholder Model
This model will allow any predictions >= the concept values defined in the model to be outputted from the model.
- gRPC Python
- gRPC NodeJS
- gRPC Java
- cURL
#########################################################################################
# In this section, we set the user authentication, app ID, and the details of the model
# we want to create. 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 create your own concept thresholder model
MODEL_ID = 'greater-than-model-id'
MODEL_TYPE_ID = 'concept-thresholder'
CONCEPT_ID_1 = 'peopleID'
CONCEPT_ID_2 = 'manID'
CONCEPT_ID_3 = 'adultID'
##########################################################################
# 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
from google.protobuf.struct_pb2 import Struct
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 required when using a PAT
params = Struct()
params.update({
"concept_threshold_type": "GREATER_THAN"
})
post_models_response = stub.PostModels(
service_pb2.PostModelsRequest(
user_app_id=userDataObject,
models=[
resources_pb2.Model(
id=MODEL_ID,
model_type_id=MODEL_TYPE_ID,
output_info=resources_pb2.OutputInfo(
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_1, value=0.5),
resources_pb2.Concept(id=CONCEPT_ID_2, value=0.5),
resources_pb2.Concept(id=CONCEPT_ID_3, value=0.95),
]
),
params=params
)
),
]
),
metadata=metadata
)
if post_models_response.status.code != status_code_pb2.SUCCESS:
print(post_models_response.status)
raise Exception("Post models failed, status: " + post_models_response.status.description)
//index.js file
///////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the model
// we want to create. 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 create your own concept thresholder model
const MODEL_ID = 'greater-than-model-id';
const MODEL_TYPE_ID = 'concept-thresholder';
const CONCEPT_ID_1 = 'peopleID';
const CONCEPT_ID_2 = 'manID';
const CONCEPT_ID_3 = 'adultID';
/////////////////////////////////////////////////////////////////////////////
// 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);
const params = {
concept_threshold_type: "GREATER_THAN"
}
stub.PostModels(
{
user_app_id: {
user_id: USER_ID,
app_id: APP_ID
},
models: [
{
id: MODEL_ID,
model_type_id: MODEL_TYPE_ID,
output_info: {
data: {
concepts: [
{ id: CONCEPT_ID_1, value: 0.5 },
{ id: CONCEPT_ID_2, value: 0.5 },
{ id: CONCEPT_ID_3, value: 0.95 }
]
},
},
params: params
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post models failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the model
// we want to create. 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 create your own concept thresholder model
static final String MODEL_ID = "greater-than-model-id";
static final String MODEL_TYPE_ID = "concept-thresholder";
static final String CONCEPT_ID_1 = "peopleID";
static final String CONCEPT_ID_2 = "manID";
static final String CONCEPT_ID_3 = "adultID";
///////////////////////////////////////////////////////////////////////////////////
// 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));
Struct.Builder params = Struct.newBuilder()
.putFields(
"concept_threshold_type",
Value.newBuilder().setNumberValue(ValueComparator.GREATER_THAN_VALUE).build()
);
SingleModelResponse postModelsResponse = stub.postModels(
PostModelsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addModels(
Model.newBuilder()
.setId(MODEL_ID)
.setModelTypeId(MODEL_TYPE_ID)
.setOutputInfo(
OutputInfo.newBuilder()
.setData(
Data.newBuilder()
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_1)
.setValue(0.5f)
)
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_2)
.setValue(0.5f)
)
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_3)
.setValue(0.95f)
)
)
.setParams(params)
)
)
.build()
);
if (postModelsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post models failed, status: " + postModelsResponse.getStatus());
}
}
}
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/models" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
--data-raw '{
"model": {
"id": "greater-than-model-id",
"model_type_id": "concept-thresholder",
"output_info": {
"data": {
"concepts": [
{
"id": "peopleID",
"value": 0.5
},
{
"id": "manID",
"value": 0.5
},
{
"id": "adultID",
"value": 0.95
}
]
},
"params": {
"concept_threshold_type": "GREATER_THAN"
}
}
}
}'
Create a "Less Than" Concept Thresholder Model
This model will allow any predictions < the concept values defined in the model to be outputted from the model.
- gRPC Python
- gRPC NodeJS
- gRPC Java
- cURL
#########################################################################################
# In this section, we set the user authentication, app ID, and the details of the model
# we want to create. 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 create your own concept thresholder model
MODEL_ID = 'less-than-model-id'
MODEL_TYPE_ID = 'concept-thresholder'
CONCEPT_ID_1 = 'peopleID'
CONCEPT_ID_2 = 'manID'
CONCEPT_ID_3 = 'adultID'
##########################################################################
# 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
from google.protobuf.struct_pb2 import Struct
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 required when using a PAT
params = Struct()
params.update({
"concept_threshold_type": "LESS_THAN"
})
post_models_response = stub.PostModels(
service_pb2.PostModelsRequest(
user_app_id=userDataObject,
models=[
resources_pb2.Model(
id=MODEL_ID,
model_type_id=MODEL_TYPE_ID,
output_info=resources_pb2.OutputInfo(
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_1, value=0.5),
resources_pb2.Concept(id=CONCEPT_ID_2, value=0.5),
resources_pb2.Concept(id=CONCEPT_ID_3, value=0.95),
]
),
params=params
)
),
]
),
metadata=metadata
)
if post_models_response.status.code != status_code_pb2.SUCCESS:
print(post_models_response.status)
raise Exception("Post models failed, status: " + post_models_response.status.description)
//index.js file
///////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the model
// we want to create. 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 create your own concept thresholder model
const MODEL_ID = 'less-than-model-id';
const MODEL_TYPE_ID = 'concept-thresholder';
const CONCEPT_ID_1 = 'peopleID';
const CONCEPT_ID_2 = 'manID';
const CONCEPT_ID_3 = 'adultID';
/////////////////////////////////////////////////////////////////////////////
// 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);
const params = {
concept_threshold_type: "LESS_THAN"
}
stub.PostModels(
{
user_app_id: {
user_id: USER_ID,
app_id: APP_ID
},
models: [
{
id: MODEL_ID,
model_type_id: MODEL_TYPE_ID,
output_info: {
data: {
concepts: [
{ id: CONCEPT_ID_1, value: 0.5 },
{ id: CONCEPT_ID_2, value: 0.5 },
{ id: CONCEPT_ID_3, value: 0.95 }
]
},
params: params
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post models failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the model
// we want to create. 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 create your own concept thresholder model
static final String MODEL_ID = "less-than-model-id";
static final String MODEL_TYPE_ID = "concept-thresholder";
static final String CONCEPT_ID_1 = "peopleID";
static final String CONCEPT_ID_2 = "manID";
static final String CONCEPT_ID_3 = "adultID";
///////////////////////////////////////////////////////////////////////////////////
// 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));
Struct.Builder params = Struct.newBuilder()
.putFields(
"concept_threshold_type",
Value.newBuilder().setNumberValue(ValueComparator.LESS_THAN_VALUE).build()
);
SingleModelResponse postModelsResponse = stub.postModels(
PostModelsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addModels(
Model.newBuilder()
.setId(MODEL_ID)
.setModelTypeId(MODEL_TYPE_ID)
.setOutputInfo(
OutputInfo.newBuilder()
.setData(
Data.newBuilder()
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_1)
.setValue(0.5f)
)
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_2)
.setValue(0.5f)
)
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_3)
.setValue(0.95f)
)
)
.setParams(params)
)
)
.build()
);
if (postModelsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post models failed, status: " + postModelsResponse.getStatus());
}
}
}
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/models" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
--data-raw '{
"model": {
"id": "less-than-model-id",
"model_type_id": "concept-thresholder",
"output_info": {
"data": {
"concepts": [
{
"id": "peopleID",
"value": 0.5
},
{
"id": "manID",
"value": 0.5
},
{
"id": "adultID",
"value": 0.95
}
]
},
"params": {
"concept_threshold_type": "LESS_THAN"
}
}
}
}'
Create a "Write Success as Me" Annotation Writer Model
Any incoming Data object full of concepts, regions, etc. will be written by this model to the database as an annotation with ANNOTATION_SUCCESS status as if the app owner did the work themself.
- gRPC Python
- gRPC NodeJS
- gRPC Java
- cURL
#########################################################################################
# In this section, we set the user authentication, app ID, and the details of the model
# we want to create. 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 create your own annotation writer model
ANNOTATION_USER_ID = 'ANNOTATION_USER_ID_HERE'
MODEL_ID = 'write-success-model-id'
MODEL_TYPE_ID = 'annotation-writer'
##########################################################################
# 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
from google.protobuf.struct_pb2 import Struct
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 required when using a PAT
params = Struct()
params.update({
"annotation_status": status_code_pb2.ANNOTATION_SUCCESS,
"annotation_user_id": ANNOTATION_USER_ID
})
post_models_response = stub.PostModels(
service_pb2.PostModelsRequest(
user_app_id=userDataObject,
models=[
resources_pb2.Model(
id=MODEL_ID,
model_type_id=MODEL_TYPE_ID,
output_info=resources_pb2.OutputInfo(
params=params
)
),
]
),
metadata=metadata
)
if post_models_response.status.code != status_code_pb2.SUCCESS:
print(post_models_response.status)
raise Exception("Post models failed, status: " + post_models_response.status.description)
//index.js file
///////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the model
// we want to create. 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 create your own annotation writer model
const ANNOTATION_USER_ID = 'ANNOTATION_USER_ID_HERE';
const MODEL_ID = 'write-success-model-id';
const MODEL_TYPE_ID = 'annotation-writer';
/////////////////////////////////////////////////////////////////////////////
// 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);
const params = {
annotation_status: "ANNOTATION_SUCCESS",
annotation_user_id: ANNOTATION_USER_ID
}
stub.PostModels(
{
user_app_id: {
user_id: USER_ID,
app_id: APP_ID
},
models: [
{
id: MODEL_ID,
model_type_id: MODEL_TYPE_ID,
output_info: {
params: params
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post models failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the model
// we want to create. 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 create your own annotation writer model
static final String ANNOTATION_USER_ID = "ANNOTATION_USER_ID_HERE";
static final String MODEL_ID = "write-success-as-me-id";
static final String MODEL_TYPE_ID = "annotation-writer";
///////////////////////////////////////////////////////////////////////////////////
// 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));
Struct.Builder params = Struct.newBuilder()
.putFields(
"annotation_status", Value.newBuilder().setNumberValue(StatusCode.ANNOTATION_SUCCESS_VALUE).build()
)
.putFields(
"annotation_user_id",
Value.newBuilder().setStringValue(ANNOTATION_USER_ID).build()
);
SingleModelResponse postModelsResponse = stub.postModels(
PostModelsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addModels(
Model.newBuilder()
.setId(MODEL_ID)
.setModelTypeId(MODEL_TYPE_ID)
.setOutputInfo(
OutputInfo.newBuilder()
.setParams(params)
)
)
.build()
);
if (postModelsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post models failed, status: " + postModelsResponse.getStatus());
}
}
}
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/models" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
--data-raw '{
"model": {
"id": "write-success-as-me",
"model_type_id": "annotation-writer",
"output_info": {
"params": {
"annotation_status": 24150,
"annotation_user_id": "ANNOTATION_USER_ID_HERE"
}
}
}
}'
Create a "Write Pending as Me" Annotation Writer Model
Any incoming Data object full of concepts, regions, etc. will be written by this model to the database as an annotation with ANNOTATION_PENDING status as if the app owner did the work themself, but needs further review. So, it is marked as pending.
- gRPC Python
- gRPC NodeJS
- gRPC Java
- cURL
#########################################################################################
# In this section, we set the user authentication, app ID, and the details of the model
# we want to create. 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 create your own annotation writer model
ANNOTATION_USER_ID = 'ANNOTATION_USER_ID_HERE'
MODEL_ID = 'write-pending-model-id'
MODEL_TYPE_ID = 'annotation-writer'
##########################################################################
# 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
from google.protobuf.struct_pb2 import Struct
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 required when using a PAT
params = Struct()
params.update({
"annotation_status": status_code_pb2.ANNOTATION_PENDING,
"annotation_user_id": ANNOTATION_USER_ID
})
post_models_response = stub.PostModels(
service_pb2.PostModelsRequest(
user_app_id=userDataObject,
models=[
resources_pb2.Model(
id=MODEL_ID,
model_type_id=MODEL_TYPE_ID,
output_info=resources_pb2.OutputInfo(
params=params
)
),
]
),
metadata=metadata
)
if post_models_response.status.code != status_code_pb2.SUCCESS:
print(post_models_response.status)
raise Exception("Post models failed, status: " + post_models_response.status.description)
//index.js file
///////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the model
// we want to create. 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 create your own annotation writer model
const ANNOTATION_USER_ID = 'ANNOTATION_USER_ID_HERE';
const MODEL_ID = 'write-pending-model-id';
const MODEL_TYPE_ID = 'annotation-writer';
/////////////////////////////////////////////////////////////////////////////
// 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);
const params = {
annotation_status: "ANNOTATION_SUCCESS",
annotation_user_id: ANNOTATION_USER_ID
}
stub.PostModels(
{
user_app_id: {
user_id: USER_ID,
app_id: APP_ID
},
models: [
{
id: MODEL_ID,
model_type_id: MODEL_TYPE_ID,
output_info: {
params: params
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post models failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the model
// we want to create. 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 create your own annotation writer model
static final String ANNOTATION_USER_ID = "ANNOTATION_USER_ID_HERE";
static final String MODEL_ID = "write-pending-as-me-id";
static final String MODEL_TYPE_ID = "annotation-writer";
///////////////////////////////////////////////////////////////////////////////////
// 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));
Struct.Builder params = Struct.newBuilder()
.putFields(
"annotation_status", Value.newBuilder().setNumberValue(StatusCode.ANNOTATION_PENDING_VALUE).build()
)
.putFields(
"annotation_user_id",
Value.newBuilder().setStringValue(ANNOTATION_USER_ID).build()
);
SingleModelResponse postModelsResponse = stub.postModels(
PostModelsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addModels(
Model.newBuilder()
.setId(MODEL_ID)
.setModelTypeId(MODEL_TYPE_ID)
.setOutputInfo(
OutputInfo.newBuilder()
.setParams(params)
)
)
.build()
);
if (postModelsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post models failed, status: " + postModelsResponse.getStatus());
}
}
}
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/models" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
--data-raw '{
"model": {
"id": "write-pending-as-me",
"model_type_id": "annotation-writer",
"output_info": {
"params": {
"annotation_status": 24151,
"annotation_user_id": "ANNOTATION_USER_ID_HERE"
}
}
}
}'
Create the Workflow
We will now connect all the models together into a single workflow.
Every input will be predicted by the General Embed model to generate embeddings. The output of the embed model (embeddings) will be sent to the general concept to predict concept and cluster model. Then, the concept model's output (a list of concepts with prediction values) will be sent to the concept mapper model, which maps Clarifai's concepts to the concepts within your app—people
, man
and adult
in this case.
Then, the mapped concepts will be sent to both concept threshold models—(GREATER THAN
and LESS THAN
). The GREATER THAN
model will filter out the concepts that are lower than the corresponding value you defined in the model and send the remaining concept list to write success as me
model, which labels the input with these concepts (your app concepts only) as you with success
status. You can train or search on these concepts immediately.
The LESS THAN
model will filter out concepts that are higher than the corresponding value you defined in the model and send the remaining concept list to write pending as me
model, which labels the input with these concepts (your app concepts only) as you with pending
status.
The model IDs and model version IDs from the public clarifai/main
application are fixed to the latest version at the time of this writing (use the GET /models
endpoint to get an up to date list of the available models), so they are already hard-coded in the code examples below.
It's possible to use other public models or model version IDs.
- gRPC Python
- gRPC NodeJS
- gRPC Java
- cURL
###################################################################################
# In this section, we set the user authentication, app ID, and the details of the
# workflow we want to create. 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 create your own workflow
# Note that we've also added as comments the values of most of these variables against their names in the code below
WORKFLOW_ID = 'auto-annotation-workflow-id'
NODE_ID_1 = 'general-embed'
MODEL_ID_1 = 'bbb5f41425b8468d9b7a554ff10f8581'
MODEL_VERSION_ID_1 = 'bb186755eda04f9cbb6fe32e816be104'
NODE_ID_2 = 'general-concept'
MODEL_ID_2 = 'aaa03c23b3724a16a56b629203edc62c'
MODEL_VERSION_ID_2 = 'aa7f35c01e0642fda5cf400f543e7c40'
NODE_ID_3 = 'general-cluster'
MODEL_ID_3 = 'cccbe437d6e54e2bb911c6aa292fb072'
MODEL_VERSION_ID_3 = 'cc2074cff6dc4c02b6f4e1b8606dcb54'
NODE_ID_4 = 'mapper'
SYNONYM_MODEL_ID = 'synonym-model-id'
SYNONYM_MODEL_VERSION_ID = 'YOUR_SYNONYM_MODEL_VERSION_ID'
NODE_ID_5 = 'greater-than'
GREATER_THAN_MODEL_ID = 'greater-than-model-id'
GREATER_THAN_MODEL_VERSION_ID = 'YOUR_GREATER_THAN_MODEL_VERSION_ID'
NODE_ID_6 = 'write-success'
WRITE_SUCCESS_MODEL_ID = 'write-success-model-id'
WRITE_SUCCESS_MODEL_VERSION_ID = 'YOUR_WRITE_SUCCESS_MODEL_VERSION_ID'
NODE_ID_7 = 'less-than'
LESS_THAN_MODEL_ID = 'less-than-model-id'
LESS_THAN_MODEL_VERSION_ID = 'YOUR_LESS_THAN_MODEL_VERSION_ID'
NODE_ID_8 = 'write-pending'
WRITE_PENDING_MODEL_ID = 'write-pending-model-id'
WRITE_PENDING_MODEL_VERSION_ID = 'YOUR_WRITE_PENDING_MODEL_VERSION_ID'
##########################################################################
# 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) # The userDataObject is required when using a PAT
post_workflows_response = stub.PostWorkflows(
service_pb2.PostWorkflowsRequest(
user_app_id=userDataObject,
workflows=[
resources_pb2.Workflow(
id=WORKFLOW_ID, # auto-annotation-workflow-id
nodes=[
resources_pb2.WorkflowNode(
id=NODE_ID_1, # general-embed
model=resources_pb2.Model(
id=MODEL_ID_1, # bbb5f41425b8468d9b7a554ff10f8581
model_version=resources_pb2.ModelVersion(
id=MODEL_VERSION_ID_1 # bb186755eda04f9cbb6fe32e816be104
)
)
),
resources_pb2.WorkflowNode(
id=NODE_ID_2, # general-concept
model=resources_pb2.Model(
id=MODEL_ID_2, # aaa03c23b3724a16a56b629203edc62c
model_version=resources_pb2.ModelVersion(
id=MODEL_VERSION_ID_2 # aa7f35c01e0642fda5cf400f543e7c40
)
)
),
resources_pb2.WorkflowNode(
id=NODE_ID_3, # general-cluster
model=resources_pb2.Model(
id=MODEL_ID_3, # cccbe437d6e54e2bb911c6aa292fb072
model_version=resources_pb2.ModelVersion(
id=MODEL_VERSION_ID_3 # cc2074cff6dc4c02b6f4e1b8606dcb54
)
),
),
resources_pb2.WorkflowNode(
id=NODE_ID_4, # mapper
model=resources_pb2.Model(
id=SYNONYM_MODEL_ID,
model_version=resources_pb2.ModelVersion(
id=SYNONYM_MODEL_VERSION_ID
)
),
node_inputs=[
resources_pb2.NodeInput(node_id=NODE_ID_2) # general-concept
]
),
resources_pb2.WorkflowNode(
id=NODE_ID_5, # greater-than
model=resources_pb2.Model(
id=GREATER_THAN_MODEL_ID,
model_version=resources_pb2.ModelVersion(
id=GREATER_THAN_MODEL_VERSION_ID
)
),
node_inputs=[
resources_pb2.NodeInput(node_id=NODE_ID_4) # mapper
]
),
resources_pb2.WorkflowNode(
id=NODE_ID_6, # write-success
model=resources_pb2.Model(
id=WRITE_SUCCESS_MODEL_ID,
model_version=resources_pb2.ModelVersion(
id=WRITE_SUCCESS_MODEL_VERSION_ID
)
),
node_inputs=[
resources_pb2.NodeInput(node_id=NODE_ID_5) # greater-than
]
),
resources_pb2.WorkflowNode(
id=NODE_ID_7, # less-than
model=resources_pb2.Model(
id=LESS_THAN_MODEL_ID,
model_version=resources_pb2.ModelVersion(
id=LESS_THAN_MODEL_VERSION_ID
)
),
node_inputs=[
resources_pb2.NodeInput(node_id=NODE_ID_4) # mapper
]
),
resources_pb2.WorkflowNode(
id=NODE_ID_8, # write-pending
model=resources_pb2.Model(
id=WRITE_PENDING_MODEL_ID,
model_version=resources_pb2.ModelVersion(
id=WRITE_PENDING_MODEL_VERSION_ID
)
),
node_inputs=[
resources_pb2.NodeInput(node_id=NODE_ID_7) # less-than
]
),
]
)
]
),
metadata=metadata
)
if post_workflows_response.status.code != status_code_pb2.SUCCESS:
print(post_workflows_response.status)
raise Exception("Post workflows failed, status: " + post_workflows_response.status.description)
//index.js file
////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the
// workflow we want to create. 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 create your own workflow
// Note that we've also added as comments the values of most of these variables against their names in the code below
const WORKFLOW_ID = 'auto-annotation-workflow-id';
const NODE_ID_1 = 'general-embed';
const MODEL_ID_1 = 'bbb5f41425b8468d9b7a554ff10f8581';
const MODEL_VERSION_ID_1 = 'bb186755eda04f9cbb6fe32e816be104';
const NODE_ID_2 = 'general-concept';
const MODEL_ID_2 = 'aaa03c23b3724a16a56b629203edc62c';
const MODEL_VERSION_ID_2 = 'aa7f35c01e0642fda5cf400f543e7c40';
const NODE_ID_3 = 'general-cluster';
const MODEL_ID_3 = 'cccbe437d6e54e2bb911c6aa292fb072';
const MODEL_VERSION_ID_3 = 'cc2074cff6dc4c02b6f4e1b8606dcb54';
const NODE_ID_4 = 'mapper';
const SYNONYM_MODEL_ID = 'synonym-model-id';
const SYNONYM_MODEL_VERSION_ID = 'YOUR_SYNONYM_MODEL_VERSION_ID';
const NODE_ID_5 = 'greater-than';
const GREATER_THAN_MODEL_ID = 'greater-than-model-id';
const GREATER_THAN_MODEL_VERSION_ID = 'YOUR_GREATER_THAN_MODEL_VERSION_ID';
const NODE_ID_6 = 'write-success';
const WRITE_SUCCESS_MODEL_ID = 'write-success-model-id';
const WRITE_SUCCESS_MODEL_VERSION_ID = 'YOUR_WRITE_SUCCESS_MODEL_VERSION_ID';
const NODE_ID_7 = 'less-than';
const LESS_THAN_MODEL_ID = 'less-than-model-id';
const LESS_THAN_MODEL_VERSION_ID = 'YOUR_LESS_THAN_MODEL_VERSION_ID';
const NODE_ID_8 = 'write-pending';
const WRITE_PENDING_MODEL_ID = 'write-pending-model-id';
const WRITE_PENDING_MODEL_VERSION_ID = 'YOUR_WRITE_PENDING_MODEL_VERSION_ID';
/////////////////////////////////////////////////////////////////////////////
// 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.PostWorkflows(
{
user_app_id: {
user_id: USER_ID,
app_id: APP_ID
},
workflows: [
{
id: WORKFLOW_ID, // auto-annotation-workflow-id
nodes: [
{
id: NODE_ID_1, // general-embed
model: {
id: MODEL_ID_1, // bbb5f41425b8468d9b7a554ff10f8581
model_version: {
id: MODEL_VERSION_ID_1, // bb186755eda04f9cbb6fe32e816be104
}
}
},
{
id: NODE_ID_2, // general-concept
model: {
id: MODEL_ID_2, // aaa03c23b3724a16a56b629203edc62c
model_version: {
id: MODEL_VERSION_ID_2, // aa7f35c01e0642fda5cf400f543e7c40
}
}
},
{
id: NODE_ID_3, // general-cluster
model: {
id: MODEL_ID_3, // cccbe437d6e54e2bb911c6aa292fb072
model_version: {
id: MODEL_VERSION_ID_3, // cc2074cff6dc4c02b6f4e1b8606dcb54
}
}
},
{
id: NODE_ID_4, // mapper
model: {
id: SYNONYM_MODEL_ID, // synonym-model-id
model_version: {
id: SYNONYM_MODEL_VERSION_ID
}
},
node_inputs: [
{
node_id: NODE_ID_2 // general-concept
}
]
},
{
id: NODE_ID_5, // greater-than
model: {
id: GREATER_THAN_MODEL_ID, // greater-than-model-id
model_version: {
id: GREATER_THAN_MODEL_VERSION_ID
}
},
node_inputs: [
{
node_id: NODE_ID_4 // mapper
}
]
},
{
id: NODE_ID_6, // write-success
model: {
id: WRITE_SUCCESS_MODEL_ID,
model_version: {
id: WRITE_SUCCESS_MODEL_VERSION_ID
}
},
node_inputs: [
{
node_id: NODE_ID_5 // greater-than
}
]
},
{
id: NODE_ID_7, // less-than
model: {
id: LESS_THAN_MODEL_ID,
model_version: {
id: LESS_THAN_MODEL_VERSION_ID
}
},
node_inputs: [
{
node_id: NODE_ID_4 // mapper
}
]
},
{
id: NODE_ID_8, // write-pending
model: {
id: WRITE_PENDING_MODEL_ID,
model_version: {
id: WRITE_PENDING_MODEL_VERSION_ID
}
},
node_inputs: [
{
node_id: NODE_ID_7 // less-than
}
]
}
]
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
console.log(response.status);
throw new Error("Post workflows failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the
// workflow we want to create. 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 create your own workflow
// Note that we've also added as comments the values of most of these variables against their names in the code below
static final String WORKFLOW_ID = "auto-annotation-workflow-id";
static final String NODE_ID_1 = "general-embed";
static final String MODEL_ID_1 = "bbb5f41425b8468d9b7a554ff10f8581";
static final String MODEL_VERSION_ID_1 = "bb186755eda04f9cbb6fe32e816be104";
static final String NODE_ID_2 = "general-concept";
static final String MODEL_ID_2 = "aaa03c23b3724a16a56b629203edc62c";
static final String MODEL_VERSION_ID_2 = "aa7f35c01e0642fda5cf400f543e7c40";
static final String NODE_ID_3 = "general-cluster";
static final String MODEL_ID_3 = "cccbe437d6e54e2bb911c6aa292fb072";
static final String MODEL_VERSION_ID_3 = "cc2074cff6dc4c02b6f4e1b8606dcb54";
static final String NODE_ID_4 = "mapper";
static final String SYNONYM_MODEL_ID = "synonym-model-id";
static final String SYNONYM_MODEL_VERSION_ID = "YOUR_SYNONYM_MODEL_VERSION_ID";
static final String NODE_ID_5 = "greater-than";
static final String GREATER_THAN_MODEL_ID = "greater-than-model-id";
static final String GREATER_THAN_MODEL_VERSION_ID = "YOUR_GREATER_THAN_MODEL_VERSION_ID";
static final String NODE_ID_6 = "write-as-success-as-me";
static final String WRITE_SUCCESS_MODEL_ID = "write-success-as-me-id";
static final String WRITE_SUCCESS_MODEL_VERSION_ID = "YOUR_WRITE_SUCCESS_MODEL_VERSION_ID";
static final String NODE_ID_7 = "less-than";
static final String LESS_THAN_MODEL_ID = "less-than-model-id";
static final String LESS_THAN_MODEL_VERSION_ID = "YOUR_LESS_THAN_MODEL_VERSION_ID";
static final String NODE_ID_8 = "write-pending";
static final String WRITE_PENDING_MODEL_ID = "write-pending-as-me-id";
static final String WRITE_PENDING_MODEL_VERSION_ID = "YOUR_WRITE_PENDING_MODEL_VERSION_ID";
///////////////////////////////////////////////////////////////////////////////////
// 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));
MultiWorkflowResponse postWorkflowsResponse = stub.postWorkflows(
PostWorkflowsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addWorkflows(
Workflow.newBuilder()
.setId(WORKFLOW_ID) //auto-annotation-workflow-id
.addNodes(
WorkflowNode.newBuilder()
.setId(NODE_ID_1) // general-embed
.setModel(
Model.newBuilder()
.setId(MODEL_ID_1) // bbb5f41425b8468d9b7a554ff10f8581
.setModelVersion(
ModelVersion.newBuilder()
.setId(MODEL_VERSION_ID_1) // bb186755eda04f9cbb6fe32e816be104
)
)
)
.addNodes(
WorkflowNode.newBuilder()
.setId(NODE_ID_2) // general-concept
.setModel(
Model.newBuilder()
.setId(MODEL_ID_2) // aaa03c23b3724a16a56b629203edc62c
.setModelVersion(
ModelVersion.newBuilder()
.setId(MODEL_VERSION_ID_2) // aa7f35c01e0642fda5cf400f543e7c40
)
)
)
.addNodes(
WorkflowNode.newBuilder()
.setId(NODE_ID_3) // general-cluster
.setModel(
Model.newBuilder()
.setId(MODEL_ID_3) // cccbe437d6e54e2bb911c6aa292fb072
.setModelVersion(
ModelVersion.newBuilder()
.setId(MODEL_VERSION_ID_3) // cc2074cff6dc4c02b6f4e1b8606dcb54
)
)
)
.addNodes(
WorkflowNode.newBuilder()
.setId(NODE_ID_4) // mapper
.setModel(
Model.newBuilder()
.setId(SYNONYM_MODEL_ID) // synonym-model-id
.setModelVersion(
ModelVersion.newBuilder()
.setId(SYNONYM_MODEL_VERSION_ID)
)
)
.addNodeInputs(NodeInput.newBuilder().setNodeId(NODE_ID_2)) // general-concept
)
.addNodes(
WorkflowNode.newBuilder()
.setId(NODE_ID_5) // greater-than
.setModel(
Model.newBuilder()
.setId(GREATER_THAN_MODEL_ID) // greater-than-model-id
.setModelVersion(
ModelVersion.newBuilder()
.setId(GREATER_THAN_MODEL_VERSION_ID)
)
)
.addNodeInputs(NodeInput.newBuilder().setNodeId(NODE_ID_4)) // mapper
)
.addNodes(
WorkflowNode.newBuilder()
.setId(NODE_ID_6) // write-as-success-as-me
.setModel(
Model.newBuilder()
.setId(WRITE_SUCCESS_MODEL_ID) // write-success-as-me-id
.setModelVersion(
ModelVersion.newBuilder()
.setId(WRITE_SUCCESS_MODEL_VERSION_ID)
)
)
.addNodeInputs(NodeInput.newBuilder().setNodeId(NODE_ID_5)) // greater-than
)
.addNodes(
WorkflowNode.newBuilder()
.setId(NODE_ID_7) // less-than
.setModel(
Model.newBuilder()
.setId(LESS_THAN_MODEL_ID)
.setModelVersion(
ModelVersion.newBuilder()
.setId(LESS_THAN_MODEL_VERSION_ID)
)
)
.addNodeInputs(NodeInput.newBuilder().setNodeId(NODE_ID_4)) // mapper
)
.addNodes(
WorkflowNode.newBuilder()
.setId(NODE_ID_8) // write-pending
.setModel(
Model.newBuilder()
.setId(WRITE_PENDING_MODEL_ID) // write-pending-as-me-id
.setModelVersion(
ModelVersion.newBuilder()
.setId(WRITE_PENDING_MODEL_VERSION_ID)
)
)
.addNodeInputs(NodeInput.newBuilder().setNodeId(NODE_ID_7)) // less-than
)
)
.build()
);
if (postWorkflowsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post workflows failed, status: " + postWorkflowsResponse.getStatus());
}
}
}
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/workflows" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
--data-raw '{
"workflows": [
{
"id": "auto-annotation-workflow-id",
"nodes": [
{
"id": "general-embed",
"model": {
"id": "YOUR_GENERAL_EMBED_MODEL_ID_HERE",
"model_version": {
"id": "YOUR_GENERAL_EMBED_MODEL_VERSION_ID_HERE"
}
}
},
{
"id": "general-concept",
"model": {
"id": "YOUR_GENERAL_CONCEPT_MODEL_ID_HERE",
"model_version": {
"id": "YOUR_GENERAL_CONCEPT_MODEL_VERSION_ID_HERE"
}
}
},
{
"id": "general-cluster",
"model": {
"id": "YOUR_GENERAL_CLUSTER_MODEL_ID_HERE",
"model_version": {
"id": "YOUR_GENERAL_CLUSTER_MODEL_VERSION_ID_HERE"
}
}
},
{
"id": "mapper",
"model": {
"id": "synonym-model-id",
"model_version": {
"id": "YOUR_MAPPER_MODEL_VERSION_ID_HERE"
}
},
"node_inputs": [
{
"node_id": "general-concept"
}
]
},
{
"id": "greater-than",
"model": {
"id": "greater-than-model-id",
"model_version": {
"id": "YOUR_GREATER_THAN_MODEL_VERSION_ID_HERE"
}
},
"node_inputs": [
{
"node_id": "mapper"
}
]
},
{
"id": "write-success",
"model": {
"id": "write-success-as-me",
"model_version": {
"id": "YOUR_WRITE_AS_ME_MODEL_VERSION_ID_HERE"
}
},
"node_inputs": [
{
"node_id": "greater-than"
}
]
},
{
"id": "less-than",
"model": {
"id": "less-than-model-id",
"model_version": {
"id": "YOUR_LESS_THAN_MODEL_VERSION_ID_HERE"
}
},
"node_inputs": [
{
"node_id": "mapper"
}
]
},
{
"id": "write-pending",
"model": {
"id": "write-pending-as-me",
"model_version": {
"id": "YOUR_WRITE_AS_COLLABORATOR_MODEL_VERSION_ID_HERE"
}
},
"node_inputs": [
{
"node_id": "less-than"
}
]
}
]
}
]
}'
Make the New Workflow Your App's Default
Make this the default workflow in the app. So, it will run every time we add an input and execute the auto annotation process.
If the workflow is not the default workflow of your app, you can still use PostWorkflowResults
on new inputs to check that you configured the workflow graph and your models properly, but the data will not be written to the DB. This is recommended before making it your default workflow and adding inputs to your app.
- gRPC Python
- gRPC NodeJS
- gRPC Java
- cURL
#######################################################################################
# In this section, we set the user authentication, app ID, and the ID of the workflow
# we want to make as default. 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 this to make your own default workflow
DEFAULT_WORKFLOW_ID = 'auto-annotation-workflow-id'
##########################################################################
# 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) # The userDataObject is required when using a PAT
patch_apps_response = stub.PatchApps(
service_pb2.PatchAppsRequest(
user_app_id=userDataObject,
action="overwrite",
apps=[
resources_pb2.App(
id=APP_ID,
default_workflow_id=DEFAULT_WORKFLOW_ID
)
]
),
metadata=metadata
)
if patch_apps_response.status.code != status_code_pb2.SUCCESS:
print(patch_apps_response.status)
raise Exception("Patch apps failed, status: " + patch_apps_response.status.description)
//index.js file
/////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the ID of the workflow
// we want to make as default. 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 make your own default workflow
const DEFAULT_WORKFLOW_ID = 'auto-annotation-workflow-id';
/////////////////////////////////////////////////////////////////////////////
// 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.PatchApps(
{
user_app_id: {
user_id: USER_ID,
app_id: APP_ID
},
action: "overwrite",
apps: [
{
id: APP_ID,
default_workflow_id: DEFAULT_WORKFLOW_ID
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
console.log(response.status);
throw new Error("Patch apps failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
/////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the ID of the workflow
// we want to make as default. 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 this to make your own default workflow
static final String DEFAULT_WORKFLOW_ID = "auto-annotation-workflow-id";
///////////////////////////////////////////////////////////////////////////////////
// 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));
MultiAppResponse patchAppsResponse = stub.patchApps(
PatchAppsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setAction("overwrite")
.addApps(
App.newBuilder()
.setId(APP_ID)
.setDefaultWorkflowId(DEFAULT_WORKFLOW_ID)
).build()
);
if (patchAppsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Patch apps failed, status: " + patchAppsResponse.getStatus());
}
}
}
curl -X PATCH "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
--data-raw '{
"action": "overwrite",
"apps": [
{
"id": "YOUR_APP_ID_HERE",
"default_workflow_id": "auto-annotation-workflow-ID"
}
]
}'
Add an Image
Adding an image will trigger the default workflow.
- gRPC Python
- gRPC NodeJS
- gRPC Java
- cURL
#####################################################################################
# In this section, we set the user authentication, app ID, and the URL of the image
# we want to add. 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 this to add your own image
IMAGE_URL = 'https://samples.clarifai.com/metro-north.jpg'
##########################################################################
# 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) # The userDataObject is required when using a PAT
post_inputs_response = stub.PostInputs(
service_pb2.PostInputsRequest(
user_app_id=userDataObject,
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
url=IMAGE_URL
)
)
)
]
),
metadata=metadata
)
if post_inputs_response.status.code != status_code_pb2.SUCCESS:
print(post_inputs_response.status)
raise Exception("Post inputs failed, status: " + post_inputs_response.status.description)
//index.js file
/////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the URL of the image
// we want to add. 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 add your own image
const IMAGE_URL = 'https://samples.clarifai.com/metro-north.jpg';
/////////////////////////////////////////////////////////////////////////////
// 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.PostInputs(
{
user_app_id: {
user_id: USER_ID,
app_id: APP_ID
},
inputs: [
{
data: {
image: {
url: IMAGE_URL
}
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
console.log(response.status);
throw new Error("Post inputs failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
/////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the URL of the image
// we want to add. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_PAT_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 this to add your own image
static final String IMAGE_URL = "https://samples.clarifai.com/metro-north.jpg";
///////////////////////////////////////////////////////////////////////////////////
// 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));
MultiInputResponse postInputsResponse = stub.postInputs(
PostInputsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addInputs(
Input.newBuilder()
.setData(
Data.newBuilder()
.setImage(
Image.newBuilder()
.setUrl(IMAGE_URL)
)
)
)
.build()
);
if (postInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post inputs failed, status: " + postInputsResponse.getStatus());
}
}
}
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/inputs" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
--data-raw '{
"inputs": [
{
"data": {
"image": {
"url": "https://samples.clarifai.com/metro-north.jpg"
}
}
}
]
}'
List Annotations
You can now list annotations with your user ID and see the annotations created by your workflow.
- gRPC Python
- gRPC NodeJS
- gRPC Java
- 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) # The userDataObject is required when using a PAT
list_annotations_response = stub.ListAnnotations(
service_pb2.ListAnnotationsRequest(
user_app_id=userDataObject,
user_ids=[USER_ID],
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 in list_annotations_response.annotations:
print(annotation)
//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: {
app_id: APP_ID
},
user_ids: [USER_ID],
list_all_annotations: true
},
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(annotation);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
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))
.addUserIds(USER_ID)
.setListAllAnnotations(true)
.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);
}
}
}
curl -X GET "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations" \
-H "Authorization: Key YOUR_PAT_HERE" \