Clarifai Guide
Clarifai Home
v7.11
v7.11
  • Welcome
  • Clarifai Basics
    • Start Here (5 mins or less!)
      • Your First AI Predictions (~1 min)
      • Your First Visual Search App (~1 min)
      • Your First Custom Model (~5 mins)
    • Key Terminology to Know
    • Applications
      • Create an Application
      • Application Settings
      • Collaboration
    • Authentication
      • App-Specific API Keys
      • Authorize
      • Personal Access Tokens
      • Scopes
      • 2FA
      • Roll-Based Access Control
    • Clarifai Community Quick Start
  • API Guide
    • Clarifai API Basics
      • Clarifai API Clients
        • gRPC vs HTTP Channels
      • Helpful API Resources
        • Using Postman with Clarifai APIs
    • Your Data
      • Datasets
        • Dataset Basics
        • Dataset Filters
        • Dataset Inputs
        • Dataset Versions
      • Supported Formats
      • Adding and Removing Data
      • Collectors
    • Making Predictions
      • Images
      • Video
      • Text
      • Prediction Parameters
      • Multilingual Classification
    • Creating and Managing Concepts
      • Create, Get, Update
      • Languages
      • Search by Concept
      • Knowledge Graph
    • Labeling Your Data
      • Annotations
      • Training Data
      • Positive and Negative Annotations
      • Tasks
      • Task Annotations
    • Creating and Training Models
      • Clarifai Models
      • Model Types
      • Custom Models
      • Custom Text Model
      • Create, Get, Update, Delete
      • Deep Training
    • Evaluating Models
      • Interpreting Evaluations
      • Improving Your Model
    • Creating Workflows
      • Base Workflows
      • Input Nodes
      • Setting Up Mesh Workflows
      • Common Workflows
        • Workflow Predict
        • Auto Annotation
        • Custom KNN Face Classifier Workflow
        • Visual Text Recognition
    • Search, Sort, Filter and Save
      • Search Overview
      • Combine or Negate
      • Filter
      • Rank
      • Index Images for Search
      • Legacy Search
        • Combine or Negate
        • Filter
        • Rank
        • Saved Searches
    • Advanced Topics
      • Status Codes
      • Patching
      • Pagination
      • Batch Predict CSV on Custom Text Model
      • Document Processing
  • Portal Guide
    • Clarifai Portal Basics
    • Your Data
      • Supported Formats
      • Exploring Your Data
        • Predictions
        • Annotations
        • Bulk Labeling
        • Proposals
        • Object Tracking
      • Collectors
    • Making Predictions
    • Creating and Managing Concepts
      • Create, Get, Update, Delete
      • Knowledge Graph
      • Languages
    • Labeling Your Data
      • Create a Task
      • Label Types
      • Labeling Tools
      • AI Assist
      • Workforce Management
      • Review
      • Training Data
      • Positive and Negative Annotations
    • Creating and Training Models
      • Training Basics
      • Clarifai Models
      • Custom Models
      • Model Types
      • Deep Training
    • Evaluating Models
      • Interpreting Evaluations
      • Improving Your Model
    • Creating Workflows
      • Input Nodes
      • Workflow Builder
      • Base Workflows
      • Setting Up a Workflow
      • Common Workflows
        • Auto Annotation
        • Visual Text Recognition
        • Text Classification
    • Search, Sort, Filter and Save
      • Rank
      • Filter
      • Combine or Negate
      • Saved Searches
      • Visual Search
      • Text Search
    • Advanced Topics
      • Importing Data with CSV and TSV Files
  • Data Labeling Services
    • Scribe LabelForce
  • Product Updates
    • Upcoming API Changes
    • Changelog
      • Release 8.1
      • Release 8.0
      • Release 7.11
      • Release 7.10
      • Release 7.9
      • Release 7.8
      • Release 7.7
      • Release 7.6
      • Release 7.5
      • Release 7.4
      • Release 7.3
      • Release 7.2
      • Release 7.1
      • Release 7.0
      • Release 6.11
      • Release 6.10
      • Release 6.9
      • Release 6.8
      • Release 6.7
      • Release 6.6
      • Release 6.5
      • Release 6.4
      • Release 6.3
      • Release 6.2
      • Release 6.1
      • Release 6.0
      • Release 5.11
      • Release 5.10
  • Additional Resources
    • API Status
    • Clarifai Blog
    • Clarifai Help
    • Clarifai Community
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. API Guide
  2. Creating Workflows
  3. Common Workflows

Workflow Predict

Make model predictions in your workflows.

PreviousCommon WorkflowsNextAuto Annotation

Last updated 3 years ago

Was this helpful?

The Workflow Predict API allows you to predict using 1 or more model(s), regardless of them being Clarifai or custom, within a single API call. The max number of inputs processed at once with any given workflow is 32.

