Skip to main content

Add, Get, Update, Delete

Manage the data in your app


The API is built around a simple idea. You send inputs (such as images) to the service and it returns predictions. In addition to receiving predictions on inputs, you can also index inputs and their predictions to later search against. You can also index inputs with concepts to later train your own model.

When you add an input to your app, the base workflow of your app runs, computing the outputs from all the models in that workflow and indexing those outputs. Those indexed outputs are what incur the indexing fee monthly, and enable search and training on top of the outputs of the base workflow models.

info

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

Add Inputs

You can add inputs one by one or in bulk. If you send them in bulk, you are limited to sending 128 inputs at a time.

Note

Adding inputs is an asynchronous operation. That means it will process indexing of your inputs through your default workflow in the background, which can take some time. In order to check the status of each input you add, see the section on Get Inputs and look for status 30000 (INPUT_IMAGE_DOWNLOAD_SUCCESS) status code on each input to know when it has successfully been indexed.

Add Inputs via URL

Below is an example of how to add inputs via a publicly accessible URL.

##########################################################################
# In this section, we set the user authentication, app ID, and input URL.
# 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 whatever image input you want to add
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)

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,
allow_duplicate_url=True
)
)
)
]
),
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)

Add Inputs via Bytes

Below is an example of how to add inputs via bytes.

Note

The data must be base64 encoded. When you add a base64 image to our servers, a copy will be stored and hosted on our servers. If you already have an image hosting service, we recommend using it and adding images via the url parameter.

##################################################################################
# In this section, we set the user authentication, app ID, and the location
# of the image we want as an input. 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 whatever image input you want to add
IMAGE_FILE_LOCATION = 'YOUR_IMAGE_FILE_LOCATION'

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

with open(IMAGE_FILE_LOCATION, "rb") as f:
file_bytes = f.read()

post_inputs_response = stub.PostInputs(
service_pb2.PostInputsRequest(
user_app_id=userDataObject,
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
base64=file_bytes
)
)
)
]
),
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)

Add Multiple Inputs With IDs

In cases where you have your own id and you only have one item per image, you are encouraged to send inputs with your own id. This will help you later match the input to your own database.

If you do not send an id, one will be created for you. If you have more than one item per image, it is recommended that you put the product id in the metadata.

##################################################################################
# In this section, we set the user authentication, app ID, and the URLs and IDs
# of the images we want as inputs. 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 whatever inputs you want to add
IMAGE_URL_1 = 'https://samples.clarifai.com/metro-north.jpg'
IMAGE_URL_2 = 'https://samples.clarifai.com/puppy.jpeg'
INPUT_ID_1 = 'mytrain'
INPUT_ID_2 = 'mypuppy'

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

post_inputs_response = stub.PostInputs(
service_pb2.PostInputsRequest(
user_app_id=userDataObject,
inputs=[
resources_pb2.Input(
id=INPUT_ID_1,
data=resources_pb2.Data(
image=resources_pb2.Image(
url=IMAGE_URL_1,
allow_duplicate_url=True
)
)
),
resources_pb2.Input(
id=INPUT_ID_2,
data=resources_pb2.Data(
image=resources_pb2.Image(
url=IMAGE_URL_2,
allow_duplicate_url=True
)
)
),
]
),
metadata=metadata
)

if post_inputs_response.status.code != status_code_pb2.SUCCESS:
print("There was an error with your request!")
for input_object in post_inputs_response.inputs:
print("Input " + input_object.id + " status:")
print(input_object.status)
raise Exception("Post inputs failed, status: " + post_inputs_response.status.description)

Add Inputs With Concepts

If you would like to add an input with concepts, you can do so. Concepts play an important role in creating your own models.

You can learn more about creating your own models here.

Concepts also help you search for inputs. You can learn more about search here.

When you add a concept to an input, you need to indicate whether the concept is present in the image or not.

You can add inputs with concepts via URLs or bytes.

