Running apps with the AI Hub SDK
With the AI Hub software development kit (SDK), you can create an end-to-end solution and integrate it with existing upstream and downstream workflows. From uploading files to running an app, you can use the SDK to create a complete AI Hub document-processing solution. This guide includes a full script you can reference to create your own workflow.
Review the developer quickstart and install the AI Hub SDK.
Uploading files to a batch
You can create a batch of files to use as input for your app run. In AI Hub, a batch is a user-defined group of files. You can add and remove files from the batch, but its ID remains constant so you can repeatedly use all files in the batch as app input.
For more information, see the Batches endpoint.
Script excerpt
This section of the script creates a batch and uploads the listed files to it.
Define the following values in the script:
Processing files through an AI Hub app
After uploading your files to a batch, you can process them using an AI Hub app. With the SDK you can run the app, check the status of your app run, and, when the run is complete, get the run results.
For more information, see the Runs endpoint.
Script excerpt
This section of the script runs the app with the batch you created as input, checks the status of the app run, and gets the results.
Define the following values in the script:
batch.id
or run.id
values in this section of the script, as they’re passed through from the results of the previous step.For more information about customizing an app run, including using webhooks, see the Runs endpoint.
Complete workflow
This example Python script shows a complete, end-to-end workflow based on calls to AI Hub API using the AI Hub SDK. When run, this script performs the following tasks:
-
Creates a batch object and uploads files to the batch.
-
Runs the specified app using the batch as input.
-
Automatically polls the app run’s status for completion.
-
Returns the app run’s results in JSON format. See the Get run results endpoint for an example of app run results.
Complete script
User-defined values
To recap, this table outlines all values in the complete script that can or must be defined.