Skip to main content

Manage Workflows

Manage workflows


Manage via the UI

Edit Workflow

After creating your workflow, you can edit it at any time by navigating to its individual page and clicking the Edit workflow button in the upper-right section.

This allows you to make changes easily whenever needed.

alt_text

For example, to add a text-to-audio node to your workflow, first locate it in the left sidebar. Drag the node and connect it to the preceding text-to-text node. Next, use the search box on the right side of the page to select the specific model you want for the text-to-audio conversion.

alt_text

Once you've made your changes, click the Save as new version button to save the updated workflow under a new version — without exiting the workflow editor.

note
  • You can easily switch between different versions by selecting the respective version ID from the left sidebar in the workflow editor.
  • Clicking the Update Workflow button creates a new workflow version and exits the workflow editor, redirecting to the workflow's main page.

alt_text

tip
  • You can add a maximum of 20 nodes in a single workflow.
  • Ensure all connections between nodes are correctly set to avoid errors during execution.

Manage via the API

Get

Get all Workflows in an App

You can return all custom workflows in your app.

tip

If you want to get a list of the workflows not within the scope of your app, you need to use your PAT while specifying the user_id of their owner and the app_id of the application that you’re accessing. For example, to get Clarifai's workflows in the main app, you need to use your PAT while specifying Clarifai's user_id as "clarifai" and app_id as "main" in the request.

from clarifai.client.app import App

# Your PAT (Personal Access Token) can be found in the Account's Security section
app = App(app_id="APP_ID", user_id="USER_ID", pat="YOUR_PAT")

for workflow in app.list_workflows(page_no=1,per_page=7):
print("Workflow ID: ", workflow.id)
Output
Workflow ID:  object_track

Workflow ID: video_track

Workflow ID: multimodal_to_text

Workflow ID: text_to_audio

Workflow ID: upscale_workflow

Workflow ID: image_generation

Workflow ID: text_generation

Get a Workflow by a Specific ID

You can return information about a specific workflow.

############################################################################
# In this section, we set the user authentication, app ID, and workflow ID.
# Change these strings to run your own example.
#############################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change this to your own workflow ID
WORKFLOW_ID = 'my-custom-workflow'

##########################################################################
# 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

get_workflow_response = stub.GetWorkflow(
service_pb2.GetWorkflowRequest(
user_app_id=userDataObject,
workflow_id=WORKFLOW_ID
),
metadata=metadata
)

if get_workflow_response.status.code != status_code_pb2.SUCCESS:
print(get_workflow_response.status)
raise Exception("Get workflow failed, status: " + get_workflow_response.status.description)

workflow = get_workflow_response.workflow
print(f"The workflow consists of these models:")
for workflow_node in workflow.nodes:
model = workflow_node.model
print(model.id)

Update

After creating a workflow, you can perform patch operations on it by merging, removing, or overwriting data. By default, all actions support overwriting, with specific behaviors for lists of objects.

  • The merge action updates an existing key:value pair with key:new_value or appends to an existing list. For dictionaries, it merges objects that share a matching id field.
  • The remove action is only used to delete the workflow's cover image on the platform UI.
  • The overwrite action fully replaces an existing object with a new one.

Patch Workflow's Models

You can change a workflow; that is, change the models of which the workflow consists.

###################################################################################
# In this section, we set the user authentication, app ID, and the details of the
# workflow we want to update. 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 update your own workflow
WORKFLOW_ID = 'my-custom-workflow'
NODE_ID_1 = 'audio-to-text'
MODEL_ID_1 = 'asr-wav2vec2-base-960h-english'
MODEL_VERSION_ID_1 = 'f4deae70a473492a8e2f9b7bb1dbee85'

NODE_ID_2 = 'text-summarization'
MODEL_ID_2 = 'text-summarization-english-distilbart-cnn-12-6'
MODEL_VERSION_ID_2 = '8279cec2221a4b1d9db774470940aebd'

NODE_ID_3 = 'english-to-french'
MODEL_ID_3 = 'translation-english-to-french-text'
MODEL_VERSION_ID_3 = 'c65a4a51c2b646fca5f0e4bf1ff200d7'