##################################################################################
# In this section, we set the user authentication, app ID, and the input to add
# with concept. 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 whatever input and concept you want to add
IMAGE_URL = 'https://samples.clarifai.com/puppy.jpeg'
CONCEPT_ID = 'charlie'

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

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,
allow_duplicate_url=True
),
concepts=[resources_pb2.Concept(id=CONCEPT_ID, value=1.)]
)
)
]
),
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)

Add Inputs With Multiple Concepts

You can also add an input with multiple concepts in a single API call. You can provide the concepts in a list and iterate through it.

You can add the inputs via URLs or bytes.

##################################################################################
# In this section, we set the user authentication, app ID, and the input to add
# with concepts. 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 whatever input and concepts you want to add
IMAGE_URL = 'https://samples.clarifai.com/puppy.jpeg'
CONCEPT_IDS_LIST = ['one', 'two', 'three', 'four', 'five', 'six']

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

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,
allow_duplicate_url=True
),
# We use Python list comprehension to iterate through the list of concepts
concepts=[resources_pb2.Concept(id=str(i), value=1.) for i in CONCEPT_IDS_LIST]
)
)
]
),
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)

Add Inputs With Custom Metadata

In addition to adding an input with concepts, you can also add an input with custom metadata. This metadata will then be searchable. Metadata can be any arbitrary JSON.

If you have more than one item per image, it is recommended to put the id in the metadata like:

{
"product_id": "xyz"
}
####################################################################################
# In this section, we set the user authentication, app ID, and the custom metadata
# and input 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 these to whatever input and custom metadata you want to add
CUSTOM_METADATA = {"id": "id001", "type": "animal", "size": 100}
IMAGE_URL = 'https://samples.clarifai.com/puppy.jpeg'

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

input_metadata = Struct()

input_metadata.update(CUSTOM_METADATA)

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,
allow_duplicate_url=True
),
metadata=input_metadata
)
)
]
),
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)

Add Inputs From Cloud Storage

You can add inputs from various cloud storage platforms, such as S3 (Amazon Simple Storage Service) and GCP (Google Cloud Platform), by simply providing their corresponding URLs. In cases where access credentials are necessary, you can include them as part of the request.

This simplifies the process of adding inputs to our platform, offering a more efficient alternative to the conventional method of using the PostInputs endpoint for users who already have data stored in the cloud platforms.

note

This functionality has been introduced starting from the 10.1 release.

info
  • Image files stored in the cloud platforms will be treated as image inputs, video files as video inputs, etc. Archives will be extracted, and their contents will also be processed like this.

  • We do not support extraction of archives located inside other archives.

  • The cloud URL will serve as a filter prefix. For instance, in the case of an S3 URL like s3:/bucket/images_folder/abc, files within the images_folder will be processed starting with abc, or within a subfolder beginning with abc. For example, files such as bucket/images_folder/abcImage.png or bucket/images_folder/abc-1/Data.zip will be processed accordingly.

Add Inputs via Cloud Storage URLs

Below is an example of pulling inputs from a subfolder of an S3 bucket.

######################################################################################################
# In this section, we set the user authentication, app ID, ID to collect statistics about inputs job
# to be created, and cloud storage URL. Change these strings to run your own example.
######################################################################################################

USER_ID = "YOUR_USER_ID_HERE"
# Your PAT (Personal Access Token) can be found in the Portal under Account > Security
PAT = "YOUR_PAT_HERE"
APP_ID = "YOUR_APP_ID_HERE"
# Change these to create your own extraction job
INPUTS_JOB_ID = "" # If empty, ID will be autogenerated; if non-empty, the given ID will be used
CLOUD_STORAGE_URL = "s3://samples.clarifai.com/storage/"

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