Now that you have that all set up, you will be able to predict under a workflow using the POST /v2/workflows/{workflow_id}/results endpoint. Your {workflow-id} currently is whatever you set as your ID. Then as far as your request body, nothing has changed with how you would normally do a predict. In the response body, you will see a results object and each object will be the response from the models in the same ordering from the workflow you set up.

You can also use the Explorer in Clarifai Portal to see the results of your workflow's predictions on a given input.

import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;

// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions

PostWorkflowResultsResponse postWorkflowResultsResponse = stub.postWorkflowResults(
    PostWorkflowResultsRequest.newBuilder()
        .setWorkflowId("{YOUR_WORKFLOW_ID}")
        .addInputs(
            Input.newBuilder().setData(
                Data.newBuilder().setImage(
                    Image.newBuilder().setUrl(
                        "https://samples.clarifai.com/metro-north.jpg"
                    )
                )
            )
        )
        .build()
);

if (postWorkflowResultsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
  throw new RuntimeException("Post workflow results failed, status: " + postWorkflowResultsResponse.getStatus());
}

// We'll get one WorkflowResult for each input we used above. Because of one input, we have here
// one WorkflowResult.
WorkflowResult results = postWorkflowResultsResponse.getResults(0);

// Each model we have in the workflow will produce one output.
for (Output output : results.getOutputsList()) {
    Model model = output.getModel();

    System.out.println("Predicted concepts for the model `" + model.getName() + "`:");
    for (Concept concept : output.getData().getConceptsList()) {
        System.out.printf("\t%s %.2f%n", concept.getName(), concept.getValue());
    }
}
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions

stub.PostWorkflowResults(
    {
        workflow_id: "{YOUR_WORKFLOW_ID}",
        inputs: [
            {data: {image: {url: "https://samples.clarifai.com/metro-north.jpg"}}}
        ]
    },
    metadata,
    (err, response) => {
        if (err) {
            throw new Error(err);
        }

        if (response.status.code !== 10000) {
            throw new Error("Post workflow results failed, status: " + response.status.description);
        }

        // We'll get one WorkflowResult for each input we used above. Because of one input, we have here
        // one WorkflowResult.
        const results = response.results[0];

        // Each model we have in the workflow will produce one output.
        for (const output of results.outputs) {
            const model = output.model;

            console.log("Predicted concepts for the model `" + model.name + "`:");
            for (const concept of output.data.concepts) {
                console.log("\t" + concept.name + " " + concept.value);
            }
        }
    }
);
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions

post_workflow_results_response = stub.PostWorkflowResults(
    service_pb2.PostWorkflowResultsRequest(
        user_app_id=userDataObject,  # The userDataObject is created in the overview and is required when using a PAT
        workflow_id="{YOUR_WORKFLOW_ID}",
        inputs=[
            resources_pb2.Input(
                data=resources_pb2.Data(
                    image=resources_pb2.Image(
                        url="https://samples.clarifai.com/metro-north.jpg"
                    )
                )
            )
        ]
    ),
    metadata=metadata
)
if post_workflow_results_response.status.code != status_code_pb2.SUCCESS:
    raise Exception("Post workflow results failed, status: " + post_workflow_results_response.status.description)

# We'll get one WorkflowResult for each input we used above. Because of one input, we have here
# one WorkflowResult.
results = post_workflow_results_response.results[0]

# Each model we have in the workflow will produce one output.
for output in results.outputs:
    model = output.model

    print("Predicted concepts for the model `%s`" % model.name)
    for concept in output.data.concepts:
        print("\t%s %.2f" % (concept.name, concept.value))
