Skip to main content

Managing Inputs

Learn how to interact with inputs using Clarifai Python SDK


Effortlessly handle and organize your input data with Clarifai's Python SDK. The Input Management feature empowers you to efficiently manage various types of data, including images, videos, and text, facilitating seamless integration into your machine learning workflows. Take control of your inputs, whether sourced from URLs, file paths, or raw bytes, and streamline the preparation process for predictive model inferences. Clarifai's Input Management simplifies the task of organizing and preparing data for an enhanced and streamlined machine learning experience.

Image Data as Inputs

The Clarifai Python SDK empowers you to seamlessly upload image data through various methods, providing flexibility and ease of integration. Whether your images are hosted online via URLs, stored locally as file paths, or represented as bytes within your application, our API accommodates all these formats. This versatility ensures a smooth and efficient workflow, allowing you to leverage Clarifai's powerful capabilities with the convenience that suits your specific use case.

Visit this page for more information.

from clarifai.client.input import Inputs

img_url = "https://samples.clarifai.com/metro-north.jpg"
input_obj = Inputs(user_id="user_id", app_id="test_app", pat="YOUR_PAT")
# You can also upload data through Bytes and Filepath,

# Upload from file
# input_obj.upload_from_file(input_id='demo', image_file=’image_filepath')

# Upload from bytes
# input_obj.upload_from_bytes(input_id='demo', image_bytes=image)

input_obj.upload_from_url(input_id="demo", image_url=img_url)
Output

2024-01-15 16:38:49 INFO clarifai.client.input: input.py:669

Inputs Uploaded

code: SUCCESS

description: "Ok"

details: "All inputs successfully added"

req_id: "a14eda72951b06cd25561381d70ced74"

Text Data as Inputs

Use the potential of the Clarifai Python SDK to effortlessly upload text data through diverse methods, providing a seamless experience and fostering adaptability in your integration process. Whether your text is accessible online via URLs, resides locally as file paths, or is represented as bytes within your application, our API seamlessly accommodates these formats. This versatility ensures a fluid and effective workflow, enabling you to unlock Clarifai's robust capabilities with the utmost convenience tailored to your specific use case.

Visit this page for more information.

from clarifai.client.input import Inputs

input_text = b"Write a tweet on future of AI"
input_obj = Inputs(user_id="user_id", app_id="test_app", pat="YOUR_PAT")

# You can also upload data through URLand Filepath,

# Upload from file
# input_obj.upload_from_file(input_id='text_dat', text_file=’text_filepath')

# Upload from url
# input_obj.upload_from_url(input_id='text,text_url=”text_url”)

input_obj.upload_from_bytes(input_id="text_data", text_bytes=input_text)
Output
2024-01-16 14:14:41 INFO     clarifai.client.input:                                                    input.py:669

Inputs Uploaded

code: SUCCESS

description: "Ok"

details: "All inputs successfully added"

req_id: "80d2454a1dea0411e20fb03b2fe0c8b1"

Audio Data as Inputs

Unlock the potential of audio analysis with the Clarifai Python SDK, offering seamless integration for uploading audio data through multiple avenues. Whether your audio files reside on external servers accessible via URLs, are stored locally with file paths, or are represented as raw bytes within your application, our API effortlessly accommodates each of these formats. This adaptability ensures a streamlined and user-friendly workflow, providing you the freedom to harness Clarifai's advanced capabilities with the utmost convenience tailored to your specific use case.

Visit this page for more information.

from clarifai.client.input import Inputs

audio_url = "https://s3.amazonaws.com/samples.clarifai.com/GoodMorning.wav"
input_obj = Inputs(user_id="user_id", app_id="test_app", pat="YOUR_PAT")

# You can also upload data through Bytes and Filepath,

# Upload from file
# input_obj.upload_from_file(input_id='audio_data', audio_file=’audio_filepath')

# Upload from bytes
# input_obj.upload_from_bytes(input_id='audio_data’, audio_bytes=audio)

input_obj.upload_from_url(
input_id="audio_data",
audio_url=audio_url,
)
Output

2024-01-16 14:18:58 INFO clarifai.client.input: input.py:669

Inputs Uploaded

code: SUCCESS

description: "Ok"

details: "All inputs successfully added"

req_id: "c16d3dd066d7ee48d038744daacef6e8"

Video Data as Inputs

Unlock the potential of video analysis with the Clarifai Python SDK, offering seamless integration for uploading video data through various methods. Whether your videos are accessible online via URLs, residing locally as file paths, or encapsulated as bytes within your application, our API effortlessly accommodates these diverse formats.

Visit this page for more information.