post_inputs_response = stub.PostInputsDataSources(
service_pb2.PostInputsDataSourcesRequest(
user_app_id=userDataObject,
app_pat=PAT,
data_sources=[
resources_pb2.InputsDataSource(
inputs_add_job_id=INPUTS_JOB_ID,
url=resources_pb2.DataSourceURL(
url=CLOUD_STORAGE_URL,
# Uncomment to add credentials
# credentials=resources_pb2.DataSourceCredentials(
# s3_creds=resources_pb2.AWSCreds(
# id="ADD_ACCESS_ID_HERE",
# secret="ADD_SECRET_HERE",
# region="ADD_AWS_REGION_HERE"
# )
# If using GCP
# gcpCreds="" # GCP uses service account key data (creds.json) as Byte array for authentication
# ),
),
)
],
),
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
)

print(post_inputs_response)
Output Example
status {
code: SUCCESS
description: "Ok"
req_id: "8759d87e31403bbd838794fe6016f36d"
}
inputs_add_jobs {
id: "2581ebd8d7cd42e7ac0da2bec14d5426"
progress {
}
created_at {
seconds: 1708361354
nanos: 820114719
}
modified_at {
seconds: 1708361354
nanos: 847655746
}
extraction_jobs {
status {
code: JOB_QUEUED
description: "Job is queued to be ran."
}
id: "2a6f1f69cced42029986a72009e7d4da"
url: "s3://samples.clarifai.com/storage/"
progress {
}
created_at {
seconds: 1708361354
nanos: 835105396
}
modified_at {
seconds: 1708361354
nanos: 835105396
}
}
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
}

Track Upload Process

After starting to pull the inputs from a cloud storage service, you can track the progress of the exercise. Note that we’ll use the inputs_extraction_job_id returned after running the extraction job.

###################################################################################################
# In this section, we set the user authentication, app ID, and the inputs extraction job 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 Portal under Account > Security
PAT = "YOUR_PAT_HERE"
APP_ID = "YOUR_APP_ID_HERE"
# Change this ID to whatever inputs you want to track their upload process
INPUTS_EXTRACTION_JOB_ID = "2a6f1f69cced42029986a72009e7d4da"

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

get_inputs_extraction_response = stub.GetInputsExtractionJob(
service_pb2.GetInputsExtractionJobRequest(
user_app_id=userDataObject,
inputs_extraction_job_id=INPUTS_EXTRACTION_JOB_ID
),
metadata=metadata,
)

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

print(get_inputs_extraction_response)
Output Example
status {
code: SUCCESS
description: "Ok"
req_id: "bae1f832c8931d47388f875653e7035d"
}
inputs_extraction_job {
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
id: "2a6f1f69cced42029986a72009e7d4da"
url: "s3://samples.clarifai.com/storage/"
progress {
image_inputs_count: 3
video_inputs_count: 1
}
created_at {
seconds: 1708361354
nanos: 835105000
}
modified_at {
seconds: 1708361355
nanos: 386004000
}
}

List Inputs Extraction Jobs

You can list all your inputs extraction jobs and get their details.

##################################################################
# 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 Portal under Account > Security
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)

list_inputs_extraction_jobs = stub.ListInputsExtractionJobs(
service_pb2.ListInputsExtractionJobsRequest(
user_app_id=userDataObject, per_page=1000, page=1
),
metadata=metadata,
)

if list_inputs_extraction_jobs.status.code != status_code_pb2.SUCCESS:
print(list_inputs_extraction_jobs.status)
raise Exception(
"List input failed, status: " + list_inputs_extraction_jobs.status.description
)