##########################################################################
# 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_workflows_response = stub.PatchWorkflows(
service_pb2.PatchWorkflowsRequest(
user_app_id=userDataObject,
action="overwrite",
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
)
)
),
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)
]
),
resources_pb2.WorkflowNode(
id=NODE_ID_3,
model=resources_pb2.Model(
id=MODEL_ID_3,
model_version=resources_pb2.ModelVersion(
id=MODEL_VERSION_ID_3
)
),
node_inputs=[
resources_pb2.NodeInput(node_id=NODE_ID_2)
]
),
]
)
]
),
metadata=metadata
)

if patch_workflows_response.status.code != status_code_pb2.SUCCESS:
print(patch_workflows_response.status)
raise Exception("Patch workflows failed, status: " + patch_workflows_response.status.description)

Patch YAML Configuration, Description, etc

Below is an example of performing patch operations on a workflow, where the YAML configuration is updated, and changes are made to its description, notes, and image URL.

from clarifai.client.app import App

app = App(app_id="YOUR_APP_ID_HERE", user_id="YOUR_USER_ID_HERE", pat="YOUR_PAT_HERE")

# Update an existing workflow to use a different yml configuration like "demographics"
WORKFLOW_ID = general_workflow.kwargs['id']
app.patch_workflow(workflow_id=WORKFLOW_ID, action="merge", config_filepath="configs/demographics.yml")

# Update workflow details, such as description, notes, etc
app.patch_workflow(workflow_id=WORKFLOW_ID, action="merge", description="description", notes="notes", image_url="https://samples.clarifai.com/metro-north.jpg")

# Remove the workflow's image by specifying the 'remove' action
app.patch_workflow(workflow_id=WORKFLOW_ID, action="remove", image_url="https://samples.clarifai.com/metro-north.jpg")

Delete

caution

Be certain that you want to delete a particular workflow as the operation cannot be undone.

Delete Workflow by ID

You can delete a specific workflow.

from clarifai.client.app import App

# Your PAT (Personal Access Token) can be found in the Account's Security section
app = App(app_id="APP_ID", user_id="USER_ID", pat="YOUR_PAT")
# Delete the workflow within an application
app.delete_workflow(workflow_id="workflow-id")
Output
2024-01-18 16:34:46 INFO     clarifai.client.app:                                                        app.py:653

Workflow Deleted

code: SUCCESS

description: "Ok"

req_id: "a979f35e9c826bb9046f4d92879c6b7c"

Delete all Workflows

You can delete all custom workflows.

tip

Instead of delete_all, you can specify a list of workflow IDs to be deleted, using the ids field.

###################################################################
# 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

delete_workflows_response = stub.DeleteWorkflows(
service_pb2.DeleteWorkflowsRequest(
user_app_id=userDataObject,
delete_all=True
# ids = ['workflow_id_1', 'workflow_id_2'] # Specify a list of workflow IDs to be deleted

),
metadata=metadata
)

if delete_workflows_response.status.code != status_code_pb2.SUCCESS:
print(delete_workflows_response.status)
raise Exception("Delete workflows failed, status: " + delete_workflows_response.status.description)

Export Workflow

You can easily export your entire workflow as a YAML file. This local copy enables convenient editing and offers the flexibility to create, reuse, or manage workflows with ease.

from clarifai.client.workflow import Workflow

# Your PAT (Personal Access Token) can be found in the Account's Security section

workflow_url = "https://clarifai.com/clarifai/main/workflows/Demographics"
demographics_workflow = Workflow(
url=workflow_url , pat="YOUR_PAT"
)
demographics_workflow.export("demographics_workflow.yml")
"""
Now the parameters of each model can be changed and new workflow can be easily created by app.create_workflow().

Here we change the margin parameter of the image cropper node to be 1.5

- id: image-crop
model:
model_id: margin-100-image-crop-custom
model_type_id: image-crop
description: Custom crop model
output_info:
params:
margin: 1.5


"""