from clarifai.client.input import Inputs
video_url = "https://samples.clarifai.com/beer.mp4"
input_obj = Inputs(user_id="user_id", app_id="test_app", pat="YOUR_PAT")

# You can also upload data through Bytes and Filepath,

# Upload from file
# input_obj.upload_from_file(input_id='video_data', video_file=’video_filepath')

# Upload from bytes
# input_obj.upload_from_bytes(input_id='video_data’, video_bytes=video)

input_obj.upload_from_url(
input_id="video_data", video_url= video_url
)
Output
2024-01-16 14:25:26 INFO     clarifai.client.input:                                                    input.py:669

Inputs Uploaded

code: SUCCESS

description: "Ok"

details: "All inputs successfully added"

req_id: "00576d040a6254019942ab4eceb306ad"

Multimodal Data as Inputs

With the Clarifai Python SDK, the integration of multimodal inputs becomes a seamless and intuitive process. Unlock the power of combining various types of inputs by leveraging our API. Whether you're incorporating a mix of images, text, or other data sources, our SDK allows you to specify and upload these multimodal inputs effortlessly. For now the Clarifai platform only supports multimodal inputs like [Image ,Text]->text.

Visit this page for more information.

from clarifai.client.input import Inputs

input_obj = Inputs(user_id="user_id", app_id="test_app", pat="YOUR_PAT")

# initialize inputs of different type
prompt = "What time of day is it?"
image_url = "https://samples.clarifai.com/metro-north.jpg"

# Here you can give the value for different types of inputs
input_obj.get_multimodal_input(
input_id="multimodal_data", image_url=image_url, raw_text=prompt
)
Output
id: "multimodal_data"
data {
image {
url: "https://samples.clarifai.com/metro-north.jpg"
}
text {
raw: "What time of day is it?"
}
}

Custom Metadata

When working with the Clarifai Python SDK, you can add inputs with custom metadata in addition to concepts. This allows you to attach additional information to your inputs, which can be useful for various purposes such as categorization, filtering, or later reference.

Visit this page for more information.

Image With Metadata

In the below example we are uploading an image with metadata that includes details about the filename and to which split it belongs to.

# Import necessary modules
from google.protobuf.struct_pb2 import Struct
from clarifai.client.input import Inputs

# Create an Inputs object with user_id and app_id
input_object = Inputs(user_id="user_id", app_id="app_id", pat="YOUR_PAT")

# Create a Struct object for metadata
metadata = Struct()

# Update metadata with filename and split information
metadata.update({"filename": "XiJinping.jpg", "split": "train"})

# URL of the image to upload
url = "https://samples.clarifai.com/XiJinping.jpg"

# Upload the image from the URL with associated metadata
input_object.upload_from_url(input_id="metadata", image_url=url, metadata=metadata)
Output
2024-04-05 13:03:24 INFO     clarifai.client.input:                                                    input.py:674
Inputs Uploaded
code: SUCCESS
description: "Ok"
details: "All inputs successfully added"
req_id: "951a64b950cccf05c8d274c8acc1f0f6"

INFO:clarifai.client.input:
Inputs Uploaded
code: SUCCESS
description: "Ok"
details: "All inputs successfully added"
req_id: "951a64b950cccf05c8d274c8acc1f0f6"

('8557e0f57f464c22b3483de76757fb4f',
status {
code: SUCCESS
description: "Ok"
details: "All inputs successfully added"
req_id: "951a64b950cccf05c8d274c8acc1f0f6"
}
inputs {
id: "metadata"
data {
image {
url: "https://samples.clarifai.com/XiJinping.jpg"
image_info {
format: "UnknownImageFormat"
color_mode: "UnknownColorMode"
}
}
metadata {
fields {
key: "filename"
value {
string_value: "XiJinping.jpg"
}
}
fields {
key: "split"
value {
string_value: "train"
}
}
}
}
created_at {
seconds: 1712322204
nanos: 737881425
}
modified_at {
seconds: 1712322204
nanos: 737881425
}
status {
code: INPUT_DOWNLOAD_PENDING
description: "Download pending"
}
}
inputs_add_job {
id: "8557e0f57f464c22b3483de76757fb4f"
progress {
pending_count: 1
}
created_at {
seconds: 1712322204
nanos: 714751000
}
modified_at {
seconds: 1712322204
nanos: 714751000
}
status {
code: JOB_QUEUED
description: "Job is queued to be ran."
}
})

Video With Metadata

In the below example we are uploading a video file with metadata that includes details about the filename and to which split it belongs to.

from google.protobuf.struct_pb2 import Struct
from clarifai.client.input import Inputs