print(list_inputs_extraction_jobs)
Output Example
----
inputs_extraction_jobs {
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
id: "487d863784804390a92e1108ee1ae1fb"
url: "s3://samples.clarifai.com/storage/"
progress {
image_inputs_count: 3
video_inputs_count: 1
}
created_at {
seconds: 1708406450
nanos: 685101000
}
modified_at {
seconds: 1708406451
nanos: 191007000
}
}
inputs_extraction_jobs {
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
id: "16d65cdff5d64ae8ba94ae59f5d7f43c"
url: "s3://samples.clarifai.com/storage/"
progress {
image_inputs_count: 3
video_inputs_count: 1
}
created_at {
seconds: 1708406156
nanos: 2926000
}
modified_at {
seconds: 1708406156
nanos: 560108000
}
}
inputs_extraction_jobs {
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
id: "423b4dfa36f64fffbe79cf845918d4c0"
url: "s3://samples.clarifai.com/storage/"
progress {
image_inputs_count: 3
video_inputs_count: 1
}
created_at {
seconds: 1708405684
nanos: 297689000
}
modified_at {
seconds: 1708405684
nanos: 778885000
}
}
inputs_extraction_jobs {
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
id: "a5af6a185ab148d4b7eb02e713d3340d"
url: "s3://samples.clarifai.com/storage/"
progress {
image_inputs_count: 3
video_inputs_count: 1
}
created_at {
seconds: 1708405639
nanos: 186106000
}
modified_at {
seconds: 1708405639
nanos: 696943000
}
}
inputs_extraction_jobs {
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
id: "1c10da09706d40448bf11fc5aaa8664b"
url: "s3://samples.clarifai.com/storage/"
progress {
image_inputs_count: 3
video_inputs_count: 1
}
created_at {
seconds: 1708405297
nanos: 953730000
}
modified_at {
seconds: 1708405298
nanos: 506209000
}
}
inputs_extraction_jobs {
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
id: "10ad7ba72e5e49899a042637178c9452"
url: "s3://samples.clarifai.com/storage/"
progress {
image_inputs_count: 3
video_inputs_count: 1
}
created_at {
seconds: 1708404787
nanos: 575667000
}
modified_at {
seconds: 1708404788
nanos: 141744000
}
}
inputs_extraction_jobs {
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
id: "8d7a240f39494ce18c3a5f4aeea687c1"
url: "s3://samples.clarifai.com/storage/"
progress {
image_inputs_count: 3
video_inputs_count: 1
}
created_at {
seconds: 1708403207
nanos: 89134000
}
modified_at {
seconds: 1708403207
nanos: 729276000
}
}
inputs_extraction_jobs {
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
id: "2a6f1f69cced42029986a72009e7d4da"
url: "s3://samples.clarifai.com/storage/"
progress {
image_inputs_count: 3
video_inputs_count: 1
}
created_at {
seconds: 1708361354
nanos: 835105000
}
modified_at {
seconds: 1708361355
nanos: 386004000
}
}
inputs_extraction_jobs {
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
id: "6db64516daf04abd97852407f9076e42"
url: "s3://samples.clarifai.com/storage/"
progress {
image_inputs_count: 3
video_inputs_count: 1
}
created_at {
seconds: 1708361312
nanos: 309789000
}
modified_at {
seconds: 1708361313
nanos: 435552000
}
}
inputs_extraction_jobs {
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
id: "7e4bd42e84294e8f9423e0a01783e3b1"
url: "s3://samples.clarifai.com/storage/"
progress {
image_inputs_count: 3
video_inputs_count: 1
}
created_at {
seconds: 1708354769
nanos: 17131000
}
modified_at {
seconds: 1708354769
nanos: 473323000
}
input_template {
data {
concepts {
id: "lamborghini23_A"
value: 1
}
concepts {
id: "spiderman_a"
value: 1
}
metadata {
fields {
key: "id"
value {
string_value: "id001"
}
}
}
}
dataset_ids: "dataset-1"
}
}
-----

Cancel Extraction Jobs

You can cancel the process of extraction of inputs from a cloud storage service. Note that we’ll use the inputs_extraction_job_id returned after starting the extraction process.

#####################################################################################################
# In this section, we set the user authentication, app ID, and the inputs extraction job 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 Portal under Account > Security
PAT = "YOUR_PAT_HERE"
APP_ID = "YOUR_APP_ID_HERE"
# Change this ID to whatever inputs you want to cancel their upload process
INPUTS_EXTRACTION_JOB_ID = "2a6f1f69cced42029986a72009e7d4da"

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

