Skip to main content

Input Nodes

Connect your models together


The outputs from one model can be used as inputs for another model. This allows you to link together the models in a graph. Linking models helps you build sophisticated AI solutions that can zero-in on a specific use case.

Supported Input and Output Types

To view your available models, just open your application in the Portal and click the Model Mode icon on the left-hand side of the screen. From there, just click the Create a Custom Model button on the top right-hand corner of the screen.

Different models accept different types of inputs and return different types of outputs. They are named after the fields in the Data object of our API. This object uses inputs, annotations, models, and workflows.

Some examples include:

Inputs

  • Concepts
  • Embeddings
  • Image
  • Image or video
  • Regions

Outputs

  • Concepts
  • Clusters
  • Regions

The Building Blocks

You can create workflows out of any Clarifai Models or custom models that you have created for your app. The inputs and outputs supported by your custom models will depend on the inputs and outputs supported by the Clarifai Models, or model templates that you have used to build them.

info

The initialization code used in the following examples is outlined in detail on the client installation page.

Sample Workflow With Multiple Connected Nodes

The following is an example of how to build a workflow with multiple connected nodes. Note that model IDs and model version IDs from the public clarifai/main application are fixed, so they are already hard-coded in the code examples below. It is possible to use other public model or model version IDs.

###################################################################################
# In this section, we set the user authentication, app ID, and the details of the
# workflow we want to build. 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 build your own workflow with multiple connected nodes
# 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 = 'YOUR_SYNONYM_MODEL_ID'
SYNONYM_MODEL_VERSION_ID = 'YOUR_SYNONYM_MODEL_VERSION_ID'

NODE_ID_5 = 'greater-than'
GREATER_THAN_MODEL_ID = 'YOUR_GREATER_THAN_MODEL_ID'
GREATER_THAN_MODEL_VERSION_ID = 'YOUR_GREATER_THAN_MODEL_VERSION_ID'

NODE_ID_6 = 'less-than'
LESS_THAN_MODEL_ID = 'YOUR_LESS_THAN_MODEL_ID'
LESS_THAN_MODEL_VERSION_ID = 'YOUR_LESS_THAN_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
)
),
node_inputs=[
resources_pb2.NodeInput(node_id=NODE_ID_1) # general-embed
]
),
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, # 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
]
),
]
)
]
),
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)

Suppressing the Output From Nodes

It is possible to turn the outputs from given nodes in your workflow on and off with the suppress_output endpoint. This can be helpful when you want to hide outputs for expensive return values like image crops or embedding.

By default, this endpoint will be set to false, meaning that we do not suppress any model's output.

###################################################################################
# In this section, we set the user authentication, app ID, and the details of the
# nodes to suppress their outputs. 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 suppress the outputs of your own nodes
WORKFLOW_ID = 'predict-cluster-only'
NODE_ID_1 = 'general-embed'
MODEL_ID_1 = 'bbb5f41425b8468d9b7a554ff10f8581'
MODEL_VERSION_ID_1 = 'bb186755eda04f9cbb6fe32e816be104'

NODE_ID_2 = 'general-cluster'
MODEL_ID_2 = 'cccbe437d6e54e2bb911c6aa292fb072'
MODEL_VERSION_ID_2 = 'cc2074cff6dc4c02b6f4e1b8606dcb54'

##########################################################################
# 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,
nodes=[
resources_pb2.WorkflowNode(
id=NODE_ID_1,
model=resources_pb2.Model(
id=MODEL_ID_1,
model_version=resources_pb2.ModelVersion(
id=MODEL_VERSION_ID_1
)
),
suppress_output = True
),
resources_pb2.WorkflowNode(
id=NODE_ID_2,
model=resources_pb2.Model(
id=MODEL_ID_2,
model_version=resources_pb2.ModelVersion(
id=MODEL_VERSION_ID_2
)
),
node_inputs=[
resources_pb2.NodeInput(node_id=NODE_ID_1)
]
),
]
)
]
),
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)