# Initialize an Inputs object with specified user_id and app_id
input_object = Inputs(user_id="user_id", app_id="app_id", pat="YOUR_PAT")

# Define the URL of the video to upload
video_url = "https://samples.clarifai.com/beer.mp4"

# Create a Struct object to hold metadata
metadata = Struct()

# Update the metadata with filename and split information
metadata.update({"filename": "drinks.jpg", "split": "train"})

# Upload the video from the specified URL with the provided metadata
input_object.upload_from_url(
input_id="video_data_metadata", video_url=video_url, metadata=metadata
)
Output
2024-04-05 13:05:49 INFO     clarifai.client.input:                                                    input.py:674
Inputs Uploaded
code: SUCCESS
description: "Ok"
details: "All inputs successfully added"
req_id: "72c9820d805efb9f3ee7f0508778c1f3"

INFO:clarifai.client.input:
Inputs Uploaded
code: SUCCESS
description: "Ok"
details: "All inputs successfully added"
req_id: "72c9820d805efb9f3ee7f0508778c1f3"

('7fdc30b9c2a24f31b6a41b32bd9fea02',
status {
code: SUCCESS
description: "Ok"
details: "All inputs successfully added"
req_id: "72c9820d805efb9f3ee7f0508778c1f3"
}
inputs {
id: "video_data_metadata"
data {
video {
url: "https://samples.clarifai.com/beer.mp4"
video_info {
video_format: "UnknownVideoFormat"
}
}
metadata {
fields {
key: "filename"
value {
string_value: "drinks.jpg"
}
}
fields {
key: "split"
value {
string_value: "train"
}
}
}
}
created_at {
seconds: 1712322349
nanos: 628288634
}
modified_at {
seconds: 1712322349
nanos: 628288634
}
status {
code: INPUT_DOWNLOAD_PENDING
description: "Download pending"
}
}
inputs_add_job {
id: "7fdc30b9c2a24f31b6a41b32bd9fea02"
progress {
pending_count: 1
}
created_at {
seconds: 1712322349
nanos: 602487000
}
modified_at {
seconds: 1712322349
nanos: 602487000
}
status {
code: JOB_QUEUED
description: "Job is queued to be ran."
}
})

Text With Metadata

In the below example we are uploading a text file with metadata that includes details about the filename and to which split it belongs to.

# Import necessary modules
from google.protobuf.struct_pb2 import Struct
from clarifai.client.input import Inputs

# Define the input object with user_id and app_id
input_object = Inputs(user_id="user_id", app_id="app_id", pat="YOUR_PAT")

# Define the input text
input_text = b"Write a tweet on future of AI"

# Create a Struct object for metadata
metadata = Struct()

# Update metadata with filename and split information
metadata.update({"filename": "tweet.txt", "split": "train"})

# Upload the input from bytes with custom metadata
input_object.upload_from_bytes(input_id="text_data_metadata", text_bytes=input_text, metadata=metadata)
Output
2024-04-05 13:07:04 INFO     clarifai.client.input:                                                    input.py:674
Inputs Uploaded
code: SUCCESS
description: "Ok"
details: "All inputs successfully added"
req_id: "835f6c736f032947d1f4067e39c10b72"

INFO:clarifai.client.input:
Inputs Uploaded
code: SUCCESS
description: "Ok"
details: "All inputs successfully added"
req_id: "835f6c736f032947d1f4067e39c10b72"

('e3de274f644a4e98a488e7c85f94c0d1',
status {
code: SUCCESS
description: "Ok"
details: "All inputs successfully added"
req_id: "835f6c736f032947d1f4067e39c10b72"
}
inputs {
id: "text_data_metadata"
data {
metadata {
fields {
key: "filename"
value {
string_value: "tweet.txt"
}
}
fields {
key: "split"
value {
string_value: "train"
}
}
}
text {
url: "https://data.clarifai.com/orig/users/8tzpjy1a841y/apps/visual_classifier_eval/inputs/text/c439598b04d8112867eec70097aa00c2"
text_info {
encoding: "UnknownTextEnc"
}
}
}
created_at {
seconds: 1712322424
nanos: 56818659
}
modified_at {
seconds: 1712322424
nanos: 56818659
}
status {
code: INPUT_DOWNLOAD_PENDING
description: "Download pending"
}
}
inputs_add_job {
id: "e3de274f644a4e98a488e7c85f94c0d1"
progress {
pending_count: 1
}
created_at {
seconds: 1712322423
nanos: 941401000
}
modified_at {
seconds: 1712322423
nanos: 941401000
}
status {
code: JOB_QUEUED
description: "Job is queued to be ran."
}
})