cancel_inputs_extraction_response = stub.CancelInputsExtractionJobs(
service_pb2.CancelInputsExtractionJobsRequest(
user_app_id=userDataObject, ids=[INPUTS_EXTRACTION_JOB_ID]
),
metadata=metadata,
)

if cancel_inputs_extraction_response.status.code != status_code_pb2.SUCCESS:
print(cancel_inputs_extraction_response.status)
raise Exception(
"Cancel input failed, status: "
+ cancel_inputs_extraction_response.status.description
)

print(cancel_inputs_extraction_response)

Add Inputs With Concepts and Datasets

You can also add inputs from cloud storage platforms while attaching relevant concepts, assigning them to an already existing dataset, or adding other metadata information to them.

The input_template parameter allows you to do that.

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

USER_ID = "YOUR_USER_ID_HERE"
# Your PAT (Personal Access Token) can be found in the Portal under Account > Security
PAT = "YOUR_PAT_HERE"
APP_ID = "YOUR_APP_ID_HERE"
# Change these to make your own extraction
INPUTS_JOB_ID = ""
CLOUD_STORAGE_URL = "s3://samples.clarifai.com/storage/"
CUSTOM_METADATA = {"id": "id001"}
DATASET_ID_1 = "dataset-1"
CONCEPT_ID_1 = "lamborghini23_A"
CONCEPT_ID_2 = "spiderman_a"

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

input_metadata = Struct()

input_metadata.update(CUSTOM_METADATA)

post_inputs_response = stub.PostInputsDataSources(
service_pb2.PostInputsDataSourcesRequest(
user_app_id=userDataObject,
app_pat=PAT,
data_sources=[
resources_pb2.InputsDataSource(
inputs_add_job_id=INPUTS_JOB_ID,
url=resources_pb2.DataSourceURL(url=CLOUD_STORAGE_URL),
input_template=resources_pb2.Input(
dataset_ids=[DATASET_ID_1], # List of dataset IDs that this input is part of
data=resources_pb2.Data(
metadata=input_metadata,
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_1, value=1),
resources_pb2.Concept(id=CONCEPT_ID_2, value=1),
],
),
),
)
],
),
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
)

print(post_inputs_response)
Output Example
status {
code: SUCCESS
description: "Ok"
req_id: "32694c6a3ef8fe3f6704502c0b053734"
}
inputs_add_jobs {
id: "66b5ca001e754111a81c4839cdabed10"
progress {
}
created_at {
seconds: 1708500170
nanos: 508992497
}
modified_at {
seconds: 1708500170
nanos: 582792601
}
extraction_jobs {
status {
code: JOB_QUEUED
description: "Job is queued to be ran."
}
id: "7e9b139f65fb4426a3d273d609758d34"
url: "s3://samples.clarifai.com/storage/"
progress {
}
created_at {
seconds: 1708500170
nanos: 550291872
}
modified_at {
seconds: 1708500170
nanos: 550291872
}
input_template {
data {
concepts {
id: "lamborghini23_A"
value: 1
}
concepts {
id: "spiderman_a"
value: 1
}
metadata {
fields {
key: "id"
value {
string_value: "id001"
}
}
}
}
dataset_ids: "dataset-1"
}
}
status {
code: JOB_COMPLETED
description: "Job successfully ran."
}
}

List Inputs

List all Inputs

You can list all the inputs (images) you previously added either for search or train. If you added inputs with concepts, they will be returned in the response as well.

This request is paginated.

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

list_inputs_response = stub.ListInputs(
service_pb2.ListInputsRequest(
user_app_id=userDataObject,
page=1,
per_page=10
),
metadata=metadata
)

if list_inputs_response.status.code != status_code_pb2.SUCCESS:
print(list_inputs_response.status)
raise Exception("List inputs failed, status: " + list_inputs_response.status.description)

for input_object in list_inputs_response.inputs:
print(input_object)

List Inputs (Streaming)