curl -X POST \
  -H 'authorization: Key YOUR_API_KEY' \
  -H 'content-type: application/json' \
  -d '{
    "inputs": [
        {
          "data": {
            "image": {
              "url": "https://samples.clarifai.com/metro-north.jpg"
          }
        }
      }
    ]
}'\
https://api.clarifai.com/v2/workflows/{YOUR_WORKFLOW_ID}/results
{
  "status": {
    "code": 10000,
    "description": "Ok"
  },
  "workflow": {
    "id": "my-workflow",
    "app_id": "c54b7637df12407aa9c57dfd6d5c057f",
    "created_at": "2017-07-10T01:45:05.672880Z"
  },
  "results": [
    {
      "status": {
        "code": 10000,
        "description": "Ok"
      },
      "input": {
        "id": "c88aeed9d04c471cace6f8e4801f1a1c",
        "data": {
          "image": {
            "url": "https://samples.clarifai.com/metro-north.jpg"
          }
        }
      },
      "outputs": [
        {
          "id": "feae971167a04d1bbebb7ea49d6ba0f7",
          "status": {
            "code": 10000,
            "description": "Ok"
          },
          "created_at": "2017-07-10T12:01:44.929928529Z",
          "model": {
            "id": "d16f390eb32cad478c7ae150069bd2c6",
            "name": "moderation",
            "created_at": "2017-05-12T21:28:00.471607Z",
            "app_id": "main",
            "output_info": {
              "message": "Show output_info with: GET /models/{model_id}/output_info",
              "type": "concept",
              "type_ext": "concept"
            },
            "model_version": {
              "id": "b42ac907ac93483484483a0040a386be",
              "created_at": "2017-05-12T21:28:00.471607Z",
              "status": {
                "code": 21100,
                "description": "Model trained successfully"
              }
            }
          },
          "data": {
            "concepts": [
              {
                "id": "ai_QD1zClSd",
                "name": "safe",
                "value": 0.99999714,
                "app_id": "main"
              },
              {
                "id": "ai_kBBGf7r8",
                "name": "gore",
                "value": 3.7771046e-05,
                "app_id": "main"
              },
              {
                "id": "ai_8QQwMjQR",
                "name": "drug",
                "value": 1.0449563e-05,
                "app_id": "main"
              },
              {
                "id": "ai_V76bvrtj",
                "name": "explicit",
                "value": 5.2887003e-06,
                "app_id": "main"
              },
              {
                "id": "ai_RtXh5qkR",
                "name": "suggestive",
                "value": 4.7939684e-06,
                "app_id": "main"
              }
            ]
          }
        },
        {
          "id": "f635b40cbeee47ddb7b348a981e14faf",
          "status": {
            "code": 10000,
            "description": "Ok"
          },
          "created_at": "2017-07-10T12:01:44.929941126Z",
          "model": {
            "id": "aaa03c23b3724a16a56b629203edc62c",
            "name": "general-v1.3",
            "created_at": "2016-02-26T23:38:40.086101Z",
            "app_id": "main",
            "output_info": {
              "message": "Show output_info with: GET /models/{model_id}/output_info",
              "type": "concept",
              "type_ext": "concept"
            },
            "model_version": {
              "id": "aa9ca48295b37401f8af92ad1af0d91d",
              "created_at": "2016-07-13T00:58:55.915745Z",
              "status": {
                "code": 21100,
                "description": "Model trained successfully"
              }
            }
          },
          "data": {
            "concepts": [
              {
                "id": "ai_HLmqFqBf",
                "name": "train",
                "value": 0.9989112,
                "app_id": "main"
              },
              {
                "id": "ai_fvlBqXZR",
                "name": "railway",
                "value": 0.9975532,
                "app_id": "main"
              },
              {
                "id": "ai_Xxjc3MhT",
                "name": "transportation system",
                "value": 0.9959158,
                "app_id": "main"
              },
              {
                "id": "ai_6kTjGfF6",
                "name": "station",
                "value": 0.992573,
                "app_id": "main"
              },
              {
                "id": "ai_RRXLczch",
                "name": "locomotive",
                "value": 0.992556,
                "app_id": "main"
              },
              {
                "id": "ai_VRmbGVWh",
                "name": "travel",
                "value": 0.98789215,
                "app_id": "main"
              },
              {
                "id": "ai_SHNDcmJ3",
                "name": "subway system",
                "value": 0.9816359,
                "app_id": "main"
              },
              {
                "id": "ai_jlb9q33b",
                "name": "commuter",
                "value": 0.9712483,
                "app_id": "main"
              },
              {
                "id": "ai_46lGZ4Gm",
                "name": "railroad track",
                "value": 0.9690325,
                "app_id": "main"
              },
              {
                "id": "ai_tr0MBp64",
                "name": "traffic",
                "value": 0.9687052,
                "app_id": "main"
              },
              {
                "id": "ai_l4WckcJN",
                "name": "blur",
                "value": 0.9667078,
                "app_id": "main"
              },
              {
                "id": "ai_2gkfMDsM",
                "name": "platform",
                "value": 0.9624243,
                "app_id": "main"
              },
              {
                "id": "ai_CpFBRWzD",
                "name": "urban",
                "value": 0.960752,
                "app_id": "main"
              },
              {
                "id": "ai_786Zr311",
                "name": "no person",
                "value": 0.95864904,
                "app_id": "main"
              },
              {
                "id": "ai_6lhccv44",
                "name": "business",
                "value": 0.95720303,
                "app_id": "main"
              },
              {
                "id": "ai_971KsJkn",
                "name": "track",
                "value": 0.9494642,
                "app_id": "main"
              },
              {
                "id": "ai_WBQfVV0p",
                "name": "city",
                "value": 0.94089437,
                "app_id": "main"
              },
              {
                "id": "ai_dSCKh8xv",
                "name": "fast",
                "value": 0.9399334,
                "app_id": "main"
              },
              {
                "id": "ai_TZ3C79C6",
                "name": "road",
                "value": 0.93121606,
                "app_id": "main"
              },
              {
                "id": "ai_VSVscs9k",
                "name": "terminal",
                "value": 0.9230834,
                "app_id": "main"
              }
            ]
          }
        }
      ]
    }
  ]
}
Image showing the Portal's workflow prediction results