Audio With Metadata

In the below example we are uploading an audio file with metadata that includes details about the filename and to which split it belongs to.

# Import necessary modules
from clarifai.client.input import Inputs
from google.protobuf.struct_pb2 import Struct


# Define the input object with user_id and app_id
input_object = Inputs(user_id="user_id", app_id="app_id", pat="YOUR_PAT")

# Define the URL of the audio file
audio_url = "https://s3.amazonaws.com/samples.clarifai.com/GoodMorning.wav"

# Create a new Struct to hold metadata
metadata = Struct()

# Update the metadata with filename and split information
metadata.update({"filename": "goodmorning.wav", "split": "test"})

# Upload the input from the specified URL with metadata
input_object.upload_from_url(
input_id="audio_data_metadata", # Specify an ID for the input
audio_url=audio_url, # URL of the audio file
metadata=metadata # Custom metadata associated with the input
)
Output
2024-04-08 06:39:32 INFO     clarifai.client.input:                                                    input.py:674
Inputs Uploaded
code: SUCCESS
description: "Ok"
details: "All inputs successfully added"
req_id: "4c96e4167170c174838c7987101f3478"

INFO:clarifai.client.input:
Inputs Uploaded
code: SUCCESS
description: "Ok"
details: "All inputs successfully added"
req_id: "4c96e4167170c174838c7987101f3478"

('109349aa790a404db39f6324415a47a5',
status {
code: SUCCESS
description: "Ok"
details: "All inputs successfully added"
req_id: "4c96e4167170c174838c7987101f3478"
}
inputs {
id: "audio_data_metadata"
data {
metadata {
fields {
key: "filename"
value {
string_value: "goodmorning.wav"
}
}
fields {
key: "split"
value {
string_value: "test"
}
}
}
audio {
url: "https://s3.amazonaws.com/samples.clarifai.com/GoodMorning.wav"
audio_info {
audio_format: "UnknownAudioFormat"
}
}
}
created_at {
seconds: 1712558372
nanos: 764691920
}
modified_at {
seconds: 1712558372
nanos: 764691920
}
status {
code: INPUT_DOWNLOAD_PENDING
description: "Download pending"
}
}
inputs_add_job {
id: "109349aa790a404db39f6324415a47a5"
progress {
pending_count: 1
}
created_at {
seconds: 1712558372
nanos: 751997000
}
modified_at {
seconds: 1712558372
nanos: 751997000
}
status {
code: JOB_QUEUED
description: "Job is queued to be ran."
}
})

List inputs

Effortlessly explore and manage your inputs with the Clarifai Python SDK. By utilizing the list_inputs() method, you gain the ability to seamlessly view all inputs within your app. This powerful function supports features like pagination, enabling a well-organized display of information. Tailor your queries by setting parameters such as page_no and per_page to align with your specific requirements.

Visit this page for more information.

from clarifai.client.user import User

# Create the input object
input_obj = User(user_id="user_id").app(app_id="test_app", pat="YOUR_PAT").inputs()
# list the inputs with pagination
all_inputs = list(input_obj.list_inputs(page_no=1,per_page=3))
print(all_inputs)
Output
[id: "demo1"
data {
image {
url: "https://samples.clarifai.com/metro-north.jpg"
hosted {
prefix: "https://data.clarifai.com"
suffix: "users/8tzpjy1a841y/apps/test_app/inputs/image/140c856dc82565d2c4d6ea720fceff78"
sizes: "orig"
sizes: "tiny"
sizes: "small"
sizes: "large"
crossorigin: "use-credentials"
}
image_info {
width: 512
height: 384
format: "JPEG"
color_mode: "YUV"
}
}
}
created_at {
seconds: 1705917660
nanos: 789409000
}
...
code: INPUT_DOWNLOAD_SUCCESS
description: "Download complete"
}
]

Delete Inputs

Effortlessly manage your input data with the Clarifai Python SDK's Delete Inputs feature. Through the API, you gain the ability to delete inputs seamlessly by providing a list of input IDs. This straightforward and intuitive process empowers you to maintain control over your dataset, allowing for efficient removal of specific inputs as needed.

caution

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

from clarifai.client.user import User

input_obj = User(user_id="user_id", pat="YOUR_PAT").app(app_id="test_app").inputs()
# provide the inputs ids as parameters in delete_inputs function
input_obj.delete_inputs(list(input_obj.list_inputs()))
Output
2024-01-16 14:44:28 INFO     clarifai.client.input:                                                    input.py:732

Inputs Deleted

code: SUCCESS

description: "Ok"

req_id: "4ae26cd15c7da98a1c2d3647b03d2768"