This is another method for listing inputs, which was built to scalably list an app's inputs in an iterative / streaming fashion. StreamInputs will return per_page number of inputs from a certain input onward, controlled by the optional last_id parameter (defaults to the first input).

By default, the stream will return inputs from oldest to newest. Set the descending field to true to reverse that order.

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

# To start from beginning, do not provide the last_id parameter.
stream_inputs_response = stub.StreamInputs(
service_pb2.StreamInputsRequest(
user_app_id=userDataObject,
per_page=5,
# descending = True # Set to reverse order
),
metadata=metadata
)

if stream_inputs_response.status.code != status_code_pb2.SUCCESS:
print(stream_inputs_response.status)
raise Exception("Stream inputs failed, status: " + stream_inputs_response.status.description)

print("First response (starting from the first input):")
for input_object in stream_inputs_response.inputs:
print("\t" + input_object.id)

last_id = stream_inputs_response.inputs[-1].id

# Set last_id to get the next set of inputs. The returned inputs will not include the last_id input.
stream_inputs_response = stub.StreamInputs(
service_pb2.StreamInputsRequest(
user_app_id=userDataObject,
per_page=5,
last_id=last_id
),
metadata=metadata
)

print(f"Second response (first input is the one following input ID {last_id}):")
for input_object in stream_inputs_response.inputs:
print("\t" + input_object.id)

Get Inputs

Get Input by ID

If you'd like to get the details of a specific input by its id, you can do that as well.

###############################################################################
# In this section, we set the user authentication, app ID, and the input's 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 ID to whatever input you want its details
INPUT_ID = 'eec128fd81974543bafff48702edca4d'

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

get_input_response = stub.GetInput(
service_pb2.GetInputRequest(
user_app_id=userDataObject,
input_id=INPUT_ID
),
metadata=metadata
)

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

input_object = get_input_response.input
print(input_object)

Get Inputs' Status

If you add inputs in bulk, they will be procesed in the background. You can get the status of all your inputs (processed, to_process, and errors) like this:

##################################################################
# In this section, we set the user authentication and the 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)

get_input_count_response = stub.GetInputCount(
service_pb2.GetInputCountRequest(
user_app_id=userDataObject
),
metadata=metadata
)

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

counts = get_input_count_response.counts
print(counts)

Update Inputs

Update Input With Concepts

To update an input with a new concept, or to change a concept value from true/false, you can do the following:

##############################################################################
# In this section, we set the user authentication, app ID, and the input and
# concept ID 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 based on the update you want to make
INPUT_ID = 'eec128fd81974543bafff48702edca4d'
CONCEPT_ID_1 = 'tree'
CONCEPT_ID_2 = 'water'

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

patch_inputs_response = stub.PatchInputs(
service_pb2.PatchInputsRequest(
user_app_id=userDataObject,
action="merge", # Supported actions: overwrite, merge, remove
inputs=[
resources_pb2.Input(
id=INPUT_ID,
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_1, value=1.), # 1 means true, this concept is present.
resources_pb2.Concept(id=CONCEPT_ID_2, value=0.) # 0 means false, this concept is not present.
]
)
)
]
),
metadata=metadata
)

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

Bulk Update Inputs With Concepts

You can update existing inputs using their ids. This is useful if you'd like to add concepts to inputs after they have already been added.

Below is an example of how to update multiple inputs with concepts at once.

################################################################################
# In this section, we set the user authentication, app ID, and the inputs and
# concepts IDs 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 based on the updates you want to make
INPUT_ID_1 = '2e9c4a86555d40ffb47c7b045d7e3048'
INPUT_ID_2 = '52b467c2005946cbbbe7a5eec76e29cf'
CONCEPT_ID_1 = 'tree'
CONCEPT_ID_2 = 'water'
CONCEPT_ID_3 = 'animal'
CONCEPT_ID_4 = 'fruit'

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

patch_inputs_response = stub.PatchInputs(
service_pb2.PatchInputsRequest(
user_app_id=userDataObject,
action="merge", # Supported actions: overwrite, merge, remove.
inputs=[
resources_pb2.Input(
id=INPUT_ID_1,
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_1, value=1.), # 1 means true, this concept is present.
resources_pb2.Concept(id=CONCEPT_ID_2, value=0.) # 0 means false, this concept is not present.
]
)
),
resources_pb2.Input(
id=INPUT_ID_2,
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_3, value=1.),
resources_pb2.Concept(id=CONCEPT_ID_4, value=0.)
]
)
),
]
),
metadata=metadata
)

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

Delete Inputs

Delete Concepts From an Input

To remove concepts that were already added to an input, you can do this:

##############################################################################
# In this section, we set the user authentication, app ID, and the input and
# concept 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 these based on the concept you want to remove
INPUT_ID = '2e9c4a86555d40ffb47c7b045d7e3048'
CONCEPT_ID = 'water'

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

patch_inputs_response = stub.PatchInputs(
service_pb2.PatchInputsRequest(
user_app_id=userDataObject,
action="remove", # Supported actions: overwrite, merge, remove.
inputs=[
resources_pb2.Input(
id=INPUT_ID,
data=resources_pb2.Data(
concepts=[
# We're removing the concept, so there's no need to specify
# the concept value.
resources_pb2.Concept(id=CONCEPT_ID),
]
)
)
]
),
metadata=metadata
)

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

Bulk Delete Concepts From a List of Inputs

Below is an example of how to bulk delete multiple concepts from a list of inputs.

##############################################################################
# In this section, we set the user authentication, app ID, and the inputs and
# concepts IDs. 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 based on the concepts you want to remove
INPUT_ID_1 = '2e9c4a86555d40ffb47c7b045d7e3048'
INPUT_ID_2 = '52b467c2005946cbbbe7a5eec76e29cf'
CONCEPT_ID_1 = 'tree'
CONCEPT_ID_2 = 'water'
CONCEPT_ID_3 = 'animal'
CONCEPT_ID_4 = 'fruit'

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

patch_inputs_response = stub.PatchInputs(
service_pb2.PatchInputsRequest(
user_app_id=userDataObject,
action="remove", # Supported actions: overwrite, merge, remove.
inputs=[
resources_pb2.Input(
id=INPUT_ID_1,
data=resources_pb2.Data(
concepts=[
# We're removing the concepts, so there's no need to specify
# the concept value.
resources_pb2.Concept(id=CONCEPT_ID_1),
resources_pb2.Concept(id=CONCEPT_ID_2),
]
)
),
resources_pb2.Input(
id=INPUT_ID_2,
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_3),
resources_pb2.Concept(id=CONCEPT_ID_4),
]
)
),
]
),
metadata=metadata
)

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

Delete Input by ID

Below is an example of how to delete a single input by its id.

##############################################################################
# In this section, we set the user authentication, app ID, and the ID of the
# input we want to delete. 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 based on the input you want to delete
INPUT_ID = '2e9c4a86555d40ffb47c7b045d7e3048'

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

delete_input_response = stub.DeleteInput(
service_pb2.DeleteInputRequest(
user_app_id=userDataObject,
input_id=INPUT_ID
),
metadata=metadata
)

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

Delete a List of Inputs

You can also delete multiple inputs in one API call. This will happen asynchronously.

info

We currently support a batch size of 128 inputs per request. So, you can provide a list of 128 input IDs and delete them in one API call.

##############################################################################
# In this section, we set the user authentication, app ID, and the IDs of the
# inputs we want to delete. 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 based on the inputs you want to delete
INPUT_ID_1 = '97eb76d22e964c7cbbf06a51532c6fbe'
INPUT_ID_2 = '86b1272feabb45d4bcd2de51eedd729b'

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

delete_inputs_response = stub.DeleteInputs(
service_pb2.DeleteInputsRequest(
user_app_id=userDataObject,
ids=[INPUT_ID_1, INPUT_ID_2]
),
metadata=metadata
)

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